3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
30 * Stores all constants and pseudo constants for CRM application.
32 * examples of constants are "Contact Type" which will always be either
33 * 'Individual', 'Household', 'Organization'.
35 * pseudo constants are entities from the database whose values rarely
36 * change. examples are list of countries, states, location types,
39 * currently we're getting the data from the underlying database. this
40 * will be reworked to use caching.
42 * Note: All pseudoconstants should be uninitialized or default to NULL.
43 * This provides greater consistency/predictability after flushing.
46 * @copyright CiviCRM LLC (c) 2004-2013
50 class CRM_Core_PseudoConstant
{
53 * static cache for pseudoconstant arrays
57 private static $cache;
64 private static $activityType;
67 * payment processor billing modes
71 private static $billingMode;
78 private static $stateProvince;
85 private static $county;
88 * states/provinces abbreviations
92 private static $stateProvinceAbbreviation;
99 private static $country;
106 private static $countryIsoCode;
113 private static $group;
120 private static $groupIterator;
127 private static $relationshipType;
130 * civicrm groups that are not smart groups
134 private static $staticGroup;
141 private static $currencyCode;
148 private static $paymentProcessor;
151 * payment processor types
155 private static $paymentProcessorType;
162 private static $worldRegions;
169 private static $activityStatus;
176 private static $visibility;
183 private static $greeting;
190 private static $greetingDefaults;
193 * Extensions of type module
197 private static $extensions;
200 * Financial Account Type
204 private static $accountOptionValues;
207 * Get options for a given field.
208 * @param String $daoName
209 * @param String $fieldName
210 * @param Array $params
211 * - name string name of the option group
212 * - flip boolean results are return in id => label format if false
213 * if true, the results are reversed
214 * - grouping boolean if true, return the value in 'grouping' column (currently unsupported for tables other than option_value)
215 * - localize boolean if true, localize the results before returning
216 * - condition string add another condition to the sql query
217 * - keyColumn string the column to use for 'id'
218 * - labelColumn string the column to use for 'label'
219 * - orderColumn string the column to use for sorting, defaults to 'weight'
220 * - onlyActive boolean return only the action option values
221 * - fresh boolean ignore cache entries and go back to DB
223 * @return Array on success, FALSE on error.
227 public static function get($daoName, $fieldName, $params = array()) {
229 $fields = $dao->fields();
230 $fieldKeys = $dao->fieldKeys();
231 $fieldKey = $fieldKeys[$fieldName];
233 if (empty($fields[$fieldKey])) {
236 $fieldSpec = $fields[$fieldKey];
237 $flip = !empty($params['flip']);
239 // If the field is an enum, explode the enum definition and return the array.
240 if (isset($fieldSpec['enumValues'])) {
241 // use of a space after the comma is inconsistent in xml
242 $enumStr = str_replace(', ', ',', $fieldSpec['enumValues']);
243 $output = explode(',', $enumStr);
244 return $flip ?
array_flip($output) : $output;
247 elseif (!empty($fieldSpec['pseudoconstant'])) {
248 $pseudoconstant = $fieldSpec['pseudoconstant'];
249 // Merge params with defaults
253 'condition' => CRM_Utils_Array
::value('condition', $pseudoconstant),
254 'keyColumn' => CRM_Utils_Array
::value('keyColumn', $pseudoconstant),
255 'labelColumn' => CRM_Utils_Array
::value('labelColumn', $pseudoconstant),
256 'onlyActive' => TRUE,
260 // Fetch option group from option_value table
261 if(!empty($pseudoconstant['optionGroupName'])) {
262 // Call our generic fn for retrieving from the option_value table
263 return CRM_Core_OptionGroup
::values(
264 $pseudoconstant['optionGroupName'],
268 $params['condition'],
269 $params['labelColumn'] ?
$params['labelColumn'] : 'label',
270 $params['onlyActive'],
275 // Fetch options from other tables
276 if (!empty($pseudoconstant['table'])) {
277 // Normalize params so the serialized cache string will be consistent.
278 CRM_Utils_Array
::remove($params, 'flip', 'fresh');
280 $cacheKey = $daoName . $fieldName . serialize($params);
282 // Retrieve cached options
283 if (isset(self
::$cache[$cacheKey]) && empty($params['fresh'])) {
284 $output = self
::$cache[$cacheKey];
287 // Get list of fields for the option table
288 $daoName = CRM_Core_AllCoreTables
::getClassForTable($pseudoconstant['table']);
290 $availableFields = array_keys($dao->fieldKeys());
291 if (in_array('is_active', $availableFields)) {
292 $wheres[] = 'is_active = 1';
296 $select = "SELECT %1 AS id, %2 AS label";
299 $order = "ORDER BY %2";
300 // Condition param can be passed as an sql string
301 if (!empty($params['condition'])) {
302 $wheres[] = $params['condition'];
304 // Support for onlyActive param if option table contains is_active field
305 if (!empty($params['onlyActive'])) {
306 if (in_array('is_active', $availableFields)) {
307 $wheres[] = 'is_active = 1';
310 $queryParams = array(
311 1 => array($params['keyColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
312 2 => array($params['labelColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
313 3 => array($pseudoconstant['table'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
315 // Add orderColumn param
316 if (!empty($params['orderColumn'])) {
317 $queryParams[4] = array($params['orderColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
);
318 $order = "ORDER BY %4";
320 // Support no sorting if $params[orderColumn] is FALSE
321 elseif (isset($params['orderColumn']) && $params['orderColumn'] === FALSE) {
324 // Default to 'weight' if that column exists
325 elseif (in_array('weight', $availableFields)) {
326 $order = "ORDER BY weight";
330 $query = "$select $from";
332 $query .= " WHERE " . implode($wheres, ' AND ');
334 $query .= ' ' . $order;
335 $dao = CRM_Core_DAO
::executeQuery($query, $queryParams);
336 while ($dao->fetch()) {
337 $output[$dao->id
] = $dao->label
;
340 if (!empty($params['localize'])) {
341 $i18n = CRM_Core_I18n
::singleton();
342 $i18n->localizeArray($output);
343 // Maintain sort by label
344 if ($order == "ORDER BY %2") {
345 CRM_Utils_Array
::asort($output);
348 self
::$cache[$cacheKey] = $output;
350 return $flip ?
array_flip($output) : $output;
353 // If we're still here, it's an error. Return FALSE.
358 * populate the object from the database. generic populate
361 * The static array $var is populated from the db
362 * using the <b>$name DAO</b>.
364 * Note: any database errors will be trapped by the DAO.
366 * @param array $var the associative array we will fill
367 * @param string $name the name of the DAO
368 * @param boolean $all get all objects. default is to get only active ones.
369 * @param string $retrieve the field that we are interested in (normally name, differs in some objects)
370 * @param string $filter the field that we want to filter the result set with
371 * @param string $condition the condition that gets passed to the final query as the WHERE clause
377 public static function populate(
382 $filter = 'is_active',
388 $cacheKey = "CRM_PC_{$name}_{$all}_{$key}_{$retrieve}_{$filter}_{$condition}_{$orderby}";
389 $cache = CRM_Utils_Cache
::singleton();
390 $var = $cache->get($cacheKey);
391 if ($var && empty($force)) {
395 $object = new $name ( );
397 $object->selectAdd();
398 $object->selectAdd("$key, $retrieve");
400 $object->whereAdd($condition);
404 $object->orderBy($retrieve);
407 $object->orderBy($orderby);
411 $object->$filter = 1;
416 while ($object->fetch()) {
417 $var[$object->$key] = $object->$retrieve;
420 $cache->set($cacheKey, $var);
424 * Flush given pseudoconstant so it can be reread from db
425 * nex time it's requested.
430 * @param boolean $name pseudoconstant to be flushed
433 public static function flush($name = 'cache') {
434 if (property_exists(self
, $name)) {
440 * Get all Activty types.
442 * The static array activityType is returned
444 * @param boolean $all - get All Activity types - default is to get only active ones.
449 * @return array - array reference of all activity types.
451 public static function &activityType() {
452 $args = func_get_args();
453 $all = CRM_Utils_Array
::value(0, $args, TRUE);
454 $includeCaseActivities = CRM_Utils_Array
::value(1, $args, FALSE);
455 $reset = CRM_Utils_Array
::value(2, $args, FALSE);
456 $returnColumn = CRM_Utils_Array
::value(3, $args, 'label');
457 $includeCampaignActivities = CRM_Utils_Array
::value(4, $args, FALSE);
458 $onlyComponentActivities = CRM_Utils_Array
::value(5, $args, FALSE);
459 $index = (int) $all . '_' . $returnColumn . '_' . (int) $includeCaseActivities;
460 $index .= '_' . (int) $includeCampaignActivities;
461 $index .= '_' . (int) $onlyComponentActivities;
463 if (NULL === self
::$activityType) {
464 self
::$activityType = array();
467 if (!isset(self
::$activityType[$index]) ||
$reset) {
470 $condition = 'AND filter = 0';
472 $componentClause = " v.component_id IS NULL";
473 if ($onlyComponentActivities) {
474 $componentClause = " v.component_id IS NOT NULL";
477 $componentIds = array();
478 $compInfo = CRM_Core_Component
::getEnabledComponents();
480 // build filter for listing activity types only if their
481 // respective components are enabled
482 foreach ($compInfo as $compName => $compObj) {
483 if ($compName == 'CiviCase') {
484 if ($includeCaseActivities) {
485 $componentIds[] = $compObj->componentID
;
488 elseif ($compName == 'CiviCampaign') {
489 if ($includeCampaignActivities) {
490 $componentIds[] = $compObj->componentID
;
494 $componentIds[] = $compObj->componentID
;
498 if (count($componentIds)) {
499 $componentIds = implode(',', $componentIds);
500 $componentClause = " ($componentClause OR v.component_id IN ($componentIds))";
501 if ($onlyComponentActivities) {
502 $componentClause = " ( v.component_id IN ($componentIds ) )";
505 $condition = $condition . ' AND ' . $componentClause;
507 self
::$activityType[$index] = CRM_Core_OptionGroup
::values('activity_type', FALSE, FALSE, FALSE, $condition, $returnColumn);
509 return self
::$activityType[$index];
513 * Get all payment-processor billing modes
518 * @return array ($id => $name)
520 public static function billingMode() {
521 if (!self
::$billingMode) {
522 self
::$billingMode = array(
523 CRM_Core_Payment
::BILLING_MODE_FORM
=> 'form',
524 CRM_Core_Payment
::BILLING_MODE_BUTTON
=> 'button',
525 CRM_Core_Payment
::BILLING_MODE_NOTIFY
=> 'notify',
528 return self
::$billingMode;
532 * Get all the State/Province from database.
534 * The static array stateProvince is returned, and if it's
535 * called the first time, the <b>State Province DAO</b> is used
536 * to get all the States.
538 * Note: any database errors will be trapped by the DAO.
543 * @param int $id - Optional id to return
545 * @return array - array reference of all State/Provinces.
548 public static function &stateProvince($id = FALSE, $limit = TRUE) {
549 if (($id && !CRM_Utils_Array
::value($id, self
::$stateProvince)) ||
!self
::$stateProvince ||
!$id) {
550 $whereClause = FALSE;
551 $config = CRM_Core_Config
::singleton();
553 $countryIsoCodes = self
::countryIsoCode();
554 $limitCodes = $config->provinceLimit();
556 foreach ($limitCodes as $code) {
557 $limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
559 if (!empty($limitIds)) {
560 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
563 $whereClause = FALSE;
566 self
::populate(self
::$stateProvince, 'CRM_Core_DAO_StateProvince', TRUE, 'name', 'is_active', $whereClause);
568 // localise the province names if in an non-en_US locale
570 if ($tsLocale != '' and $tsLocale != 'en_US') {
571 $i18n = CRM_Core_I18n
::singleton();
572 $i18n->localizeArray(self
::$stateProvince, array(
573 'context' => 'province',
575 self
::$stateProvince = CRM_Utils_Array
::asort(self
::$stateProvince);
579 if (array_key_exists($id, self
::$stateProvince)) {
580 return self
::$stateProvince[$id];
587 return self
::$stateProvince;
591 * Get all the State/Province abbreviations from the database.
593 * Same as above, except gets the abbreviations instead of the names.
598 * @param int $id - Optional id to return
600 * @return array - array reference of all State/Province abbreviations.
602 public static function &stateProvinceAbbreviation($id = FALSE, $limit = TRUE) {
606 FROM civicrm_state_province
614 return CRM_Core_DAO
::singleValueQuery($query, $params);
617 if (!self
::$stateProvinceAbbreviation ||
!$id) {
619 $whereClause = FALSE;
622 $config = CRM_Core_Config
::singleton();
623 $countryIsoCodes = self
::countryIsoCode();
624 $limitCodes = $config->provinceLimit();
626 foreach ($limitCodes as $code) {
627 $tmpArray = array_keys($countryIsoCodes, $code);
629 if (!empty($tmpArray)) {
630 $limitIds[] = array_shift($tmpArray);
633 if (!empty($limitIds)) {
634 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
637 self
::populate(self
::$stateProvinceAbbreviation, 'CRM_Core_DAO_StateProvince', TRUE, 'abbreviation', 'is_active', $whereClause);
641 if (array_key_exists($id, self
::$stateProvinceAbbreviation)) {
642 return self
::$stateProvinceAbbreviation[$id];
649 return self
::$stateProvinceAbbreviation;
653 * Get all the countries from database.
655 * The static array country is returned, and if it's
656 * called the first time, the <b>Country DAO</b> is used
657 * to get all the countries.
659 * Note: any database errors will be trapped by the DAO.
664 * @param int $id - Optional id to return
666 * @return array - array reference of all countries.
669 public static function country($id = FALSE, $applyLimit = TRUE) {
670 if (($id && !CRM_Utils_Array
::value($id, self
::$country)) ||
!self
::$country ||
!$id) {
672 $config = CRM_Core_Config
::singleton();
673 $limitCodes = array();
676 // limit the country list to the countries specified in CIVICRM_COUNTRY_LIMIT
677 // (ensuring it's a subset of the legal values)
678 // K/P: We need to fix this, i dont think it works with new setting files
679 $limitCodes = $config->countryLimit();
680 if (!is_array($limitCodes)) {
682 $config->countryLimit
=> 1,
686 $limitCodes = array_intersect(self
::countryIsoCode(), $limitCodes);
689 if (count($limitCodes)) {
690 $whereClause = "iso_code IN ('" . implode("', '", $limitCodes) . "')";
696 self
::populate(self
::$country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active', $whereClause);
698 // if default country is set, percolate it to the top
699 if ($config->defaultContactCountry()) {
700 $countryIsoCodes = self
::countryIsoCode();
701 $defaultID = array_search($config->defaultContactCountry(), $countryIsoCodes);
702 if ($defaultID !== FALSE) {
703 $default[$defaultID] = CRM_Utils_Array
::value($defaultID, self
::$country);
704 self
::$country = $default + self
::$country;
708 // localise the country names if in an non-en_US locale
710 if ($tsLocale != '' and $tsLocale != 'en_US') {
711 $i18n = CRM_Core_I18n
::singleton();
712 $i18n->localizeArray(self
::$country, array(
713 'context' => 'country',
715 self
::$country = CRM_Utils_Array
::asort(self
::$country);
719 if (array_key_exists($id, self
::$country)) {
720 return self
::$country[$id];
723 return CRM_Core_DAO
::$_nullObject;
726 return self
::$country;
730 * Get all the country ISO Code abbreviations from the database.
732 * The static array countryIsoCode is returned, and if it's
733 * called the first time, the <b>Country DAO</b> is used
734 * to get all the countries' ISO codes.
736 * Note: any database errors will be trapped by the DAO.
741 * @return array - array reference of all country ISO codes.
744 public static function &countryIsoCode($id = FALSE) {
745 if (!self
::$countryIsoCode) {
746 self
::populate(self
::$countryIsoCode, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
749 if (array_key_exists($id, self
::$countryIsoCode)) {
750 return self
::$countryIsoCode[$id];
753 return CRM_Core_DAO
::$_nullObject;
756 return self
::$countryIsoCode;
760 * Get all groups from database
762 * The static array group is returned, and if it's
763 * called the first time, the <b>Group DAO</b> is used
764 * to get all the groups.
766 * Note: any database errors will be trapped by the DAO.
768 * @param string $groupType type of group(Access/Mailing)
769 * @param boolen $excludeHidden exclude hidden groups.
774 * @return array - array reference of all groups.
777 public static function &allGroup($groupType = NULL, $excludeHidden = TRUE) {
778 $condition = CRM_Contact_BAO_Group
::groupTypeCondition($groupType, $excludeHidden);
781 self
::$group = array();
784 $groupKey = $groupType ?
$groupType : 'null';
786 if (!isset(self
::$group[$groupKey])) {
787 self
::$group[$groupKey] = NULL;
788 self
::populate(self
::$group[$groupKey], 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition);
790 return self
::$group[$groupKey];
794 * Create or get groups iterator (iterates over nested groups in a
797 * The GroupNesting instance is returned; it's created if this is being
798 * called for the first time
804 * @return mixed - instance of CRM_Contact_BAO_GroupNesting
807 public static function &groupIterator($styledLabels = FALSE) {
808 if (!self
::$groupIterator) {
810 When used as an object, GroupNesting implements Iterator
811 and iterates nested groups in a logical manner for us
813 self
::$groupIterator = new CRM_Contact_BAO_GroupNesting($styledLabels);
815 return self
::$groupIterator;
819 * Get all permissioned groups from database
821 * The static array group is returned, and if it's
822 * called the first time, the <b>Group DAO</b> is used
823 * to get all the groups.
825 * Note: any database errors will be trapped by the DAO.
827 * @param string $groupType type of group(Access/Mailing)
828 * @param boolen $excludeHidden exclude hidden groups.
833 * @return array - array reference of all groups.
836 public static function group($groupType = NULL, $excludeHidden = TRUE) {
837 return CRM_Core_Permission
::group($groupType, $excludeHidden);
841 * Get all permissioned groups from database
843 * The static array group is returned, and if it's
844 * called the first time, the <b>Group DAO</b> is used
845 * to get all the groups.
847 * Note: any database errors will be trapped by the DAO.
852 * @return array - array reference of all groups.
855 public static function &staticGroup($onlyPublic = FALSE, $groupType = NULL, $excludeHidden = TRUE) {
856 if (!self
::$staticGroup) {
857 $condition = 'saved_search_id = 0 OR saved_search_id IS NULL';
859 $condition .= " AND visibility != 'User and User Admin Only'";
863 $condition .= ' AND ' . CRM_Contact_BAO_Group
::groupTypeCondition($groupType);
866 if ($excludeHidden) {
867 $condition .= ' AND is_hidden != 1 ';
870 self
::populate(self
::$staticGroup, 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition, 'title');
873 return self
::$staticGroup;
877 * Get all Relationship Types from database.
879 * The static array group is returned, and if it's
880 * called the first time, the <b>RelationshipType DAO</b> is used
881 * to get all the relationship types.
883 * Note: any database errors will be trapped by the DAO.
885 * @param string $valueColumnName db column name/label.
886 * @param boolean $reset reset relationship types if true
891 * @return array - array reference of all relationship types.
893 public static function &relationshipType($valueColumnName = 'label', $reset = FALSE) {
894 if (!CRM_Utils_Array
::value($valueColumnName, self
::$relationshipType) ||
$reset) {
895 self
::$relationshipType[$valueColumnName] = array();
897 //now we have name/label columns CRM-3336
898 $column_a_b = "{$valueColumnName}_a_b";
899 $column_b_a = "{$valueColumnName}_b_a";
901 $relationshipTypeDAO = new CRM_Contact_DAO_RelationshipType();
902 $relationshipTypeDAO->selectAdd();
903 $relationshipTypeDAO->selectAdd("id, {$column_a_b}, {$column_b_a}, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b");
904 $relationshipTypeDAO->is_active
= 1;
905 $relationshipTypeDAO->find();
906 while ($relationshipTypeDAO->fetch()) {
908 self
::$relationshipType[$valueColumnName][$relationshipTypeDAO->id
] = array(
909 $column_a_b => $relationshipTypeDAO->$column_a_b,
910 $column_b_a => $relationshipTypeDAO->$column_b_a,
911 'contact_type_a' => "$relationshipTypeDAO->contact_type_a",
912 'contact_type_b' => "$relationshipTypeDAO->contact_type_b",
913 'contact_sub_type_a' => "$relationshipTypeDAO->contact_sub_type_a",
914 'contact_sub_type_b' => "$relationshipTypeDAO->contact_sub_type_b",
919 return self
::$relationshipType[$valueColumnName];
923 * get all the ISO 4217 currency codes
925 * so far, we use this for validation only, so there's no point of putting this into the database
929 * @return array - array reference of all currency codes
932 public static function ¤cyCode() {
933 if (!self
::$currencyCode) {
934 self
::$currencyCode = array(
1204 return self
::$currencyCode;
1208 * Get all the County from database.
1210 * The static array county is returned, and if it's
1211 * called the first time, the <b>County DAO</b> is used
1212 * to get all the Counties.
1214 * Note: any database errors will be trapped by the DAO.
1219 * @param int $id - Optional id to return
1221 * @return array - array reference of all Counties
1224 public static function &county($id = FALSE) {
1225 if (!self
::$county) {
1227 $config = CRM_Core_Config
::singleton();
1228 // order by id so users who populate civicrm_county can have more control over sort by the order they load the counties
1229 self
::populate(self
::$county, 'CRM_Core_DAO_County', TRUE, 'name', NULL, NULL, 'id');
1232 if (array_key_exists($id, self
::$county)) {
1233 return self
::$county[$id];
1236 return CRM_Core_DAO
::$_nullObject;
1239 return self
::$county;
1243 * Get all active payment processors
1245 * The static array paymentProcessor is returned
1250 * @param boolean $all - get payment processors - default is to get only active ones.
1251 * @param boolean $test - get test payment processors
1253 * @return array - array of all payment processors
1256 public static function &paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
1257 $condition = "is_test = ";
1258 $condition .= ($test) ?
'1' : '0';
1260 if ($additionalCond) {
1261 $condition .= " AND ( $additionalCond ) ";
1264 // CRM-7178. Make sure we only include payment processors valid in ths
1266 $condition .= " AND domain_id = " . CRM_Core_Config
::domainID();
1268 $cacheKey = $condition . '_' . (int) $all;
1269 if (!isset(self
::$paymentProcessor[$cacheKey])) {
1270 self
::populate(self
::$paymentProcessor[$cacheKey], 'CRM_Financial_DAO_PaymentProcessor', $all, 'name', 'is_active', $condition, 'is_default desc, name');
1273 return self
::$paymentProcessor[$cacheKey];
1277 * Get all active payment processors
1279 * The static array paymentProcessorType is returned
1284 * @param boolean $all - get payment processors - default is to get only active ones.
1286 * @return array - array of all payment processor types
1289 public static function &paymentProcessorType($all = FALSE, $id = NULL, $return = 'title') {
1290 $cacheKey = $id . '_' .$return;
1291 if (empty(self
::$paymentProcessorType[$cacheKey])) {
1292 self
::populate(self
::$paymentProcessorType[$cacheKey], 'CRM_Financial_DAO_PaymentProcessorType', $all, $return, 'is_active', NULL, "is_default, $return", 'id');
1294 if ($id && CRM_Utils_Array
::value($id, self
::$paymentProcessorType[$cacheKey])) {
1295 return self
::$paymentProcessorType[$cacheKey][$id];
1297 return self
::$paymentProcessorType[$cacheKey];
1301 * Get all the World Regions from Database
1305 * @return array - array reference of all World Regions
1308 public static function &worldRegion($id = FALSE) {
1309 if (!self
::$worldRegions) {
1310 self
::populate(self
::$worldRegions, 'CRM_Core_DAO_Worldregion', TRUE, 'name', NULL, NULL, 'id');
1314 if (array_key_exists($id, self
::$worldRegions)) {
1315 return self
::$worldRegions[$id];
1318 return CRM_Core_DAO
::$_nullObject;
1322 return self
::$worldRegions;
1326 * Get all Activity Statuses.
1328 * The static array activityStatus is returned
1333 * @return array - array reference of all activity statuses
1335 public static function &activityStatus($column = 'label') {
1336 if (NULL === self
::$activityStatus) {
1337 self
::$activityStatus = array();
1339 if (!array_key_exists($column, self
::$activityStatus)) {
1340 self
::$activityStatus[$column] = array();
1342 self
::$activityStatus[$column] = CRM_Core_OptionGroup
::values('activity_status', FALSE, FALSE, FALSE, NULL, $column);
1345 return self
::$activityStatus[$column];
1349 * Get all Visibility levels.
1351 * The static array visibility is returned
1356 * @return array - array reference of all Visibility levels.
1359 public static function &visibility($column = 'label') {
1360 if (!isset(self
::$visibility)) {
1361 self
::$visibility = array( );
1364 if (!isset(self
::$visibility[$column])) {
1365 self
::$visibility[$column] = CRM_Core_OptionGroup
::values('visibility', FALSE, FALSE, FALSE, NULL, $column);
1368 return self
::$visibility[$column];
1371 public static function &stateProvinceForCountry($countryID, $field = 'name') {
1372 static $_cache = NULL;
1374 $cacheKey = "{$countryID}_{$field}";
1379 if (!empty($_cache[$cacheKey])) {
1380 return $_cache[$cacheKey];
1384 SELECT civicrm_state_province.{$field} name, civicrm_state_province.id id
1385 FROM civicrm_state_province
1386 WHERE country_id = %1
1395 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1398 while ($dao->fetch()) {
1399 $result[$dao->id
] = $dao->name
;
1402 // localise the stateProvince names if in an non-en_US locale
1403 $config = CRM_Core_Config
::singleton();
1405 if ($tsLocale != '' and $tsLocale != 'en_US') {
1406 $i18n = CRM_Core_I18n
::singleton();
1407 $i18n->localizeArray($result, array(
1408 'context' => 'province',
1410 $result = CRM_Utils_Array
::asort($result);
1413 $_cache[$cacheKey] = $result;
1415 CRM_Utils_Hook
::buildStateProvinceForCountry($countryID, $result);
1420 public static function &countyForState($stateID) {
1421 if (is_array($stateID)) {
1422 $states = implode(", ", $stateID);
1424 SELECT civicrm_county.name name, civicrm_county.id id, civicrm_state_province.abbreviation abbreviation
1426 LEFT JOIN civicrm_state_province ON civicrm_county.state_province_id = civicrm_state_province.id
1427 WHERE civicrm_county.state_province_id in ( $states )
1428 ORDER BY civicrm_state_province.abbreviation, civicrm_county.name";
1430 $dao = CRM_Core_DAO
::executeQuery($query);
1433 while ($dao->fetch()) {
1434 $result[$dao->id
] = $dao->abbreviation
. ': ' . $dao->name
;
1439 static $_cache = NULL;
1441 $cacheKey = "{$stateID}_name";
1446 if (!empty($_cache[$cacheKey])) {
1447 return $_cache[$cacheKey];
1451 SELECT civicrm_county.name name, civicrm_county.id id
1453 WHERE state_province_id = %1
1462 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1465 while ($dao->fetch()) {
1466 $result[$dao->id
] = $dao->name
;
1474 * Given a state ID return the country ID, this allows
1475 * us to populate forms and values for downstream code
1477 * @param $stateID int
1479 * @return int the country id that the state belongs to
1483 static function countryIDForStateID($stateID) {
1484 if (empty($stateID)) {
1485 return CRM_Core_DAO
::$_nullObject;
1490 FROM civicrm_state_province
1493 $params = array(1 => array($stateID, 'Integer'));
1495 return CRM_Core_DAO
::singleValueQuery($query, $params);
1499 * Get all types of Greetings.
1501 * The static array of greeting is returned
1506 * @param $filter - get All Email Greetings - default is to get only active ones.
1508 * @return array - array reference of all greetings.
1511 public static function greeting($filter, $columnName = 'label') {
1512 $index = $filter['greeting_type'] . '_' . $columnName;
1514 // also add contactType to the array
1515 $contactType = CRM_Utils_Array
::value('contact_type', $filter);
1517 $index .= '_' . $contactType;
1520 if (NULL === self
::$greeting) {
1521 self
::$greeting = array();
1524 if (!CRM_Utils_Array
::value($index, self
::$greeting)) {
1525 $filterCondition = NULL;
1527 $filterVal = 'v.filter =';
1528 switch ($contactType) {
1537 case 'Organization':
1541 $filterCondition .= "AND (v.filter = 0 OR {$filterVal}) ";
1544 self
::$greeting[$index] = CRM_Core_OptionGroup
::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName);
1547 return self
::$greeting[$index];
1551 * Construct array of default greeting values for contact type
1556 * @return array - array reference of default greetings.
1559 public static function &greetingDefaults() {
1560 if (!self
::$greetingDefaults) {
1561 $defaultGreetings = array();
1562 $contactTypes = self
::get('CRM_Contact_DAO_Contact', 'contact_type', array('keyColumn' => 'id', 'labelColumn' => 'name'));
1564 foreach ($contactTypes as $filter => $contactType) {
1565 $filterCondition = " AND (v.filter = 0 OR v.filter = $filter) AND v.is_default = 1 ";
1567 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
1568 $tokenVal = CRM_Core_OptionGroup
::values($greeting, NULL, NULL, NULL, $filterCondition, 'label');
1569 $defaultGreetings[$contactType][$greeting] = $tokenVal;
1573 self
::$greetingDefaults = $defaultGreetings;
1576 return self
::$greetingDefaults;
1580 * Get all the Languages from database.
1585 * @return array self::languages - array reference of all languages
1588 public static function &languages() {
1589 return CRM_Core_I18n_PseudoConstant
::languages();
1595 public static function &preferredLanguage() {
1596 return CRM_Core_I18n_PseudoConstant
::languages();
1600 * Get all extensions
1602 * The static array extensions
1604 * FIXME: This is called by civix but not by any core code. We
1605 * should provide an API call which civix can use instead.
1610 * @return array - array($fullyQualifiedName => $label) list of extensions
1612 public static function &getExtensions() {
1613 if (!self
::$extensions) {
1614 self
::$extensions = array();
1616 SELECT full_name, label
1617 FROM civicrm_extension
1620 $dao = CRM_Core_DAO
::executeQuery($sql);
1621 while ($dao->fetch()) {
1622 self
::$extensions[$dao->full_name
] = $dao->label
;
1626 return self
::$extensions;
1630 * Fetch the list of active extensions of type 'module'
1632 * @param $fresh bool whether to forcibly reload extensions list from canonical store
1636 * @return array - array(array('prefix' => $, 'file' => $))
1638 public static function getModuleExtensions($fresh = FALSE) {
1639 return CRM_Extension_System
::singleton()->getMapper()->getActiveModuleFiles($fresh);
1643 * Get all options values
1645 * The static array option values is returned
1650 * @param boolean $optionGroupName - get All Option Group values- default is to get only active ones.
1652 * @return array - array reference of all Option Group Name
1655 public static function accountOptionValues($optionGroupName, $id = null, $condition = null) {
1656 $cacheKey = $optionGroupName . '_' . $condition;
1657 if (empty(self
::$accountOptionValues[$cacheKey])) {
1658 self
::$accountOptionValues[$cacheKey] = CRM_Core_OptionGroup
::values($optionGroupName, false, false, false, $condition);
1661 return CRM_Utils_Array
::value($id, self
::$accountOptionValues[$cacheKey]);
1664 return self
::$accountOptionValues[$cacheKey];