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;
60 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
66 private static $activityType;
73 private static $stateProvince;
80 private static $county;
83 * states/provinces abbreviations
87 private static $stateProvinceAbbreviation;
94 private static $country;
101 private static $countryIsoCode;
104 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
110 private static $group;
117 private static $groupIterator;
124 private static $relationshipType;
127 * civicrm groups that are not smart groups
131 private static $staticGroup;
138 private static $currencyCode;
145 private static $paymentProcessor;
148 * payment processor types
152 private static $paymentProcessorType;
159 private static $worldRegions;
162 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
168 private static $activityStatus;
175 private static $visibility;
182 private static $greeting;
189 private static $greetingDefaults;
192 * Extensions of type module
196 private static $extensions;
199 * Financial Account Type
203 private static $accountOptionValues;
206 * Low-level option getter, rarely accessed directly.
207 * NOTE: Rather than calling this function directly use CRM_*_BAO_*::buildOptions()
209 * @param String $daoName
210 * @param String $fieldName
211 * @param Array $params
212 * - name string name of the option group
213 * - flip boolean results are return in id => label format if false
214 * if true, the results are reversed
215 * - grouping boolean if true, return the value in 'grouping' column (currently unsupported for tables other than option_value)
216 * - localize boolean if true, localize the results before returning
217 * - condition string|array add condition(s) to the sql query - will be concatenated using 'AND'
218 * - keyColumn string the column to use for 'id'
219 * - labelColumn string the column to use for 'label'
220 * - orderColumn string the column to use for sorting, defaults to 'weight' column if one exists, else defaults to labelColumn
221 * - onlyActive boolean return only the action option values
222 * - fresh boolean ignore cache entries and go back to DB
224 * @return Array on success, FALSE on error.
228 public static function get($daoName, $fieldName, $params = array()) {
229 $flip = !empty($params['flip']);
231 // Custom fields are not in the schema
232 if (strpos($fieldName, 'custom') === 0 && is_numeric($fieldName[7])) {
233 $dao = new CRM_Core_DAO_CustomField
;
234 $dao->id
= (int) substr($fieldName, 7);
236 $customField = (array) $dao;
239 CRM_Core_BAO_CustomField
::buildOption($customField, $output);
240 // @see FIXME note in CRM_Core_BAO_CustomField::buildOption()
241 unset($output['attributes']);
242 return $flip ?
array_flip($output) : $output;
245 // Core field: load schema
247 $fields = $dao->fields();
248 $fieldKeys = $dao->fieldKeys();
249 $fieldKey = $fieldKeys[$fieldName];
251 if (empty($fields[$fieldKey])) {
254 $fieldSpec = $fields[$fieldKey];
256 // If the field is an enum, explode the enum definition and return the array.
257 if (isset($fieldSpec['enumValues'])) {
258 // use of a space after the comma is inconsistent in xml
259 $enumStr = str_replace(', ', ',', $fieldSpec['enumValues']);
260 $output = explode(',', $enumStr);
261 return $flip ?
array_flip($output) : $output;
264 elseif (!empty($fieldSpec['pseudoconstant'])) {
265 $pseudoconstant = $fieldSpec['pseudoconstant'];
266 // Merge params with defaults
270 'condition' => CRM_Utils_Array
::value('condition', $pseudoconstant),
271 'keyColumn' => CRM_Utils_Array
::value('keyColumn', $pseudoconstant),
272 'labelColumn' => CRM_Utils_Array
::value('labelColumn', $pseudoconstant),
273 'onlyActive' => TRUE,
277 // Fetch option group from option_value table
278 if(!empty($pseudoconstant['optionGroupName'])) {
279 // Call our generic fn for retrieving from the option_value table
280 return CRM_Core_OptionGroup
::values(
281 $pseudoconstant['optionGroupName'],
285 $params['condition'] ?
' AND ' . implode(' AND ', (array) $params['condition']) : NULL,
286 $params['labelColumn'] ?
$params['labelColumn'] : 'label',
287 $params['onlyActive'],
289 $params['keyColumn'] ?
$params['keyColumn'] : 'value'
293 // Fetch options from other tables
294 if (!empty($pseudoconstant['table'])) {
295 // Normalize params so the serialized cache string will be consistent.
296 CRM_Utils_Array
::remove($params, 'flip', 'fresh');
298 $cacheKey = $daoName . $fieldName . serialize($params);
300 // Retrieve cached options
301 if (isset(self
::$cache[$cacheKey]) && empty($params['fresh'])) {
302 $output = self
::$cache[$cacheKey];
305 $daoName = CRM_Core_DAO_AllCoreTables
::getClassForTable($pseudoconstant['table']);
306 if (!class_exists($daoName)) {
309 // Get list of fields for the option table
311 $availableFields = array_keys($dao->fieldKeys());
312 if (in_array('is_active', $availableFields)) {
313 $wheres[] = 'is_active = 1';
317 $select = "SELECT %1 AS id, %2 AS label";
320 $order = "ORDER BY %2";
321 // Condition param can be passed as an sql clause string or an array of clauses
322 if (!empty($params['condition'])) {
323 $wheres[] = implode(' AND ', (array) $params['condition']);
325 // onlyActive param will automatically filter on common flags
326 if (!empty($params['onlyActive'])) {
327 foreach (array('is_active' => 1, 'is_deleted' => 0, 'is_test' => 0) as $flag => $val) {
328 if (in_array($flag, $availableFields)) {
329 $wheres[] = "$flag = $val";
333 // Filter domain specific options
334 if (in_array('domain_id', $availableFields)) {
335 $wheres[] = 'domain_id = ' . CRM_Core_Config
::domainID();
337 $queryParams = array(
338 1 => array($params['keyColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
339 2 => array($params['labelColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
340 3 => array($pseudoconstant['table'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
342 // Add orderColumn param
343 if (!empty($params['orderColumn'])) {
344 $queryParams[4] = array($params['orderColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
);
345 $order = "ORDER BY %4";
347 // Support no sorting if $params[orderColumn] is FALSE
348 elseif (isset($params['orderColumn']) && $params['orderColumn'] === FALSE) {
351 // Default to 'weight' if that column exists
352 elseif (in_array('weight', $availableFields)) {
353 $order = "ORDER BY weight";
357 $query = "$select $from";
359 $query .= " WHERE " . implode($wheres, ' AND ');
361 $query .= ' ' . $order;
362 $dao = CRM_Core_DAO
::executeQuery($query, $queryParams);
363 while ($dao->fetch()) {
364 $output[$dao->id
] = $dao->label
;
367 if (!empty($params['localize'])) {
368 $i18n = CRM_Core_I18n
::singleton();
369 $i18n->localizeArray($output);
370 // Maintain sort by label
371 if ($order == "ORDER BY %2") {
372 CRM_Utils_Array
::asort($output);
375 self
::$cache[$cacheKey] = $output;
377 return $flip ?
array_flip($output) : $output;
380 // If we're still here, it's an error. Return FALSE.
385 * Fetch the label (or other value) for a field given its key
387 * @param String $daoName
388 * @param String $fieldName
389 * @param String|Int $key
390 * @param Array $params will be passed into self::get
394 static function getValue($daoName, $fieldName, $key, $params = array()) {
395 $values = self
::get($daoName, $fieldName, $params);
396 return CRM_Utils_Array
::value($key, $values);
400 * Fetch the key for a field option given its label/name
402 * @param String $daoName
403 * @param String $fieldName
404 * @param String|Int $value
405 * @param Array $params will be passed into self::get
409 static function getKey($daoName, $fieldName, $value, $params = array()) {
410 $values = self
::get($daoName, $fieldName, $params);
411 return CRM_Utils_Array
::key($value, $values);
415 * DEPRECATED generic populate method
416 * All pseudoconstant functions that use this method are also deprecated.
418 * The static array $var is populated from the db
419 * using the <b>$name DAO</b>.
421 * Note: any database errors will be trapped by the DAO.
423 * @param array $var the associative array we will fill
424 * @param string $name the name of the DAO
425 * @param boolean $all get all objects. default is to get only active ones.
426 * @param string $retrieve the field that we are interested in (normally name, differs in some objects)
427 * @param string $filter the field that we want to filter the result set with
428 * @param string $condition the condition that gets passed to the final query as the WHERE clause
434 public static function populate(
439 $filter = 'is_active',
445 $cacheKey = "CRM_PC_{$name}_{$all}_{$key}_{$retrieve}_{$filter}_{$condition}_{$orderby}";
446 $cache = CRM_Utils_Cache
::singleton();
447 $var = $cache->get($cacheKey);
448 if ($var && empty($force)) {
452 $object = new $name ( );
454 $object->selectAdd();
455 $object->selectAdd("$key, $retrieve");
457 $object->whereAdd($condition);
461 $object->orderBy($retrieve);
464 $object->orderBy($orderby);
468 $object->$filter = 1;
473 while ($object->fetch()) {
474 $var[$object->$key] = $object->$retrieve;
477 $cache->set($cacheKey, $var);
481 * Flush given pseudoconstant so it can be reread from db
482 * nex time it's requested.
487 * @param boolean $name pseudoconstant to be flushed
490 public static function flush($name = 'cache') {
491 if (isset(self
::$
$name)) {
494 if ($name == 'cache') {
495 CRM_Core_OptionGroup
::flushAll();
500 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
502 * Get all Activty types.
504 * The static array activityType is returned
506 * @param boolean $all - get All Activity types - default is to get only active ones.
511 * @return array - array reference of all activity types.
513 public static function &activityType() {
514 $args = func_get_args();
515 $all = CRM_Utils_Array
::value(0, $args, TRUE);
516 $includeCaseActivities = CRM_Utils_Array
::value(1, $args, FALSE);
517 $reset = CRM_Utils_Array
::value(2, $args, FALSE);
518 $returnColumn = CRM_Utils_Array
::value(3, $args, 'label');
519 $includeCampaignActivities = CRM_Utils_Array
::value(4, $args, FALSE);
520 $onlyComponentActivities = CRM_Utils_Array
::value(5, $args, FALSE);
521 $index = (int) $all . '_' . $returnColumn . '_' . (int) $includeCaseActivities;
522 $index .= '_' . (int) $includeCampaignActivities;
523 $index .= '_' . (int) $onlyComponentActivities;
525 if (NULL === self
::$activityType) {
526 self
::$activityType = array();
529 if (!isset(self
::$activityType[$index]) ||
$reset) {
532 $condition = 'AND filter = 0';
534 $componentClause = " v.component_id IS NULL";
535 if ($onlyComponentActivities) {
536 $componentClause = " v.component_id IS NOT NULL";
539 $componentIds = array();
540 $compInfo = CRM_Core_Component
::getEnabledComponents();
542 // build filter for listing activity types only if their
543 // respective components are enabled
544 foreach ($compInfo as $compName => $compObj) {
545 if ($compName == 'CiviCase') {
546 if ($includeCaseActivities) {
547 $componentIds[] = $compObj->componentID
;
550 elseif ($compName == 'CiviCampaign') {
551 if ($includeCampaignActivities) {
552 $componentIds[] = $compObj->componentID
;
556 $componentIds[] = $compObj->componentID
;
560 if (count($componentIds)) {
561 $componentIds = implode(',', $componentIds);
562 $componentClause = " ($componentClause OR v.component_id IN ($componentIds))";
563 if ($onlyComponentActivities) {
564 $componentClause = " ( v.component_id IN ($componentIds ) )";
567 $condition = $condition . ' AND ' . $componentClause;
569 self
::$activityType[$index] = CRM_Core_OptionGroup
::values('activity_type', FALSE, FALSE, FALSE, $condition, $returnColumn);
571 return self
::$activityType[$index];
575 * Get all the State/Province from database.
577 * The static array stateProvince is returned, and if it's
578 * called the first time, the <b>State Province DAO</b> is used
579 * to get all the States.
581 * Note: any database errors will be trapped by the DAO.
586 * @param int $id - Optional id to return
588 * @return array - array reference of all State/Provinces.
591 public static function &stateProvince($id = FALSE, $limit = TRUE) {
592 if (($id && !CRM_Utils_Array
::value($id, self
::$stateProvince)) ||
!self
::$stateProvince ||
!$id) {
593 $whereClause = FALSE;
594 $config = CRM_Core_Config
::singleton();
596 $countryIsoCodes = self
::countryIsoCode();
597 $limitCodes = $config->provinceLimit();
599 foreach ($limitCodes as $code) {
600 $limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
602 if (!empty($limitIds)) {
603 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
606 $whereClause = FALSE;
609 self
::populate(self
::$stateProvince, 'CRM_Core_DAO_StateProvince', TRUE, 'name', 'is_active', $whereClause);
611 // localise the province names if in an non-en_US locale
613 if ($tsLocale != '' and $tsLocale != 'en_US') {
614 $i18n = CRM_Core_I18n
::singleton();
615 $i18n->localizeArray(self
::$stateProvince, array(
616 'context' => 'province',
618 self
::$stateProvince = CRM_Utils_Array
::asort(self
::$stateProvince);
622 if (array_key_exists($id, self
::$stateProvince)) {
623 return self
::$stateProvince[$id];
630 return self
::$stateProvince;
634 * Get all the State/Province abbreviations from the database.
636 * Same as above, except gets the abbreviations instead of the names.
641 * @param int $id - Optional id to return
643 * @return array - array reference of all State/Province abbreviations.
645 public static function &stateProvinceAbbreviation($id = FALSE, $limit = TRUE) {
649 FROM civicrm_state_province
657 return CRM_Core_DAO
::singleValueQuery($query, $params);
660 if (!self
::$stateProvinceAbbreviation ||
!$id) {
662 $whereClause = FALSE;
665 $config = CRM_Core_Config
::singleton();
666 $countryIsoCodes = self
::countryIsoCode();
667 $limitCodes = $config->provinceLimit();
669 foreach ($limitCodes as $code) {
670 $tmpArray = array_keys($countryIsoCodes, $code);
672 if (!empty($tmpArray)) {
673 $limitIds[] = array_shift($tmpArray);
676 if (!empty($limitIds)) {
677 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
680 self
::populate(self
::$stateProvinceAbbreviation, 'CRM_Core_DAO_StateProvince', TRUE, 'abbreviation', 'is_active', $whereClause);
684 if (array_key_exists($id, self
::$stateProvinceAbbreviation)) {
685 return self
::$stateProvinceAbbreviation[$id];
692 return self
::$stateProvinceAbbreviation;
696 * Get all the countries from database.
698 * The static array country is returned, and if it's
699 * called the first time, the <b>Country DAO</b> is used
700 * to get all the countries.
702 * Note: any database errors will be trapped by the DAO.
707 * @param int $id - Optional id to return
709 * @return array - array reference of all countries.
712 public static function country($id = FALSE, $applyLimit = TRUE) {
713 if (($id && !CRM_Utils_Array
::value($id, self
::$country)) ||
!self
::$country ||
!$id) {
715 $config = CRM_Core_Config
::singleton();
716 $limitCodes = array();
719 // limit the country list to the countries specified in CIVICRM_COUNTRY_LIMIT
720 // (ensuring it's a subset of the legal values)
721 // K/P: We need to fix this, i dont think it works with new setting files
722 $limitCodes = $config->countryLimit();
723 if (!is_array($limitCodes)) {
725 $config->countryLimit
=> 1,
729 $limitCodes = array_intersect(self
::countryIsoCode(), $limitCodes);
732 if (count($limitCodes)) {
733 $whereClause = "iso_code IN ('" . implode("', '", $limitCodes) . "')";
739 self
::populate(self
::$country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active', $whereClause);
741 // if default country is set, percolate it to the top
742 if ($config->defaultContactCountry()) {
743 $countryIsoCodes = self
::countryIsoCode();
744 $defaultID = array_search($config->defaultContactCountry(), $countryIsoCodes);
745 if ($defaultID !== FALSE) {
746 $default[$defaultID] = CRM_Utils_Array
::value($defaultID, self
::$country);
747 self
::$country = $default + self
::$country;
751 // localise the country names if in an non-en_US locale
753 if ($tsLocale != '' and $tsLocale != 'en_US') {
754 $i18n = CRM_Core_I18n
::singleton();
755 $i18n->localizeArray(self
::$country, array(
756 'context' => 'country',
758 self
::$country = CRM_Utils_Array
::asort(self
::$country);
762 if (array_key_exists($id, self
::$country)) {
763 return self
::$country[$id];
766 return CRM_Core_DAO
::$_nullObject;
769 return self
::$country;
773 * Get all the country ISO Code abbreviations from the database.
775 * The static array countryIsoCode is returned, and if it's
776 * called the first time, the <b>Country DAO</b> is used
777 * to get all the countries' ISO codes.
779 * Note: any database errors will be trapped by the DAO.
784 * @return array - array reference of all country ISO codes.
787 public static function &countryIsoCode($id = FALSE) {
788 if (!self
::$countryIsoCode) {
789 self
::populate(self
::$countryIsoCode, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
792 if (array_key_exists($id, self
::$countryIsoCode)) {
793 return self
::$countryIsoCode[$id];
796 return CRM_Core_DAO
::$_nullObject;
799 return self
::$countryIsoCode;
803 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
805 * Get all groups from database
807 * The static array group is returned, and if it's
808 * called the first time, the <b>Group DAO</b> is used
809 * to get all the groups.
811 * Note: any database errors will be trapped by the DAO.
813 * @param string $groupType type of group(Access/Mailing)
814 * @param boolen $excludeHidden exclude hidden groups.
819 * @return array - array reference of all groups.
822 public static function &allGroup($groupType = NULL, $excludeHidden = TRUE) {
823 $condition = CRM_Contact_BAO_Group
::groupTypeCondition($groupType, $excludeHidden);
826 self
::$group = array();
829 $groupKey = $groupType ?
$groupType : 'null';
831 if (!isset(self
::$group[$groupKey])) {
832 self
::$group[$groupKey] = NULL;
833 self
::populate(self
::$group[$groupKey], 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition);
835 return self
::$group[$groupKey];
839 * Create or get groups iterator (iterates over nested groups in a
842 * The GroupNesting instance is returned; it's created if this is being
843 * called for the first time
849 * @return mixed - instance of CRM_Contact_BAO_GroupNesting
852 public static function &groupIterator($styledLabels = FALSE) {
853 if (!self
::$groupIterator) {
855 When used as an object, GroupNesting implements Iterator
856 and iterates nested groups in a logical manner for us
858 self
::$groupIterator = new CRM_Contact_BAO_GroupNesting($styledLabels);
860 return self
::$groupIterator;
864 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
866 * Get all permissioned groups from database
868 * The static array group is returned, and if it's
869 * called the first time, the <b>Group DAO</b> is used
870 * to get all the groups.
872 * Note: any database errors will be trapped by the DAO.
874 * @param string $groupType type of group(Access/Mailing)
875 * @param boolen $excludeHidden exclude hidden groups.
880 * @return array - array reference of all groups.
883 public static function group($groupType = NULL, $excludeHidden = TRUE) {
884 return CRM_Core_Permission
::group($groupType, $excludeHidden);
888 * Get all permissioned groups from database
890 * The static array group is returned, and if it's
891 * called the first time, the <b>Group DAO</b> is used
892 * to get all the groups.
894 * Note: any database errors will be trapped by the DAO.
899 * @return array - array reference of all groups.
902 public static function &staticGroup($onlyPublic = FALSE, $groupType = NULL, $excludeHidden = TRUE) {
903 if (!self
::$staticGroup) {
904 $condition = 'saved_search_id = 0 OR saved_search_id IS NULL';
906 $condition .= " AND visibility != 'User and User Admin Only'";
910 $condition .= ' AND ' . CRM_Contact_BAO_Group
::groupTypeCondition($groupType);
913 if ($excludeHidden) {
914 $condition .= ' AND is_hidden != 1 ';
917 self
::populate(self
::$staticGroup, 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition, 'title');
920 return self
::$staticGroup;
924 * Get all Relationship Types from database.
926 * The static array group is returned, and if it's
927 * called the first time, the <b>RelationshipType DAO</b> is used
928 * to get all the relationship types.
930 * Note: any database errors will be trapped by the DAO.
932 * @param string $valueColumnName db column name/label.
933 * @param boolean $reset reset relationship types if true
938 * @return array - array reference of all relationship types.
940 public static function &relationshipType($valueColumnName = 'label', $reset = FALSE) {
941 if (!CRM_Utils_Array
::value($valueColumnName, self
::$relationshipType) ||
$reset) {
942 self
::$relationshipType[$valueColumnName] = array();
944 //now we have name/label columns CRM-3336
945 $column_a_b = "{$valueColumnName}_a_b";
946 $column_b_a = "{$valueColumnName}_b_a";
948 $relationshipTypeDAO = new CRM_Contact_DAO_RelationshipType();
949 $relationshipTypeDAO->selectAdd();
950 $relationshipTypeDAO->selectAdd("id, {$column_a_b}, {$column_b_a}, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b");
951 $relationshipTypeDAO->is_active
= 1;
952 $relationshipTypeDAO->find();
953 while ($relationshipTypeDAO->fetch()) {
955 self
::$relationshipType[$valueColumnName][$relationshipTypeDAO->id
] = array(
956 $column_a_b => $relationshipTypeDAO->$column_a_b,
957 $column_b_a => $relationshipTypeDAO->$column_b_a,
958 'contact_type_a' => "$relationshipTypeDAO->contact_type_a",
959 'contact_type_b' => "$relationshipTypeDAO->contact_type_b",
960 'contact_sub_type_a' => "$relationshipTypeDAO->contact_sub_type_a",
961 'contact_sub_type_b' => "$relationshipTypeDAO->contact_sub_type_b",
966 return self
::$relationshipType[$valueColumnName];
970 * get all the ISO 4217 currency codes
972 * so far, we use this for validation only, so there's no point of putting this into the database
976 * @return array - array reference of all currency codes
979 public static function ¤cyCode() {
980 if (!self
::$currencyCode) {
981 self
::$currencyCode = array(
1251 return self
::$currencyCode;
1255 * Get all the County from database.
1257 * The static array county is returned, and if it's
1258 * called the first time, the <b>County DAO</b> is used
1259 * to get all the Counties.
1261 * Note: any database errors will be trapped by the DAO.
1266 * @param int $id - Optional id to return
1268 * @return array - array reference of all Counties
1271 public static function &county($id = FALSE) {
1272 if (!self
::$county) {
1274 $config = CRM_Core_Config
::singleton();
1275 // order by id so users who populate civicrm_county can have more control over sort by the order they load the counties
1276 self
::populate(self
::$county, 'CRM_Core_DAO_County', TRUE, 'name', NULL, NULL, 'id');
1279 if (array_key_exists($id, self
::$county)) {
1280 return self
::$county[$id];
1283 return CRM_Core_DAO
::$_nullObject;
1286 return self
::$county;
1290 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1291 * Get all active payment processors
1293 * The static array paymentProcessor is returned
1298 * @param boolean $all - get payment processors - default is to get only active ones.
1299 * @param boolean $test - get test payment processors
1301 * @return array - array of all payment processors
1304 public static function &paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
1305 $condition = "is_test = ";
1306 $condition .= ($test) ?
'1' : '0';
1308 if ($additionalCond) {
1309 $condition .= " AND ( $additionalCond ) ";
1312 // CRM-7178. Make sure we only include payment processors valid in ths
1314 $condition .= " AND domain_id = " . CRM_Core_Config
::domainID();
1316 $cacheKey = $condition . '_' . (int) $all;
1317 if (!isset(self
::$paymentProcessor[$cacheKey])) {
1318 self
::populate(self
::$paymentProcessor[$cacheKey], 'CRM_Financial_DAO_PaymentProcessor', $all, 'name', 'is_active', $condition, 'is_default desc, name');
1321 return self
::$paymentProcessor[$cacheKey];
1325 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1327 * The static array paymentProcessorType is returned
1332 * @param boolean $all - get payment processors - default is to get only active ones.
1334 * @return array - array of all payment processor types
1337 public static function &paymentProcessorType($all = FALSE, $id = NULL, $return = 'title') {
1338 $cacheKey = $id . '_' .$return;
1339 if (empty(self
::$paymentProcessorType[$cacheKey])) {
1340 self
::populate(self
::$paymentProcessorType[$cacheKey], 'CRM_Financial_DAO_PaymentProcessorType', $all, $return, 'is_active', NULL, "is_default, $return", 'id');
1342 if ($id && CRM_Utils_Array
::value($id, self
::$paymentProcessorType[$cacheKey])) {
1343 return self
::$paymentProcessorType[$cacheKey][$id];
1345 return self
::$paymentProcessorType[$cacheKey];
1349 * Get all the World Regions from Database
1353 * @return array - array reference of all World Regions
1356 public static function &worldRegion($id = FALSE) {
1357 if (!self
::$worldRegions) {
1358 self
::populate(self
::$worldRegions, 'CRM_Core_DAO_Worldregion', TRUE, 'name', NULL, NULL, 'id');
1362 if (array_key_exists($id, self
::$worldRegions)) {
1363 return self
::$worldRegions[$id];
1366 return CRM_Core_DAO
::$_nullObject;
1370 return self
::$worldRegions;
1374 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1376 * Get all Activity Statuses.
1378 * The static array activityStatus is returned
1383 * @return array - array reference of all activity statuses
1385 public static function &activityStatus($column = 'label') {
1386 if (NULL === self
::$activityStatus) {
1387 self
::$activityStatus = array();
1389 if (!array_key_exists($column, self
::$activityStatus)) {
1390 self
::$activityStatus[$column] = array();
1392 self
::$activityStatus[$column] = CRM_Core_OptionGroup
::values('activity_status', FALSE, FALSE, FALSE, NULL, $column);
1395 return self
::$activityStatus[$column];
1399 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1401 * Get all Visibility levels.
1403 * The static array visibility is returned
1408 * @return array - array reference of all Visibility levels.
1411 public static function &visibility($column = 'label') {
1412 if (!isset(self
::$visibility)) {
1413 self
::$visibility = array( );
1416 if (!isset(self
::$visibility[$column])) {
1417 self
::$visibility[$column] = CRM_Core_OptionGroup
::values('visibility', FALSE, FALSE, FALSE, NULL, $column);
1420 return self
::$visibility[$column];
1423 public static function &stateProvinceForCountry($countryID, $field = 'name') {
1424 static $_cache = NULL;
1426 $cacheKey = "{$countryID}_{$field}";
1431 if (!empty($_cache[$cacheKey])) {
1432 return $_cache[$cacheKey];
1436 SELECT civicrm_state_province.{$field} name, civicrm_state_province.id id
1437 FROM civicrm_state_province
1438 WHERE country_id = %1
1447 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1450 while ($dao->fetch()) {
1451 $result[$dao->id
] = $dao->name
;
1454 // localise the stateProvince names if in an non-en_US locale
1455 $config = CRM_Core_Config
::singleton();
1457 if ($tsLocale != '' and $tsLocale != 'en_US') {
1458 $i18n = CRM_Core_I18n
::singleton();
1459 $i18n->localizeArray($result, array(
1460 'context' => 'province',
1462 $result = CRM_Utils_Array
::asort($result);
1465 $_cache[$cacheKey] = $result;
1467 CRM_Utils_Hook
::buildStateProvinceForCountry($countryID, $result);
1472 public static function &countyForState($stateID) {
1473 if (is_array($stateID)) {
1474 $states = implode(", ", $stateID);
1476 SELECT civicrm_county.name name, civicrm_county.id id, civicrm_state_province.abbreviation abbreviation
1478 LEFT JOIN civicrm_state_province ON civicrm_county.state_province_id = civicrm_state_province.id
1479 WHERE civicrm_county.state_province_id in ( $states )
1480 ORDER BY civicrm_state_province.abbreviation, civicrm_county.name";
1482 $dao = CRM_Core_DAO
::executeQuery($query);
1485 while ($dao->fetch()) {
1486 $result[$dao->id
] = $dao->abbreviation
. ': ' . $dao->name
;
1491 static $_cache = NULL;
1493 $cacheKey = "{$stateID}_name";
1498 if (!empty($_cache[$cacheKey])) {
1499 return $_cache[$cacheKey];
1503 SELECT civicrm_county.name name, civicrm_county.id id
1505 WHERE state_province_id = %1
1514 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1517 while ($dao->fetch()) {
1518 $result[$dao->id
] = $dao->name
;
1526 * Given a state ID return the country ID, this allows
1527 * us to populate forms and values for downstream code
1529 * @param $stateID int
1531 * @return int the country id that the state belongs to
1535 static function countryIDForStateID($stateID) {
1536 if (empty($stateID)) {
1537 return CRM_Core_DAO
::$_nullObject;
1542 FROM civicrm_state_province
1545 $params = array(1 => array($stateID, 'Integer'));
1547 return CRM_Core_DAO
::singleValueQuery($query, $params);
1551 * Get all types of Greetings.
1553 * The static array of greeting is returned
1558 * @param $filter - get All Email Greetings - default is to get only active ones.
1560 * @return array - array reference of all greetings.
1563 public static function greeting($filter, $columnName = 'label') {
1564 $index = $filter['greeting_type'] . '_' . $columnName;
1566 // also add contactType to the array
1567 $contactType = CRM_Utils_Array
::value('contact_type', $filter);
1569 $index .= '_' . $contactType;
1572 if (NULL === self
::$greeting) {
1573 self
::$greeting = array();
1576 if (!CRM_Utils_Array
::value($index, self
::$greeting)) {
1577 $filterCondition = NULL;
1579 $filterVal = 'v.filter =';
1580 switch ($contactType) {
1589 case 'Organization':
1593 $filterCondition .= "AND (v.filter = 0 OR {$filterVal}) ";
1596 self
::$greeting[$index] = CRM_Core_OptionGroup
::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName);
1599 return self
::$greeting[$index];
1603 * Construct array of default greeting values for contact type
1608 * @return array - array reference of default greetings.
1611 public static function &greetingDefaults() {
1612 if (!self
::$greetingDefaults) {
1613 $defaultGreetings = array();
1614 $contactTypes = self
::get('CRM_Contact_DAO_Contact', 'contact_type', array('keyColumn' => 'id', 'labelColumn' => 'name'));
1616 foreach ($contactTypes as $filter => $contactType) {
1617 $filterCondition = " AND (v.filter = 0 OR v.filter = $filter) AND v.is_default = 1 ";
1619 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
1620 $tokenVal = CRM_Core_OptionGroup
::values($greeting, NULL, NULL, NULL, $filterCondition, 'label');
1621 $defaultGreetings[$contactType][$greeting] = $tokenVal;
1625 self
::$greetingDefaults = $defaultGreetings;
1628 return self
::$greetingDefaults;
1632 * Get all extensions
1634 * The static array extensions
1636 * FIXME: This is called by civix but not by any core code. We
1637 * should provide an API call which civix can use instead.
1642 * @return array - array($fullyQualifiedName => $label) list of extensions
1644 public static function &getExtensions() {
1645 if (!self
::$extensions) {
1646 self
::$extensions = array();
1648 SELECT full_name, label
1649 FROM civicrm_extension
1652 $dao = CRM_Core_DAO
::executeQuery($sql);
1653 while ($dao->fetch()) {
1654 self
::$extensions[$dao->full_name
] = $dao->label
;
1658 return self
::$extensions;
1662 * Get all options values
1664 * The static array option values is returned
1669 * @param boolean $optionGroupName - get All Option Group values- default is to get only active ones.
1671 * @return array - array reference of all Option Group Name
1674 public static function accountOptionValues($optionGroupName, $id = null, $condition = null) {
1675 $cacheKey = $optionGroupName . '_' . $condition;
1676 if (empty(self
::$accountOptionValues[$cacheKey])) {
1677 self
::$accountOptionValues[$cacheKey] = CRM_Core_OptionGroup
::values($optionGroupName, false, false, false, $condition);
1680 return CRM_Utils_Array
::value($id, self
::$accountOptionValues[$cacheKey]);
1683 return self
::$accountOptionValues[$cacheKey];
1687 * Fetch the list of active extensions of type 'module'
1689 * @param $fresh bool whether to forcibly reload extensions list from canonical store
1693 * @return array - array(array('prefix' => $, 'file' => $))
1695 public static function getModuleExtensions($fresh = FALSE) {
1696 return CRM_Extension_System
::singleton()->getMapper()->getActiveModuleFiles($fresh);