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) {
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 return $flip ?
array_flip($output) : $output;
243 // Core field: load schema
245 $fields = $dao->fields();
246 $fieldKeys = $dao->fieldKeys();
247 $fieldKey = $fieldKeys[$fieldName];
249 if (empty($fields[$fieldKey])) {
252 $fieldSpec = $fields[$fieldKey];
254 // If the field is an enum, explode the enum definition and return the array.
255 if (isset($fieldSpec['enumValues'])) {
256 // use of a space after the comma is inconsistent in xml
257 $enumStr = str_replace(', ', ',', $fieldSpec['enumValues']);
258 $output = explode(',', $enumStr);
259 return $flip ?
array_flip($output) : $output;
262 elseif (!empty($fieldSpec['pseudoconstant'])) {
263 $pseudoconstant = $fieldSpec['pseudoconstant'];
264 // Merge params with defaults
268 'condition' => CRM_Utils_Array
::value('condition', $pseudoconstant),
269 'keyColumn' => CRM_Utils_Array
::value('keyColumn', $pseudoconstant),
270 'labelColumn' => CRM_Utils_Array
::value('labelColumn', $pseudoconstant),
271 'onlyActive' => TRUE,
275 // Fetch option group from option_value table
276 if(!empty($pseudoconstant['optionGroupName'])) {
277 // Call our generic fn for retrieving from the option_value table
278 return CRM_Core_OptionGroup
::values(
279 $pseudoconstant['optionGroupName'],
283 $params['condition'] ?
' AND ' . implode(' AND ', (array) $params['condition']) : NULL,
284 $params['labelColumn'] ?
$params['labelColumn'] : 'label',
285 $params['onlyActive'],
287 $params['keyColumn'] ?
$params['keyColumn'] : 'value'
291 // Fetch options from other tables
292 if (!empty($pseudoconstant['table'])) {
293 // Normalize params so the serialized cache string will be consistent.
294 CRM_Utils_Array
::remove($params, 'flip', 'fresh');
296 $cacheKey = $daoName . $fieldName . serialize($params);
298 // Retrieve cached options
299 if (isset(self
::$cache[$cacheKey]) && empty($params['fresh'])) {
300 $output = self
::$cache[$cacheKey];
303 $daoName = CRM_Core_DAO_AllCoreTables
::getClassForTable($pseudoconstant['table']);
304 if (!class_exists($daoName)) {
307 // Get list of fields for the option table
309 $availableFields = array_keys($dao->fieldKeys());
310 if (in_array('is_active', $availableFields)) {
311 $wheres[] = 'is_active = 1';
315 $select = "SELECT %1 AS id, %2 AS label";
318 $order = "ORDER BY %2";
319 // Condition param can be passed as an sql clause string or an array of clauses
320 if (!empty($params['condition'])) {
321 $wheres[] = implode(' AND ', (array) $params['condition']);
323 // onlyActive param will automatically filter on common flags
324 if (!empty($params['onlyActive'])) {
325 foreach (array('is_active' => 1, 'is_deleted' => 0, 'is_test' => 0) as $flag => $val) {
326 if (in_array($flag, $availableFields)) {
327 $wheres[] = "$flag = $val";
331 // Filter domain specific options
332 if (in_array('domain_id', $availableFields)) {
333 $wheres[] = 'domain_id = ' . CRM_Core_Config
::domainID();
335 $queryParams = array(
336 1 => array($params['keyColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
337 2 => array($params['labelColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
338 3 => array($pseudoconstant['table'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
340 // Add orderColumn param
341 if (!empty($params['orderColumn'])) {
342 $queryParams[4] = array($params['orderColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
);
343 $order = "ORDER BY %4";
345 // Support no sorting if $params[orderColumn] is FALSE
346 elseif (isset($params['orderColumn']) && $params['orderColumn'] === FALSE) {
349 // Default to 'weight' if that column exists
350 elseif (in_array('weight', $availableFields)) {
351 $order = "ORDER BY weight";
355 $query = "$select $from";
357 $query .= " WHERE " . implode($wheres, ' AND ');
359 $query .= ' ' . $order;
360 $dao = CRM_Core_DAO
::executeQuery($query, $queryParams);
361 while ($dao->fetch()) {
362 $output[$dao->id
] = $dao->label
;
365 if (!empty($params['localize'])) {
366 $i18n = CRM_Core_I18n
::singleton();
367 $i18n->localizeArray($output);
368 // Maintain sort by label
369 if ($order == "ORDER BY %2") {
370 CRM_Utils_Array
::asort($output);
373 self
::$cache[$cacheKey] = $output;
375 return $flip ?
array_flip($output) : $output;
378 // If we're still here, it's an error. Return FALSE.
383 * Fetch the label (or other value) for a field given its key
385 * @param String $daoName
386 * @param String $fieldName
387 * @param String|Int $key
388 * @param Array $params will be passed into self::get
392 static function getValue($daoName, $fieldName, $key, $params = array()) {
393 $values = self
::get($daoName, $fieldName, $params);
394 return CRM_Utils_Array
::value($key, $values);
398 * Fetch the key for a field option given its label/name
400 * @param String $daoName
401 * @param String $fieldName
402 * @param String|Int $value
403 * @param Array $params will be passed into self::get
407 static function getKey($daoName, $fieldName, $value, $params = array()) {
408 $values = self
::get($daoName, $fieldName, $params);
409 return CRM_Utils_Array
::key($value, $values);
413 * DEPRECATED generic populate method
414 * All pseudoconstant functions that use this method are also deprecated.
416 * The static array $var is populated from the db
417 * using the <b>$name DAO</b>.
419 * Note: any database errors will be trapped by the DAO.
421 * @param array $var the associative array we will fill
422 * @param string $name the name of the DAO
423 * @param boolean $all get all objects. default is to get only active ones.
424 * @param string $retrieve the field that we are interested in (normally name, differs in some objects)
425 * @param string $filter the field that we want to filter the result set with
426 * @param string $condition the condition that gets passed to the final query as the WHERE clause
432 public static function populate(
437 $filter = 'is_active',
443 $cacheKey = "CRM_PC_{$name}_{$all}_{$key}_{$retrieve}_{$filter}_{$condition}_{$orderby}";
444 $cache = CRM_Utils_Cache
::singleton();
445 $var = $cache->get($cacheKey);
446 if ($var && empty($force)) {
450 $object = new $name ( );
452 $object->selectAdd();
453 $object->selectAdd("$key, $retrieve");
455 $object->whereAdd($condition);
459 $object->orderBy($retrieve);
462 $object->orderBy($orderby);
466 $object->$filter = 1;
471 while ($object->fetch()) {
472 $var[$object->$key] = $object->$retrieve;
475 $cache->set($cacheKey, $var);
479 * Flush given pseudoconstant so it can be reread from db
480 * nex time it's requested.
485 * @param boolean $name pseudoconstant to be flushed
488 public static function flush($name = 'cache') {
489 if (property_exists(self
, $name)) {
495 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
497 * Get all Activty types.
499 * The static array activityType is returned
501 * @param boolean $all - get All Activity types - default is to get only active ones.
506 * @return array - array reference of all activity types.
508 public static function &activityType() {
509 $args = func_get_args();
510 $all = CRM_Utils_Array
::value(0, $args, TRUE);
511 $includeCaseActivities = CRM_Utils_Array
::value(1, $args, FALSE);
512 $reset = CRM_Utils_Array
::value(2, $args, FALSE);
513 $returnColumn = CRM_Utils_Array
::value(3, $args, 'label');
514 $includeCampaignActivities = CRM_Utils_Array
::value(4, $args, FALSE);
515 $onlyComponentActivities = CRM_Utils_Array
::value(5, $args, FALSE);
516 $index = (int) $all . '_' . $returnColumn . '_' . (int) $includeCaseActivities;
517 $index .= '_' . (int) $includeCampaignActivities;
518 $index .= '_' . (int) $onlyComponentActivities;
520 if (NULL === self
::$activityType) {
521 self
::$activityType = array();
524 if (!isset(self
::$activityType[$index]) ||
$reset) {
527 $condition = 'AND filter = 0';
529 $componentClause = " v.component_id IS NULL";
530 if ($onlyComponentActivities) {
531 $componentClause = " v.component_id IS NOT NULL";
534 $componentIds = array();
535 $compInfo = CRM_Core_Component
::getEnabledComponents();
537 // build filter for listing activity types only if their
538 // respective components are enabled
539 foreach ($compInfo as $compName => $compObj) {
540 if ($compName == 'CiviCase') {
541 if ($includeCaseActivities) {
542 $componentIds[] = $compObj->componentID
;
545 elseif ($compName == 'CiviCampaign') {
546 if ($includeCampaignActivities) {
547 $componentIds[] = $compObj->componentID
;
551 $componentIds[] = $compObj->componentID
;
555 if (count($componentIds)) {
556 $componentIds = implode(',', $componentIds);
557 $componentClause = " ($componentClause OR v.component_id IN ($componentIds))";
558 if ($onlyComponentActivities) {
559 $componentClause = " ( v.component_id IN ($componentIds ) )";
562 $condition = $condition . ' AND ' . $componentClause;
564 self
::$activityType[$index] = CRM_Core_OptionGroup
::values('activity_type', FALSE, FALSE, FALSE, $condition, $returnColumn);
566 return self
::$activityType[$index];
570 * Get all the State/Province from database.
572 * The static array stateProvince is returned, and if it's
573 * called the first time, the <b>State Province DAO</b> is used
574 * to get all the States.
576 * Note: any database errors will be trapped by the DAO.
581 * @param int $id - Optional id to return
583 * @return array - array reference of all State/Provinces.
586 public static function &stateProvince($id = FALSE, $limit = TRUE) {
587 if (($id && !CRM_Utils_Array
::value($id, self
::$stateProvince)) ||
!self
::$stateProvince ||
!$id) {
588 $whereClause = FALSE;
589 $config = CRM_Core_Config
::singleton();
591 $countryIsoCodes = self
::countryIsoCode();
592 $limitCodes = $config->provinceLimit();
594 foreach ($limitCodes as $code) {
595 $limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
597 if (!empty($limitIds)) {
598 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
601 $whereClause = FALSE;
604 self
::populate(self
::$stateProvince, 'CRM_Core_DAO_StateProvince', TRUE, 'name', 'is_active', $whereClause);
606 // localise the province names if in an non-en_US locale
608 if ($tsLocale != '' and $tsLocale != 'en_US') {
609 $i18n = CRM_Core_I18n
::singleton();
610 $i18n->localizeArray(self
::$stateProvince, array(
611 'context' => 'province',
613 self
::$stateProvince = CRM_Utils_Array
::asort(self
::$stateProvince);
617 if (array_key_exists($id, self
::$stateProvince)) {
618 return self
::$stateProvince[$id];
625 return self
::$stateProvince;
629 * Get all the State/Province abbreviations from the database.
631 * Same as above, except gets the abbreviations instead of the names.
636 * @param int $id - Optional id to return
638 * @return array - array reference of all State/Province abbreviations.
640 public static function &stateProvinceAbbreviation($id = FALSE, $limit = TRUE) {
644 FROM civicrm_state_province
652 return CRM_Core_DAO
::singleValueQuery($query, $params);
655 if (!self
::$stateProvinceAbbreviation ||
!$id) {
657 $whereClause = FALSE;
660 $config = CRM_Core_Config
::singleton();
661 $countryIsoCodes = self
::countryIsoCode();
662 $limitCodes = $config->provinceLimit();
664 foreach ($limitCodes as $code) {
665 $tmpArray = array_keys($countryIsoCodes, $code);
667 if (!empty($tmpArray)) {
668 $limitIds[] = array_shift($tmpArray);
671 if (!empty($limitIds)) {
672 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
675 self
::populate(self
::$stateProvinceAbbreviation, 'CRM_Core_DAO_StateProvince', TRUE, 'abbreviation', 'is_active', $whereClause);
679 if (array_key_exists($id, self
::$stateProvinceAbbreviation)) {
680 return self
::$stateProvinceAbbreviation[$id];
687 return self
::$stateProvinceAbbreviation;
691 * Get all the countries from database.
693 * The static array country is returned, and if it's
694 * called the first time, the <b>Country DAO</b> is used
695 * to get all the countries.
697 * Note: any database errors will be trapped by the DAO.
702 * @param int $id - Optional id to return
704 * @return array - array reference of all countries.
707 public static function country($id = FALSE, $applyLimit = TRUE) {
708 if (($id && !CRM_Utils_Array
::value($id, self
::$country)) ||
!self
::$country ||
!$id) {
710 $config = CRM_Core_Config
::singleton();
711 $limitCodes = array();
714 // limit the country list to the countries specified in CIVICRM_COUNTRY_LIMIT
715 // (ensuring it's a subset of the legal values)
716 // K/P: We need to fix this, i dont think it works with new setting files
717 $limitCodes = $config->countryLimit();
718 if (!is_array($limitCodes)) {
720 $config->countryLimit
=> 1,
724 $limitCodes = array_intersect(self
::countryIsoCode(), $limitCodes);
727 if (count($limitCodes)) {
728 $whereClause = "iso_code IN ('" . implode("', '", $limitCodes) . "')";
734 self
::populate(self
::$country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active', $whereClause);
736 // if default country is set, percolate it to the top
737 if ($config->defaultContactCountry()) {
738 $countryIsoCodes = self
::countryIsoCode();
739 $defaultID = array_search($config->defaultContactCountry(), $countryIsoCodes);
740 if ($defaultID !== FALSE) {
741 $default[$defaultID] = CRM_Utils_Array
::value($defaultID, self
::$country);
742 self
::$country = $default + self
::$country;
746 // localise the country names if in an non-en_US locale
748 if ($tsLocale != '' and $tsLocale != 'en_US') {
749 $i18n = CRM_Core_I18n
::singleton();
750 $i18n->localizeArray(self
::$country, array(
751 'context' => 'country',
753 self
::$country = CRM_Utils_Array
::asort(self
::$country);
757 if (array_key_exists($id, self
::$country)) {
758 return self
::$country[$id];
761 return CRM_Core_DAO
::$_nullObject;
764 return self
::$country;
768 * Get all the country ISO Code abbreviations from the database.
770 * The static array countryIsoCode is returned, and if it's
771 * called the first time, the <b>Country DAO</b> is used
772 * to get all the countries' ISO codes.
774 * Note: any database errors will be trapped by the DAO.
779 * @return array - array reference of all country ISO codes.
782 public static function &countryIsoCode($id = FALSE) {
783 if (!self
::$countryIsoCode) {
784 self
::populate(self
::$countryIsoCode, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
787 if (array_key_exists($id, self
::$countryIsoCode)) {
788 return self
::$countryIsoCode[$id];
791 return CRM_Core_DAO
::$_nullObject;
794 return self
::$countryIsoCode;
798 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
800 * Get all groups from database
802 * The static array group is returned, and if it's
803 * called the first time, the <b>Group DAO</b> is used
804 * to get all the groups.
806 * Note: any database errors will be trapped by the DAO.
808 * @param string $groupType type of group(Access/Mailing)
809 * @param boolen $excludeHidden exclude hidden groups.
814 * @return array - array reference of all groups.
817 public static function &allGroup($groupType = NULL, $excludeHidden = TRUE) {
818 $condition = CRM_Contact_BAO_Group
::groupTypeCondition($groupType, $excludeHidden);
821 self
::$group = array();
824 $groupKey = $groupType ?
$groupType : 'null';
826 if (!isset(self
::$group[$groupKey])) {
827 self
::$group[$groupKey] = NULL;
828 self
::populate(self
::$group[$groupKey], 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition);
830 return self
::$group[$groupKey];
834 * Create or get groups iterator (iterates over nested groups in a
837 * The GroupNesting instance is returned; it's created if this is being
838 * called for the first time
844 * @return mixed - instance of CRM_Contact_BAO_GroupNesting
847 public static function &groupIterator($styledLabels = FALSE) {
848 if (!self
::$groupIterator) {
850 When used as an object, GroupNesting implements Iterator
851 and iterates nested groups in a logical manner for us
853 self
::$groupIterator = new CRM_Contact_BAO_GroupNesting($styledLabels);
855 return self
::$groupIterator;
859 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
861 * Get all permissioned groups from database
863 * The static array group is returned, and if it's
864 * called the first time, the <b>Group DAO</b> is used
865 * to get all the groups.
867 * Note: any database errors will be trapped by the DAO.
869 * @param string $groupType type of group(Access/Mailing)
870 * @param boolen $excludeHidden exclude hidden groups.
875 * @return array - array reference of all groups.
878 public static function group($groupType = NULL, $excludeHidden = TRUE) {
879 return CRM_Core_Permission
::group($groupType, $excludeHidden);
883 * Get all permissioned groups from database
885 * The static array group is returned, and if it's
886 * called the first time, the <b>Group DAO</b> is used
887 * to get all the groups.
889 * Note: any database errors will be trapped by the DAO.
894 * @return array - array reference of all groups.
897 public static function &staticGroup($onlyPublic = FALSE, $groupType = NULL, $excludeHidden = TRUE) {
898 if (!self
::$staticGroup) {
899 $condition = 'saved_search_id = 0 OR saved_search_id IS NULL';
901 $condition .= " AND visibility != 'User and User Admin Only'";
905 $condition .= ' AND ' . CRM_Contact_BAO_Group
::groupTypeCondition($groupType);
908 if ($excludeHidden) {
909 $condition .= ' AND is_hidden != 1 ';
912 self
::populate(self
::$staticGroup, 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition, 'title');
915 return self
::$staticGroup;
919 * Get all Relationship Types from database.
921 * The static array group is returned, and if it's
922 * called the first time, the <b>RelationshipType DAO</b> is used
923 * to get all the relationship types.
925 * Note: any database errors will be trapped by the DAO.
927 * @param string $valueColumnName db column name/label.
928 * @param boolean $reset reset relationship types if true
933 * @return array - array reference of all relationship types.
935 public static function &relationshipType($valueColumnName = 'label', $reset = FALSE) {
936 if (!CRM_Utils_Array
::value($valueColumnName, self
::$relationshipType) ||
$reset) {
937 self
::$relationshipType[$valueColumnName] = array();
939 //now we have name/label columns CRM-3336
940 $column_a_b = "{$valueColumnName}_a_b";
941 $column_b_a = "{$valueColumnName}_b_a";
943 $relationshipTypeDAO = new CRM_Contact_DAO_RelationshipType();
944 $relationshipTypeDAO->selectAdd();
945 $relationshipTypeDAO->selectAdd("id, {$column_a_b}, {$column_b_a}, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b");
946 $relationshipTypeDAO->is_active
= 1;
947 $relationshipTypeDAO->find();
948 while ($relationshipTypeDAO->fetch()) {
950 self
::$relationshipType[$valueColumnName][$relationshipTypeDAO->id
] = array(
951 $column_a_b => $relationshipTypeDAO->$column_a_b,
952 $column_b_a => $relationshipTypeDAO->$column_b_a,
953 'contact_type_a' => "$relationshipTypeDAO->contact_type_a",
954 'contact_type_b' => "$relationshipTypeDAO->contact_type_b",
955 'contact_sub_type_a' => "$relationshipTypeDAO->contact_sub_type_a",
956 'contact_sub_type_b' => "$relationshipTypeDAO->contact_sub_type_b",
961 return self
::$relationshipType[$valueColumnName];
965 * get all the ISO 4217 currency codes
967 * so far, we use this for validation only, so there's no point of putting this into the database
971 * @return array - array reference of all currency codes
974 public static function ¤cyCode() {
975 if (!self
::$currencyCode) {
976 self
::$currencyCode = array(
1246 return self
::$currencyCode;
1250 * Get all the County from database.
1252 * The static array county is returned, and if it's
1253 * called the first time, the <b>County DAO</b> is used
1254 * to get all the Counties.
1256 * Note: any database errors will be trapped by the DAO.
1261 * @param int $id - Optional id to return
1263 * @return array - array reference of all Counties
1266 public static function &county($id = FALSE) {
1267 if (!self
::$county) {
1269 $config = CRM_Core_Config
::singleton();
1270 // order by id so users who populate civicrm_county can have more control over sort by the order they load the counties
1271 self
::populate(self
::$county, 'CRM_Core_DAO_County', TRUE, 'name', NULL, NULL, 'id');
1274 if (array_key_exists($id, self
::$county)) {
1275 return self
::$county[$id];
1278 return CRM_Core_DAO
::$_nullObject;
1281 return self
::$county;
1285 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1286 * Get all active payment processors
1288 * The static array paymentProcessor is returned
1293 * @param boolean $all - get payment processors - default is to get only active ones.
1294 * @param boolean $test - get test payment processors
1296 * @return array - array of all payment processors
1299 public static function &paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
1300 $condition = "is_test = ";
1301 $condition .= ($test) ?
'1' : '0';
1303 if ($additionalCond) {
1304 $condition .= " AND ( $additionalCond ) ";
1307 // CRM-7178. Make sure we only include payment processors valid in ths
1309 $condition .= " AND domain_id = " . CRM_Core_Config
::domainID();
1311 $cacheKey = $condition . '_' . (int) $all;
1312 if (!isset(self
::$paymentProcessor[$cacheKey])) {
1313 self
::populate(self
::$paymentProcessor[$cacheKey], 'CRM_Financial_DAO_PaymentProcessor', $all, 'name', 'is_active', $condition, 'is_default desc, name');
1316 return self
::$paymentProcessor[$cacheKey];
1320 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1322 * The static array paymentProcessorType is returned
1327 * @param boolean $all - get payment processors - default is to get only active ones.
1329 * @return array - array of all payment processor types
1332 public static function &paymentProcessorType($all = FALSE, $id = NULL, $return = 'title') {
1333 $cacheKey = $id . '_' .$return;
1334 if (empty(self
::$paymentProcessorType[$cacheKey])) {
1335 self
::populate(self
::$paymentProcessorType[$cacheKey], 'CRM_Financial_DAO_PaymentProcessorType', $all, $return, 'is_active', NULL, "is_default, $return", 'id');
1337 if ($id && CRM_Utils_Array
::value($id, self
::$paymentProcessorType[$cacheKey])) {
1338 return self
::$paymentProcessorType[$cacheKey][$id];
1340 return self
::$paymentProcessorType[$cacheKey];
1344 * Get all the World Regions from Database
1348 * @return array - array reference of all World Regions
1351 public static function &worldRegion($id = FALSE) {
1352 if (!self
::$worldRegions) {
1353 self
::populate(self
::$worldRegions, 'CRM_Core_DAO_Worldregion', TRUE, 'name', NULL, NULL, 'id');
1357 if (array_key_exists($id, self
::$worldRegions)) {
1358 return self
::$worldRegions[$id];
1361 return CRM_Core_DAO
::$_nullObject;
1365 return self
::$worldRegions;
1369 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1371 * Get all Activity Statuses.
1373 * The static array activityStatus is returned
1378 * @return array - array reference of all activity statuses
1380 public static function &activityStatus($column = 'label') {
1381 if (NULL === self
::$activityStatus) {
1382 self
::$activityStatus = array();
1384 if (!array_key_exists($column, self
::$activityStatus)) {
1385 self
::$activityStatus[$column] = array();
1387 self
::$activityStatus[$column] = CRM_Core_OptionGroup
::values('activity_status', FALSE, FALSE, FALSE, NULL, $column);
1390 return self
::$activityStatus[$column];
1394 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1396 * Get all Visibility levels.
1398 * The static array visibility is returned
1403 * @return array - array reference of all Visibility levels.
1406 public static function &visibility($column = 'label') {
1407 if (!isset(self
::$visibility)) {
1408 self
::$visibility = array( );
1411 if (!isset(self
::$visibility[$column])) {
1412 self
::$visibility[$column] = CRM_Core_OptionGroup
::values('visibility', FALSE, FALSE, FALSE, NULL, $column);
1415 return self
::$visibility[$column];
1418 public static function &stateProvinceForCountry($countryID, $field = 'name') {
1419 static $_cache = NULL;
1421 $cacheKey = "{$countryID}_{$field}";
1426 if (!empty($_cache[$cacheKey])) {
1427 return $_cache[$cacheKey];
1431 SELECT civicrm_state_province.{$field} name, civicrm_state_province.id id
1432 FROM civicrm_state_province
1433 WHERE country_id = %1
1442 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1445 while ($dao->fetch()) {
1446 $result[$dao->id
] = $dao->name
;
1449 // localise the stateProvince names if in an non-en_US locale
1450 $config = CRM_Core_Config
::singleton();
1452 if ($tsLocale != '' and $tsLocale != 'en_US') {
1453 $i18n = CRM_Core_I18n
::singleton();
1454 $i18n->localizeArray($result, array(
1455 'context' => 'province',
1457 $result = CRM_Utils_Array
::asort($result);
1460 $_cache[$cacheKey] = $result;
1462 CRM_Utils_Hook
::buildStateProvinceForCountry($countryID, $result);
1467 public static function &countyForState($stateID) {
1468 if (is_array($stateID)) {
1469 $states = implode(", ", $stateID);
1471 SELECT civicrm_county.name name, civicrm_county.id id, civicrm_state_province.abbreviation abbreviation
1473 LEFT JOIN civicrm_state_province ON civicrm_county.state_province_id = civicrm_state_province.id
1474 WHERE civicrm_county.state_province_id in ( $states )
1475 ORDER BY civicrm_state_province.abbreviation, civicrm_county.name";
1477 $dao = CRM_Core_DAO
::executeQuery($query);
1480 while ($dao->fetch()) {
1481 $result[$dao->id
] = $dao->abbreviation
. ': ' . $dao->name
;
1486 static $_cache = NULL;
1488 $cacheKey = "{$stateID}_name";
1493 if (!empty($_cache[$cacheKey])) {
1494 return $_cache[$cacheKey];
1498 SELECT civicrm_county.name name, civicrm_county.id id
1500 WHERE state_province_id = %1
1509 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1512 while ($dao->fetch()) {
1513 $result[$dao->id
] = $dao->name
;
1521 * Given a state ID return the country ID, this allows
1522 * us to populate forms and values for downstream code
1524 * @param $stateID int
1526 * @return int the country id that the state belongs to
1530 static function countryIDForStateID($stateID) {
1531 if (empty($stateID)) {
1532 return CRM_Core_DAO
::$_nullObject;
1537 FROM civicrm_state_province
1540 $params = array(1 => array($stateID, 'Integer'));
1542 return CRM_Core_DAO
::singleValueQuery($query, $params);
1546 * Get all types of Greetings.
1548 * The static array of greeting is returned
1553 * @param $filter - get All Email Greetings - default is to get only active ones.
1555 * @return array - array reference of all greetings.
1558 public static function greeting($filter, $columnName = 'label') {
1559 $index = $filter['greeting_type'] . '_' . $columnName;
1561 // also add contactType to the array
1562 $contactType = CRM_Utils_Array
::value('contact_type', $filter);
1564 $index .= '_' . $contactType;
1567 if (NULL === self
::$greeting) {
1568 self
::$greeting = array();
1571 if (!CRM_Utils_Array
::value($index, self
::$greeting)) {
1572 $filterCondition = NULL;
1574 $filterVal = 'v.filter =';
1575 switch ($contactType) {
1584 case 'Organization':
1588 $filterCondition .= "AND (v.filter = 0 OR {$filterVal}) ";
1591 self
::$greeting[$index] = CRM_Core_OptionGroup
::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName);
1594 return self
::$greeting[$index];
1598 * Construct array of default greeting values for contact type
1603 * @return array - array reference of default greetings.
1606 public static function &greetingDefaults() {
1607 if (!self
::$greetingDefaults) {
1608 $defaultGreetings = array();
1609 $contactTypes = self
::get('CRM_Contact_DAO_Contact', 'contact_type', array('keyColumn' => 'id', 'labelColumn' => 'name'));
1611 foreach ($contactTypes as $filter => $contactType) {
1612 $filterCondition = " AND (v.filter = 0 OR v.filter = $filter) AND v.is_default = 1 ";
1614 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
1615 $tokenVal = CRM_Core_OptionGroup
::values($greeting, NULL, NULL, NULL, $filterCondition, 'label');
1616 $defaultGreetings[$contactType][$greeting] = $tokenVal;
1620 self
::$greetingDefaults = $defaultGreetings;
1623 return self
::$greetingDefaults;
1627 * Get all extensions
1629 * The static array extensions
1631 * FIXME: This is called by civix but not by any core code. We
1632 * should provide an API call which civix can use instead.
1637 * @return array - array($fullyQualifiedName => $label) list of extensions
1639 public static function &getExtensions() {
1640 if (!self
::$extensions) {
1641 self
::$extensions = array();
1643 SELECT full_name, label
1644 FROM civicrm_extension
1647 $dao = CRM_Core_DAO
::executeQuery($sql);
1648 while ($dao->fetch()) {
1649 self
::$extensions[$dao->full_name
] = $dao->label
;
1653 return self
::$extensions;
1657 * Get all options values
1659 * The static array option values is returned
1664 * @param boolean $optionGroupName - get All Option Group values- default is to get only active ones.
1666 * @return array - array reference of all Option Group Name
1669 public static function accountOptionValues($optionGroupName, $id = null, $condition = null) {
1670 $cacheKey = $optionGroupName . '_' . $condition;
1671 if (empty(self
::$accountOptionValues[$cacheKey])) {
1672 self
::$accountOptionValues[$cacheKey] = CRM_Core_OptionGroup
::values($optionGroupName, false, false, false, $condition);
1675 return CRM_Utils_Array
::value($id, self
::$accountOptionValues[$cacheKey]);
1678 return self
::$accountOptionValues[$cacheKey];
1682 * Fetch the list of active extensions of type 'module'
1684 * @param $fresh bool whether to forcibly reload extensions list from canonical store
1688 * @return array - array(array('prefix' => $, 'file' => $))
1690 public static function getModuleExtensions($fresh = FALSE) {
1691 return CRM_Extension_System
::singleton()->getMapper()->getActiveModuleFiles($fresh);