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)) {
497 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
499 * Get all Activty types.
501 * The static array activityType is returned
503 * @param boolean $all - get All Activity types - default is to get only active ones.
508 * @return array - array reference of all activity types.
510 public static function &activityType() {
511 $args = func_get_args();
512 $all = CRM_Utils_Array
::value(0, $args, TRUE);
513 $includeCaseActivities = CRM_Utils_Array
::value(1, $args, FALSE);
514 $reset = CRM_Utils_Array
::value(2, $args, FALSE);
515 $returnColumn = CRM_Utils_Array
::value(3, $args, 'label');
516 $includeCampaignActivities = CRM_Utils_Array
::value(4, $args, FALSE);
517 $onlyComponentActivities = CRM_Utils_Array
::value(5, $args, FALSE);
518 $index = (int) $all . '_' . $returnColumn . '_' . (int) $includeCaseActivities;
519 $index .= '_' . (int) $includeCampaignActivities;
520 $index .= '_' . (int) $onlyComponentActivities;
522 if (NULL === self
::$activityType) {
523 self
::$activityType = array();
526 if (!isset(self
::$activityType[$index]) ||
$reset) {
529 $condition = 'AND filter = 0';
531 $componentClause = " v.component_id IS NULL";
532 if ($onlyComponentActivities) {
533 $componentClause = " v.component_id IS NOT NULL";
536 $componentIds = array();
537 $compInfo = CRM_Core_Component
::getEnabledComponents();
539 // build filter for listing activity types only if their
540 // respective components are enabled
541 foreach ($compInfo as $compName => $compObj) {
542 if ($compName == 'CiviCase') {
543 if ($includeCaseActivities) {
544 $componentIds[] = $compObj->componentID
;
547 elseif ($compName == 'CiviCampaign') {
548 if ($includeCampaignActivities) {
549 $componentIds[] = $compObj->componentID
;
553 $componentIds[] = $compObj->componentID
;
557 if (count($componentIds)) {
558 $componentIds = implode(',', $componentIds);
559 $componentClause = " ($componentClause OR v.component_id IN ($componentIds))";
560 if ($onlyComponentActivities) {
561 $componentClause = " ( v.component_id IN ($componentIds ) )";
564 $condition = $condition . ' AND ' . $componentClause;
566 self
::$activityType[$index] = CRM_Core_OptionGroup
::values('activity_type', FALSE, FALSE, FALSE, $condition, $returnColumn);
568 return self
::$activityType[$index];
572 * Get all the State/Province from database.
574 * The static array stateProvince is returned, and if it's
575 * called the first time, the <b>State Province DAO</b> is used
576 * to get all the States.
578 * Note: any database errors will be trapped by the DAO.
583 * @param int $id - Optional id to return
585 * @return array - array reference of all State/Provinces.
588 public static function &stateProvince($id = FALSE, $limit = TRUE) {
589 if (($id && !CRM_Utils_Array
::value($id, self
::$stateProvince)) ||
!self
::$stateProvince ||
!$id) {
590 $whereClause = FALSE;
591 $config = CRM_Core_Config
::singleton();
593 $countryIsoCodes = self
::countryIsoCode();
594 $limitCodes = $config->provinceLimit();
596 foreach ($limitCodes as $code) {
597 $limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
599 if (!empty($limitIds)) {
600 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
603 $whereClause = FALSE;
606 self
::populate(self
::$stateProvince, 'CRM_Core_DAO_StateProvince', TRUE, 'name', 'is_active', $whereClause);
608 // localise the province names if in an non-en_US locale
610 if ($tsLocale != '' and $tsLocale != 'en_US') {
611 $i18n = CRM_Core_I18n
::singleton();
612 $i18n->localizeArray(self
::$stateProvince, array(
613 'context' => 'province',
615 self
::$stateProvince = CRM_Utils_Array
::asort(self
::$stateProvince);
619 if (array_key_exists($id, self
::$stateProvince)) {
620 return self
::$stateProvince[$id];
627 return self
::$stateProvince;
631 * Get all the State/Province abbreviations from the database.
633 * Same as above, except gets the abbreviations instead of the names.
638 * @param int $id - Optional id to return
640 * @return array - array reference of all State/Province abbreviations.
642 public static function &stateProvinceAbbreviation($id = FALSE, $limit = TRUE) {
646 FROM civicrm_state_province
654 return CRM_Core_DAO
::singleValueQuery($query, $params);
657 if (!self
::$stateProvinceAbbreviation ||
!$id) {
659 $whereClause = FALSE;
662 $config = CRM_Core_Config
::singleton();
663 $countryIsoCodes = self
::countryIsoCode();
664 $limitCodes = $config->provinceLimit();
666 foreach ($limitCodes as $code) {
667 $tmpArray = array_keys($countryIsoCodes, $code);
669 if (!empty($tmpArray)) {
670 $limitIds[] = array_shift($tmpArray);
673 if (!empty($limitIds)) {
674 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
677 self
::populate(self
::$stateProvinceAbbreviation, 'CRM_Core_DAO_StateProvince', TRUE, 'abbreviation', 'is_active', $whereClause);
681 if (array_key_exists($id, self
::$stateProvinceAbbreviation)) {
682 return self
::$stateProvinceAbbreviation[$id];
689 return self
::$stateProvinceAbbreviation;
693 * Get all the countries from database.
695 * The static array country is returned, and if it's
696 * called the first time, the <b>Country DAO</b> is used
697 * to get all the countries.
699 * Note: any database errors will be trapped by the DAO.
704 * @param int $id - Optional id to return
706 * @return array - array reference of all countries.
709 public static function country($id = FALSE, $applyLimit = TRUE) {
710 if (($id && !CRM_Utils_Array
::value($id, self
::$country)) ||
!self
::$country ||
!$id) {
712 $config = CRM_Core_Config
::singleton();
713 $limitCodes = array();
716 // limit the country list to the countries specified in CIVICRM_COUNTRY_LIMIT
717 // (ensuring it's a subset of the legal values)
718 // K/P: We need to fix this, i dont think it works with new setting files
719 $limitCodes = $config->countryLimit();
720 if (!is_array($limitCodes)) {
722 $config->countryLimit
=> 1,
726 $limitCodes = array_intersect(self
::countryIsoCode(), $limitCodes);
729 if (count($limitCodes)) {
730 $whereClause = "iso_code IN ('" . implode("', '", $limitCodes) . "')";
736 self
::populate(self
::$country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active', $whereClause);
738 // if default country is set, percolate it to the top
739 if ($config->defaultContactCountry()) {
740 $countryIsoCodes = self
::countryIsoCode();
741 $defaultID = array_search($config->defaultContactCountry(), $countryIsoCodes);
742 if ($defaultID !== FALSE) {
743 $default[$defaultID] = CRM_Utils_Array
::value($defaultID, self
::$country);
744 self
::$country = $default + self
::$country;
748 // localise the country names if in an non-en_US locale
750 if ($tsLocale != '' and $tsLocale != 'en_US') {
751 $i18n = CRM_Core_I18n
::singleton();
752 $i18n->localizeArray(self
::$country, array(
753 'context' => 'country',
755 self
::$country = CRM_Utils_Array
::asort(self
::$country);
759 if (array_key_exists($id, self
::$country)) {
760 return self
::$country[$id];
763 return CRM_Core_DAO
::$_nullObject;
766 return self
::$country;
770 * Get all the country ISO Code abbreviations from the database.
772 * The static array countryIsoCode is returned, and if it's
773 * called the first time, the <b>Country DAO</b> is used
774 * to get all the countries' ISO codes.
776 * Note: any database errors will be trapped by the DAO.
781 * @return array - array reference of all country ISO codes.
784 public static function &countryIsoCode($id = FALSE) {
785 if (!self
::$countryIsoCode) {
786 self
::populate(self
::$countryIsoCode, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
789 if (array_key_exists($id, self
::$countryIsoCode)) {
790 return self
::$countryIsoCode[$id];
793 return CRM_Core_DAO
::$_nullObject;
796 return self
::$countryIsoCode;
800 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
802 * Get all groups from database
804 * The static array group is returned, and if it's
805 * called the first time, the <b>Group DAO</b> is used
806 * to get all the groups.
808 * Note: any database errors will be trapped by the DAO.
810 * @param string $groupType type of group(Access/Mailing)
811 * @param boolen $excludeHidden exclude hidden groups.
816 * @return array - array reference of all groups.
819 public static function &allGroup($groupType = NULL, $excludeHidden = TRUE) {
820 $condition = CRM_Contact_BAO_Group
::groupTypeCondition($groupType, $excludeHidden);
823 self
::$group = array();
826 $groupKey = $groupType ?
$groupType : 'null';
828 if (!isset(self
::$group[$groupKey])) {
829 self
::$group[$groupKey] = NULL;
830 self
::populate(self
::$group[$groupKey], 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition);
832 return self
::$group[$groupKey];
836 * Create or get groups iterator (iterates over nested groups in a
839 * The GroupNesting instance is returned; it's created if this is being
840 * called for the first time
846 * @return mixed - instance of CRM_Contact_BAO_GroupNesting
849 public static function &groupIterator($styledLabels = FALSE) {
850 if (!self
::$groupIterator) {
852 When used as an object, GroupNesting implements Iterator
853 and iterates nested groups in a logical manner for us
855 self
::$groupIterator = new CRM_Contact_BAO_GroupNesting($styledLabels);
857 return self
::$groupIterator;
861 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
863 * Get all permissioned groups from database
865 * The static array group is returned, and if it's
866 * called the first time, the <b>Group DAO</b> is used
867 * to get all the groups.
869 * Note: any database errors will be trapped by the DAO.
871 * @param string $groupType type of group(Access/Mailing)
872 * @param boolen $excludeHidden exclude hidden groups.
877 * @return array - array reference of all groups.
880 public static function group($groupType = NULL, $excludeHidden = TRUE) {
881 return CRM_Core_Permission
::group($groupType, $excludeHidden);
885 * Get all permissioned groups from database
887 * The static array group is returned, and if it's
888 * called the first time, the <b>Group DAO</b> is used
889 * to get all the groups.
891 * Note: any database errors will be trapped by the DAO.
896 * @return array - array reference of all groups.
899 public static function &staticGroup($onlyPublic = FALSE, $groupType = NULL, $excludeHidden = TRUE) {
900 if (!self
::$staticGroup) {
901 $condition = 'saved_search_id = 0 OR saved_search_id IS NULL';
903 $condition .= " AND visibility != 'User and User Admin Only'";
907 $condition .= ' AND ' . CRM_Contact_BAO_Group
::groupTypeCondition($groupType);
910 if ($excludeHidden) {
911 $condition .= ' AND is_hidden != 1 ';
914 self
::populate(self
::$staticGroup, 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition, 'title');
917 return self
::$staticGroup;
921 * Get all Relationship Types from database.
923 * The static array group is returned, and if it's
924 * called the first time, the <b>RelationshipType DAO</b> is used
925 * to get all the relationship types.
927 * Note: any database errors will be trapped by the DAO.
929 * @param string $valueColumnName db column name/label.
930 * @param boolean $reset reset relationship types if true
935 * @return array - array reference of all relationship types.
937 public static function &relationshipType($valueColumnName = 'label', $reset = FALSE) {
938 if (!CRM_Utils_Array
::value($valueColumnName, self
::$relationshipType) ||
$reset) {
939 self
::$relationshipType[$valueColumnName] = array();
941 //now we have name/label columns CRM-3336
942 $column_a_b = "{$valueColumnName}_a_b";
943 $column_b_a = "{$valueColumnName}_b_a";
945 $relationshipTypeDAO = new CRM_Contact_DAO_RelationshipType();
946 $relationshipTypeDAO->selectAdd();
947 $relationshipTypeDAO->selectAdd("id, {$column_a_b}, {$column_b_a}, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b");
948 $relationshipTypeDAO->is_active
= 1;
949 $relationshipTypeDAO->find();
950 while ($relationshipTypeDAO->fetch()) {
952 self
::$relationshipType[$valueColumnName][$relationshipTypeDAO->id
] = array(
953 $column_a_b => $relationshipTypeDAO->$column_a_b,
954 $column_b_a => $relationshipTypeDAO->$column_b_a,
955 'contact_type_a' => "$relationshipTypeDAO->contact_type_a",
956 'contact_type_b' => "$relationshipTypeDAO->contact_type_b",
957 'contact_sub_type_a' => "$relationshipTypeDAO->contact_sub_type_a",
958 'contact_sub_type_b' => "$relationshipTypeDAO->contact_sub_type_b",
963 return self
::$relationshipType[$valueColumnName];
967 * get all the ISO 4217 currency codes
969 * so far, we use this for validation only, so there's no point of putting this into the database
973 * @return array - array reference of all currency codes
976 public static function ¤cyCode() {
977 if (!self
::$currencyCode) {
978 self
::$currencyCode = array(
1248 return self
::$currencyCode;
1252 * Get all the County from database.
1254 * The static array county is returned, and if it's
1255 * called the first time, the <b>County DAO</b> is used
1256 * to get all the Counties.
1258 * Note: any database errors will be trapped by the DAO.
1263 * @param int $id - Optional id to return
1265 * @return array - array reference of all Counties
1268 public static function &county($id = FALSE) {
1269 if (!self
::$county) {
1271 $config = CRM_Core_Config
::singleton();
1272 // order by id so users who populate civicrm_county can have more control over sort by the order they load the counties
1273 self
::populate(self
::$county, 'CRM_Core_DAO_County', TRUE, 'name', NULL, NULL, 'id');
1276 if (array_key_exists($id, self
::$county)) {
1277 return self
::$county[$id];
1280 return CRM_Core_DAO
::$_nullObject;
1283 return self
::$county;
1287 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1288 * Get all active payment processors
1290 * The static array paymentProcessor is returned
1295 * @param boolean $all - get payment processors - default is to get only active ones.
1296 * @param boolean $test - get test payment processors
1298 * @return array - array of all payment processors
1301 public static function &paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
1302 $condition = "is_test = ";
1303 $condition .= ($test) ?
'1' : '0';
1305 if ($additionalCond) {
1306 $condition .= " AND ( $additionalCond ) ";
1309 // CRM-7178. Make sure we only include payment processors valid in ths
1311 $condition .= " AND domain_id = " . CRM_Core_Config
::domainID();
1313 $cacheKey = $condition . '_' . (int) $all;
1314 if (!isset(self
::$paymentProcessor[$cacheKey])) {
1315 self
::populate(self
::$paymentProcessor[$cacheKey], 'CRM_Financial_DAO_PaymentProcessor', $all, 'name', 'is_active', $condition, 'is_default desc, name');
1318 return self
::$paymentProcessor[$cacheKey];
1322 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1324 * The static array paymentProcessorType is returned
1329 * @param boolean $all - get payment processors - default is to get only active ones.
1331 * @return array - array of all payment processor types
1334 public static function &paymentProcessorType($all = FALSE, $id = NULL, $return = 'title') {
1335 $cacheKey = $id . '_' .$return;
1336 if (empty(self
::$paymentProcessorType[$cacheKey])) {
1337 self
::populate(self
::$paymentProcessorType[$cacheKey], 'CRM_Financial_DAO_PaymentProcessorType', $all, $return, 'is_active', NULL, "is_default, $return", 'id');
1339 if ($id && CRM_Utils_Array
::value($id, self
::$paymentProcessorType[$cacheKey])) {
1340 return self
::$paymentProcessorType[$cacheKey][$id];
1342 return self
::$paymentProcessorType[$cacheKey];
1346 * Get all the World Regions from Database
1350 * @return array - array reference of all World Regions
1353 public static function &worldRegion($id = FALSE) {
1354 if (!self
::$worldRegions) {
1355 self
::populate(self
::$worldRegions, 'CRM_Core_DAO_Worldregion', TRUE, 'name', NULL, NULL, 'id');
1359 if (array_key_exists($id, self
::$worldRegions)) {
1360 return self
::$worldRegions[$id];
1363 return CRM_Core_DAO
::$_nullObject;
1367 return self
::$worldRegions;
1371 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1373 * Get all Activity Statuses.
1375 * The static array activityStatus is returned
1380 * @return array - array reference of all activity statuses
1382 public static function &activityStatus($column = 'label') {
1383 if (NULL === self
::$activityStatus) {
1384 self
::$activityStatus = array();
1386 if (!array_key_exists($column, self
::$activityStatus)) {
1387 self
::$activityStatus[$column] = array();
1389 self
::$activityStatus[$column] = CRM_Core_OptionGroup
::values('activity_status', FALSE, FALSE, FALSE, NULL, $column);
1392 return self
::$activityStatus[$column];
1396 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1398 * Get all Visibility levels.
1400 * The static array visibility is returned
1405 * @return array - array reference of all Visibility levels.
1408 public static function &visibility($column = 'label') {
1409 if (!isset(self
::$visibility)) {
1410 self
::$visibility = array( );
1413 if (!isset(self
::$visibility[$column])) {
1414 self
::$visibility[$column] = CRM_Core_OptionGroup
::values('visibility', FALSE, FALSE, FALSE, NULL, $column);
1417 return self
::$visibility[$column];
1420 public static function &stateProvinceForCountry($countryID, $field = 'name') {
1421 static $_cache = NULL;
1423 $cacheKey = "{$countryID}_{$field}";
1428 if (!empty($_cache[$cacheKey])) {
1429 return $_cache[$cacheKey];
1433 SELECT civicrm_state_province.{$field} name, civicrm_state_province.id id
1434 FROM civicrm_state_province
1435 WHERE country_id = %1
1444 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1447 while ($dao->fetch()) {
1448 $result[$dao->id
] = $dao->name
;
1451 // localise the stateProvince names if in an non-en_US locale
1452 $config = CRM_Core_Config
::singleton();
1454 if ($tsLocale != '' and $tsLocale != 'en_US') {
1455 $i18n = CRM_Core_I18n
::singleton();
1456 $i18n->localizeArray($result, array(
1457 'context' => 'province',
1459 $result = CRM_Utils_Array
::asort($result);
1462 $_cache[$cacheKey] = $result;
1464 CRM_Utils_Hook
::buildStateProvinceForCountry($countryID, $result);
1469 public static function &countyForState($stateID) {
1470 if (is_array($stateID)) {
1471 $states = implode(", ", $stateID);
1473 SELECT civicrm_county.name name, civicrm_county.id id, civicrm_state_province.abbreviation abbreviation
1475 LEFT JOIN civicrm_state_province ON civicrm_county.state_province_id = civicrm_state_province.id
1476 WHERE civicrm_county.state_province_id in ( $states )
1477 ORDER BY civicrm_state_province.abbreviation, civicrm_county.name";
1479 $dao = CRM_Core_DAO
::executeQuery($query);
1482 while ($dao->fetch()) {
1483 $result[$dao->id
] = $dao->abbreviation
. ': ' . $dao->name
;
1488 static $_cache = NULL;
1490 $cacheKey = "{$stateID}_name";
1495 if (!empty($_cache[$cacheKey])) {
1496 return $_cache[$cacheKey];
1500 SELECT civicrm_county.name name, civicrm_county.id id
1502 WHERE state_province_id = %1
1511 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1514 while ($dao->fetch()) {
1515 $result[$dao->id
] = $dao->name
;
1523 * Given a state ID return the country ID, this allows
1524 * us to populate forms and values for downstream code
1526 * @param $stateID int
1528 * @return int the country id that the state belongs to
1532 static function countryIDForStateID($stateID) {
1533 if (empty($stateID)) {
1534 return CRM_Core_DAO
::$_nullObject;
1539 FROM civicrm_state_province
1542 $params = array(1 => array($stateID, 'Integer'));
1544 return CRM_Core_DAO
::singleValueQuery($query, $params);
1548 * Get all types of Greetings.
1550 * The static array of greeting is returned
1555 * @param $filter - get All Email Greetings - default is to get only active ones.
1557 * @return array - array reference of all greetings.
1560 public static function greeting($filter, $columnName = 'label') {
1561 $index = $filter['greeting_type'] . '_' . $columnName;
1563 // also add contactType to the array
1564 $contactType = CRM_Utils_Array
::value('contact_type', $filter);
1566 $index .= '_' . $contactType;
1569 if (NULL === self
::$greeting) {
1570 self
::$greeting = array();
1573 if (!CRM_Utils_Array
::value($index, self
::$greeting)) {
1574 $filterCondition = NULL;
1576 $filterVal = 'v.filter =';
1577 switch ($contactType) {
1586 case 'Organization':
1590 $filterCondition .= "AND (v.filter = 0 OR {$filterVal}) ";
1593 self
::$greeting[$index] = CRM_Core_OptionGroup
::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName);
1596 return self
::$greeting[$index];
1600 * Construct array of default greeting values for contact type
1605 * @return array - array reference of default greetings.
1608 public static function &greetingDefaults() {
1609 if (!self
::$greetingDefaults) {
1610 $defaultGreetings = array();
1611 $contactTypes = self
::get('CRM_Contact_DAO_Contact', 'contact_type', array('keyColumn' => 'id', 'labelColumn' => 'name'));
1613 foreach ($contactTypes as $filter => $contactType) {
1614 $filterCondition = " AND (v.filter = 0 OR v.filter = $filter) AND v.is_default = 1 ";
1616 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
1617 $tokenVal = CRM_Core_OptionGroup
::values($greeting, NULL, NULL, NULL, $filterCondition, 'label');
1618 $defaultGreetings[$contactType][$greeting] = $tokenVal;
1622 self
::$greetingDefaults = $defaultGreetings;
1625 return self
::$greetingDefaults;
1629 * Get all extensions
1631 * The static array extensions
1633 * FIXME: This is called by civix but not by any core code. We
1634 * should provide an API call which civix can use instead.
1639 * @return array - array($fullyQualifiedName => $label) list of extensions
1641 public static function &getExtensions() {
1642 if (!self
::$extensions) {
1643 self
::$extensions = array();
1645 SELECT full_name, label
1646 FROM civicrm_extension
1649 $dao = CRM_Core_DAO
::executeQuery($sql);
1650 while ($dao->fetch()) {
1651 self
::$extensions[$dao->full_name
] = $dao->label
;
1655 return self
::$extensions;
1659 * Get all options values
1661 * The static array option values is returned
1666 * @param boolean $optionGroupName - get All Option Group values- default is to get only active ones.
1668 * @return array - array reference of all Option Group Name
1671 public static function accountOptionValues($optionGroupName, $id = null, $condition = null) {
1672 $cacheKey = $optionGroupName . '_' . $condition;
1673 if (empty(self
::$accountOptionValues[$cacheKey])) {
1674 self
::$accountOptionValues[$cacheKey] = CRM_Core_OptionGroup
::values($optionGroupName, false, false, false, $condition);
1677 return CRM_Utils_Array
::value($id, self
::$accountOptionValues[$cacheKey]);
1680 return self
::$accountOptionValues[$cacheKey];
1684 * Fetch the list of active extensions of type 'module'
1686 * @param $fresh bool whether to forcibly reload extensions list from canonical store
1690 * @return array - array(array('prefix' => $, 'file' => $))
1692 public static function getModuleExtensions($fresh = FALSE) {
1693 return CRM_Extension_System
::singleton()->getMapper()->getActiveModuleFiles($fresh);