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
223 * @param String $context: Context string
225 * @return Array on success, FALSE on error.
229 public static function get($daoName, $fieldName, $params = array(), $context = NULL) {
230 CRM_Core_DAO
::buildOptionsContext($context);
231 $flip = !empty($params['flip']);
232 // Merge params with defaults
236 'onlyActive' => ($context == 'validate' ||
$context == 'create') ?
FALSE : TRUE,
240 // Custom fields are not in the schema
241 if (strpos($fieldName, 'custom_') === 0 && is_numeric($fieldName[7])) {
242 $customFieldID = (int) substr($fieldName, 7);
243 $optionGroupID = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomField', $customFieldID, 'option_group_id');
245 $options = CRM_Core_OptionGroup
::valuesByID($optionGroupID,
249 // Note: for custom fields the 'name' column is NULL
250 CRM_Utils_Array
::value('labelColumn', $params, 'label'),
251 $params['onlyActive'],
255 CRM_Utils_Hook
::customFieldOptions($customFieldID, $options, FALSE);
259 // Core field: load schema
261 $fields = $dao->fields();
262 $fieldKeys = $dao->fieldKeys();
265 // Support "unique names" as well as sql names
266 $fieldKey = $fieldName;
267 if (empty($fields[$fieldKey])) {
268 $fieldKey = $fieldKeys[$fieldName];
270 // If neither worked then this field doesn't exist. Return false.
271 if (empty($fields[$fieldKey])) {
274 $fieldSpec = $fields[$fieldKey];
276 // If the field is an enum, explode the enum definition and return the array.
277 if (isset($fieldSpec['enumValues'])) {
278 // use of a space after the comma is inconsistent in xml
279 $enumStr = str_replace(', ', ',', $fieldSpec['enumValues']);
280 $output = explode(',', $enumStr);
281 return array_combine($output, $output);
284 elseif (!empty($fieldSpec['pseudoconstant'])) {
285 $pseudoconstant = $fieldSpec['pseudoconstant'];
286 // Merge params with schema defaults
288 'condition' => CRM_Utils_Array
::value('condition', $pseudoconstant, array()),
289 'keyColumn' => CRM_Utils_Array
::value('keyColumn', $pseudoconstant),
290 'labelColumn' => CRM_Utils_Array
::value('labelColumn', $pseudoconstant),
293 // Fetch option group from option_value table
294 if(!empty($pseudoconstant['optionGroupName'])) {
295 if ($context == 'validate') {
296 $params['labelColumn'] = 'name';
298 // Call our generic fn for retrieving from the option_value table
299 return CRM_Core_OptionGroup
::values(
300 $pseudoconstant['optionGroupName'],
304 $params['condition'] ?
' AND ' . implode(' AND ', (array) $params['condition']) : NULL,
305 $params['labelColumn'] ?
$params['labelColumn'] : 'label',
306 $params['onlyActive'],
308 $params['keyColumn'] ?
$params['keyColumn'] : 'value'
312 // Fetch options from other tables
313 if (!empty($pseudoconstant['table'])) {
314 // Normalize params so the serialized cache string will be consistent.
315 CRM_Utils_Array
::remove($params, 'flip', 'fresh');
317 $cacheKey = $daoName . $fieldName . serialize($params);
319 // Retrieve cached options
320 if (isset(self
::$cache[$cacheKey]) && empty($params['fresh'])) {
321 $output = self
::$cache[$cacheKey];
324 $daoName = CRM_Core_DAO_AllCoreTables
::getClassForTable($pseudoconstant['table']);
325 if (!class_exists($daoName)) {
328 // Get list of fields for the option table
330 $availableFields = array_keys($dao->fieldKeys());
333 $select = "SELECT %1 AS id, %2 AS label";
336 $order = "ORDER BY %2";
338 // Use machine name instead of label in validate context
339 if ($context == 'validate') {
340 if (!empty($pseudoconstant['nameColumn'])) {
341 $params['labelColumn'] = $pseudoconstant['nameColumn'];
343 elseif (in_array('name', $availableFields)) {
344 $params['labelColumn'] = 'name';
347 // Condition param can be passed as an sql clause string or an array of clauses
348 if (!empty($params['condition'])) {
349 $wheres[] = implode(' AND ', (array) $params['condition']);
351 // onlyActive param will automatically filter on common flags
352 if (!empty($params['onlyActive'])) {
353 foreach (array('is_active' => 1, 'is_deleted' => 0, 'is_test' => 0) as $flag => $val) {
354 if (in_array($flag, $availableFields)) {
355 $wheres[] = "$flag = $val";
359 // Filter domain specific options
360 if (in_array('domain_id', $availableFields)) {
361 $wheres[] = 'domain_id = ' . CRM_Core_Config
::domainID();
363 $queryParams = array(
364 1 => array($params['keyColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
365 2 => array($params['labelColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
366 3 => array($pseudoconstant['table'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
368 // Add orderColumn param
369 if (!empty($params['orderColumn'])) {
370 $queryParams[4] = array($params['orderColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
);
371 $order = "ORDER BY %4";
373 // Support no sorting if $params[orderColumn] is FALSE
374 elseif (isset($params['orderColumn']) && $params['orderColumn'] === FALSE) {
377 // Default to 'weight' if that column exists
378 elseif (in_array('weight', $availableFields)) {
379 $order = "ORDER BY weight";
383 $query = "$select $from";
385 $query .= " WHERE " . implode($wheres, ' AND ');
387 $query .= ' ' . $order;
388 $dao = CRM_Core_DAO
::executeQuery($query, $queryParams);
389 while ($dao->fetch()) {
390 $output[$dao->id
] = $dao->label
;
393 if (!empty($params['localize'])) {
394 $i18n = CRM_Core_I18n
::singleton();
395 $i18n->localizeArray($output);
396 // Maintain sort by label
397 if ($order == "ORDER BY %2") {
398 CRM_Utils_Array
::asort($output);
401 self
::$cache[$cacheKey] = $output;
403 return $flip ?
array_flip($output) : $output;
406 // If we're still here, it's an error. Return FALSE.
411 * Fetch the label (or other value) for a field given its key
413 * @param String $daoName
414 * @param String $fieldName
415 * @param String|Int $key
416 * @param Array $params will be passed into self::get
418 * @return bool|null|string
419 * FALSE if the given field has no associated option list
420 * NULL if the given key has no corresponding option
421 * String if label is found
423 static function getValue($daoName, $fieldName, $key, $params = array()) {
424 $values = self
::get($daoName, $fieldName, $params);
425 if ($values === FALSE) {
428 return CRM_Utils_Array
::value($key, $values);
432 * Fetch the key for a field option given its label/name
434 * @param String $daoName
435 * @param String $fieldName
436 * @param String|Int $value
437 * @param Array $params will be passed into self::get
439 * @return bool|null|string|number
440 * FALSE if the given field has no associated option list
441 * NULL if the given key has no corresponding option
442 * String|Number if key is found
444 static function getKey($daoName, $fieldName, $value, $params = array()) {
445 $values = self
::get($daoName, $fieldName, $params);
446 if ($values === FALSE) {
449 return CRM_Utils_Array
::key($value, $values);
453 * DEPRECATED generic populate method
454 * All pseudoconstant functions that use this method are also deprecated.
456 * The static array $var is populated from the db
457 * using the <b>$name DAO</b>.
459 * Note: any database errors will be trapped by the DAO.
461 * @param array $var the associative array we will fill
462 * @param string $name the name of the DAO
463 * @param boolean $all get all objects. default is to get only active ones.
464 * @param string $retrieve the field that we are interested in (normally name, differs in some objects)
465 * @param string $filter the field that we want to filter the result set with
466 * @param string $condition the condition that gets passed to the final query as the WHERE clause
472 public static function populate(
477 $filter = 'is_active',
483 $cacheKey = "CRM_PC_{$name}_{$all}_{$key}_{$retrieve}_{$filter}_{$condition}_{$orderby}";
484 $cache = CRM_Utils_Cache
::singleton();
485 $var = $cache->get($cacheKey);
486 if ($var && empty($force)) {
490 $object = new $name ( );
492 $object->selectAdd();
493 $object->selectAdd("$key, $retrieve");
495 $object->whereAdd($condition);
499 $object->orderBy($retrieve);
502 $object->orderBy($orderby);
506 $object->$filter = 1;
511 while ($object->fetch()) {
512 $var[$object->$key] = $object->$retrieve;
515 $cache->set($cacheKey, $var);
519 * Flush given pseudoconstant so it can be reread from db
520 * nex time it's requested.
525 * @param boolean $name pseudoconstant to be flushed
528 public static function flush($name = 'cache') {
529 if (isset(self
::$
$name)) {
532 if ($name == 'cache') {
533 CRM_Core_OptionGroup
::flushAll();
538 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
540 * Get all Activty types.
542 * The static array activityType is returned
544 * @param boolean $all - get All Activity types - default is to get only active ones.
549 * @return array - array reference of all activity types.
551 public static function &activityType() {
552 $args = func_get_args();
553 $all = CRM_Utils_Array
::value(0, $args, TRUE);
554 $includeCaseActivities = CRM_Utils_Array
::value(1, $args, FALSE);
555 $reset = CRM_Utils_Array
::value(2, $args, FALSE);
556 $returnColumn = CRM_Utils_Array
::value(3, $args, 'label');
557 $includeCampaignActivities = CRM_Utils_Array
::value(4, $args, FALSE);
558 $onlyComponentActivities = CRM_Utils_Array
::value(5, $args, FALSE);
559 $index = (int) $all . '_' . $returnColumn . '_' . (int) $includeCaseActivities;
560 $index .= '_' . (int) $includeCampaignActivities;
561 $index .= '_' . (int) $onlyComponentActivities;
563 if (NULL === self
::$activityType) {
564 self
::$activityType = array();
567 if (!isset(self
::$activityType[$index]) ||
$reset) {
570 $condition = 'AND filter = 0';
572 $componentClause = " v.component_id IS NULL";
573 if ($onlyComponentActivities) {
574 $componentClause = " v.component_id IS NOT NULL";
577 $componentIds = array();
578 $compInfo = CRM_Core_Component
::getEnabledComponents();
580 // build filter for listing activity types only if their
581 // respective components are enabled
582 foreach ($compInfo as $compName => $compObj) {
583 if ($compName == 'CiviCase') {
584 if ($includeCaseActivities) {
585 $componentIds[] = $compObj->componentID
;
588 elseif ($compName == 'CiviCampaign') {
589 if ($includeCampaignActivities) {
590 $componentIds[] = $compObj->componentID
;
594 $componentIds[] = $compObj->componentID
;
598 if (count($componentIds)) {
599 $componentIds = implode(',', $componentIds);
600 $componentClause = " ($componentClause OR v.component_id IN ($componentIds))";
601 if ($onlyComponentActivities) {
602 $componentClause = " ( v.component_id IN ($componentIds ) )";
605 $condition = $condition . ' AND ' . $componentClause;
607 self
::$activityType[$index] = CRM_Core_OptionGroup
::values('activity_type', FALSE, FALSE, FALSE, $condition, $returnColumn);
609 return self
::$activityType[$index];
613 * Get all the State/Province from database.
615 * The static array stateProvince is returned, and if it's
616 * called the first time, the <b>State Province DAO</b> is used
617 * to get all the States.
619 * Note: any database errors will be trapped by the DAO.
624 * @param int $id - Optional id to return
626 * @return array - array reference of all State/Provinces.
629 public static function &stateProvince($id = FALSE, $limit = TRUE) {
630 if (($id && !CRM_Utils_Array
::value($id, self
::$stateProvince)) ||
!self
::$stateProvince ||
!$id) {
631 $whereClause = FALSE;
632 $config = CRM_Core_Config
::singleton();
634 $countryIsoCodes = self
::countryIsoCode();
635 $limitCodes = $config->provinceLimit();
637 foreach ($limitCodes as $code) {
638 $limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
640 if (!empty($limitIds)) {
641 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
644 $whereClause = FALSE;
647 self
::populate(self
::$stateProvince, 'CRM_Core_DAO_StateProvince', TRUE, 'name', 'is_active', $whereClause);
649 // localise the province names if in an non-en_US locale
651 if ($tsLocale != '' and $tsLocale != 'en_US') {
652 $i18n = CRM_Core_I18n
::singleton();
653 $i18n->localizeArray(self
::$stateProvince, array(
654 'context' => 'province',
656 self
::$stateProvince = CRM_Utils_Array
::asort(self
::$stateProvince);
660 if (array_key_exists($id, self
::$stateProvince)) {
661 return self
::$stateProvince[$id];
668 return self
::$stateProvince;
672 * Get all the State/Province abbreviations from the database.
674 * Same as above, except gets the abbreviations instead of the names.
679 * @param int $id - Optional id to return
681 * @return array - array reference of all State/Province abbreviations.
683 public static function &stateProvinceAbbreviation($id = FALSE, $limit = TRUE) {
687 FROM civicrm_state_province
695 return CRM_Core_DAO
::singleValueQuery($query, $params);
698 if (!self
::$stateProvinceAbbreviation ||
!$id) {
700 $whereClause = FALSE;
703 $config = CRM_Core_Config
::singleton();
704 $countryIsoCodes = self
::countryIsoCode();
705 $limitCodes = $config->provinceLimit();
707 foreach ($limitCodes as $code) {
708 $tmpArray = array_keys($countryIsoCodes, $code);
710 if (!empty($tmpArray)) {
711 $limitIds[] = array_shift($tmpArray);
714 if (!empty($limitIds)) {
715 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
718 self
::populate(self
::$stateProvinceAbbreviation, 'CRM_Core_DAO_StateProvince', TRUE, 'abbreviation', 'is_active', $whereClause);
722 if (array_key_exists($id, self
::$stateProvinceAbbreviation)) {
723 return self
::$stateProvinceAbbreviation[$id];
730 return self
::$stateProvinceAbbreviation;
734 * Get all the countries from database.
736 * The static array country is returned, and if it's
737 * called the first time, the <b>Country DAO</b> is used
738 * to get all the countries.
740 * Note: any database errors will be trapped by the DAO.
745 * @param int $id - Optional id to return
747 * @return array - array reference of all countries.
750 public static function country($id = FALSE, $applyLimit = TRUE) {
751 if (($id && !CRM_Utils_Array
::value($id, self
::$country)) ||
!self
::$country ||
!$id) {
753 $config = CRM_Core_Config
::singleton();
754 $limitCodes = array();
757 // limit the country list to the countries specified in CIVICRM_COUNTRY_LIMIT
758 // (ensuring it's a subset of the legal values)
759 // K/P: We need to fix this, i dont think it works with new setting files
760 $limitCodes = $config->countryLimit();
761 if (!is_array($limitCodes)) {
763 $config->countryLimit
=> 1,
767 $limitCodes = array_intersect(self
::countryIsoCode(), $limitCodes);
770 if (count($limitCodes)) {
771 $whereClause = "iso_code IN ('" . implode("', '", $limitCodes) . "')";
777 self
::populate(self
::$country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active', $whereClause);
779 // if default country is set, percolate it to the top
780 if ($config->defaultContactCountry()) {
781 $countryIsoCodes = self
::countryIsoCode();
782 $defaultID = array_search($config->defaultContactCountry(), $countryIsoCodes);
783 if ($defaultID !== FALSE) {
784 $default[$defaultID] = CRM_Utils_Array
::value($defaultID, self
::$country);
785 self
::$country = $default + self
::$country;
789 // localise the country names if in an non-en_US locale
791 if ($tsLocale != '' and $tsLocale != 'en_US') {
792 $i18n = CRM_Core_I18n
::singleton();
793 $i18n->localizeArray(self
::$country, array(
794 'context' => 'country',
796 self
::$country = CRM_Utils_Array
::asort(self
::$country);
800 if (array_key_exists($id, self
::$country)) {
801 return self
::$country[$id];
804 return CRM_Core_DAO
::$_nullObject;
807 return self
::$country;
811 * Get all the country ISO Code abbreviations from the database.
813 * The static array countryIsoCode is returned, and if it's
814 * called the first time, the <b>Country DAO</b> is used
815 * to get all the countries' ISO codes.
817 * Note: any database errors will be trapped by the DAO.
822 * @return array - array reference of all country ISO codes.
825 public static function &countryIsoCode($id = FALSE) {
826 if (!self
::$countryIsoCode) {
827 self
::populate(self
::$countryIsoCode, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
830 if (array_key_exists($id, self
::$countryIsoCode)) {
831 return self
::$countryIsoCode[$id];
834 return CRM_Core_DAO
::$_nullObject;
837 return self
::$countryIsoCode;
841 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
843 * Get all groups from database
845 * The static array group is returned, and if it's
846 * called the first time, the <b>Group DAO</b> is used
847 * to get all the groups.
849 * Note: any database errors will be trapped by the DAO.
851 * @param string $groupType type of group(Access/Mailing)
852 * @param boolen $excludeHidden exclude hidden groups.
857 * @return array - array reference of all groups.
860 public static function &allGroup($groupType = NULL, $excludeHidden = TRUE) {
861 $condition = CRM_Contact_BAO_Group
::groupTypeCondition($groupType, $excludeHidden);
864 self
::$group = array();
867 $groupKey = $groupType ?
$groupType : 'null';
869 if (!isset(self
::$group[$groupKey])) {
870 self
::$group[$groupKey] = NULL;
871 self
::populate(self
::$group[$groupKey], 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition);
873 return self
::$group[$groupKey];
877 * Create or get groups iterator (iterates over nested groups in a
880 * The GroupNesting instance is returned; it's created if this is being
881 * called for the first time
887 * @return mixed - instance of CRM_Contact_BAO_GroupNesting
890 public static function &groupIterator($styledLabels = FALSE) {
891 if (!self
::$groupIterator) {
893 When used as an object, GroupNesting implements Iterator
894 and iterates nested groups in a logical manner for us
896 self
::$groupIterator = new CRM_Contact_BAO_GroupNesting($styledLabels);
898 return self
::$groupIterator;
902 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
904 * Get all permissioned groups from database
906 * The static array group is returned, and if it's
907 * called the first time, the <b>Group DAO</b> is used
908 * to get all the groups.
910 * Note: any database errors will be trapped by the DAO.
912 * @param string $groupType type of group(Access/Mailing)
913 * @param boolen $excludeHidden exclude hidden groups.
918 * @return array - array reference of all groups.
921 public static function group($groupType = NULL, $excludeHidden = TRUE) {
922 return CRM_Core_Permission
::group($groupType, $excludeHidden);
926 * Get all permissioned groups from database
928 * The static array group is returned, and if it's
929 * called the first time, the <b>Group DAO</b> is used
930 * to get all the groups.
932 * Note: any database errors will be trapped by the DAO.
937 * @return array - array reference of all groups.
940 public static function &staticGroup($onlyPublic = FALSE, $groupType = NULL, $excludeHidden = TRUE) {
941 if (!self
::$staticGroup) {
942 $condition = 'saved_search_id = 0 OR saved_search_id IS NULL';
944 $condition .= " AND visibility != 'User and User Admin Only'";
948 $condition .= ' AND ' . CRM_Contact_BAO_Group
::groupTypeCondition($groupType);
951 if ($excludeHidden) {
952 $condition .= ' AND is_hidden != 1 ';
955 self
::populate(self
::$staticGroup, 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition, 'title');
958 return self
::$staticGroup;
962 * Get all Relationship Types from database.
964 * The static array group is returned, and if it's
965 * called the first time, the <b>RelationshipType DAO</b> is used
966 * to get all the relationship types.
968 * Note: any database errors will be trapped by the DAO.
970 * @param string $valueColumnName db column name/label.
971 * @param boolean $reset reset relationship types if true
976 * @return array - array reference of all relationship types.
978 public static function &relationshipType($valueColumnName = 'label', $reset = FALSE) {
979 if (!CRM_Utils_Array
::value($valueColumnName, self
::$relationshipType) ||
$reset) {
980 self
::$relationshipType[$valueColumnName] = array();
982 //now we have name/label columns CRM-3336
983 $column_a_b = "{$valueColumnName}_a_b";
984 $column_b_a = "{$valueColumnName}_b_a";
986 $relationshipTypeDAO = new CRM_Contact_DAO_RelationshipType();
987 $relationshipTypeDAO->selectAdd();
988 $relationshipTypeDAO->selectAdd("id, {$column_a_b}, {$column_b_a}, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b");
989 $relationshipTypeDAO->is_active
= 1;
990 $relationshipTypeDAO->find();
991 while ($relationshipTypeDAO->fetch()) {
993 self
::$relationshipType[$valueColumnName][$relationshipTypeDAO->id
] = array(
994 $column_a_b => $relationshipTypeDAO->$column_a_b,
995 $column_b_a => $relationshipTypeDAO->$column_b_a,
996 'contact_type_a' => "$relationshipTypeDAO->contact_type_a",
997 'contact_type_b' => "$relationshipTypeDAO->contact_type_b",
998 'contact_sub_type_a' => "$relationshipTypeDAO->contact_sub_type_a",
999 'contact_sub_type_b' => "$relationshipTypeDAO->contact_sub_type_b",
1004 return self
::$relationshipType[$valueColumnName];
1008 * get all the ISO 4217 currency codes
1010 * so far, we use this for validation only, so there's no point of putting this into the database
1014 * @return array - array reference of all currency codes
1017 public static function ¤cyCode() {
1018 if (!self
::$currencyCode) {
1019 self
::$currencyCode = array(
1289 return self
::$currencyCode;
1293 * Get all the County from database.
1295 * The static array county is returned, and if it's
1296 * called the first time, the <b>County DAO</b> is used
1297 * to get all the Counties.
1299 * Note: any database errors will be trapped by the DAO.
1304 * @param int $id - Optional id to return
1306 * @return array - array reference of all Counties
1309 public static function &county($id = FALSE) {
1310 if (!self
::$county) {
1312 $config = CRM_Core_Config
::singleton();
1313 // order by id so users who populate civicrm_county can have more control over sort by the order they load the counties
1314 self
::populate(self
::$county, 'CRM_Core_DAO_County', TRUE, 'name', NULL, NULL, 'id');
1317 if (array_key_exists($id, self
::$county)) {
1318 return self
::$county[$id];
1321 return CRM_Core_DAO
::$_nullObject;
1324 return self
::$county;
1328 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1329 * Get all active payment processors
1331 * The static array paymentProcessor is returned
1336 * @param boolean $all - get payment processors - default is to get only active ones.
1337 * @param boolean $test - get test payment processors
1339 * @return array - array of all payment processors
1342 public static function &paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
1343 $condition = "is_test = ";
1344 $condition .= ($test) ?
'1' : '0';
1346 if ($additionalCond) {
1347 $condition .= " AND ( $additionalCond ) ";
1350 // CRM-7178. Make sure we only include payment processors valid in ths
1352 $condition .= " AND domain_id = " . CRM_Core_Config
::domainID();
1354 $cacheKey = $condition . '_' . (int) $all;
1355 if (!isset(self
::$paymentProcessor[$cacheKey])) {
1356 self
::populate(self
::$paymentProcessor[$cacheKey], 'CRM_Financial_DAO_PaymentProcessor', $all, 'name', 'is_active', $condition, 'is_default desc, name');
1359 return self
::$paymentProcessor[$cacheKey];
1363 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1365 * The static array paymentProcessorType is returned
1370 * @param boolean $all - get payment processors - default is to get only active ones.
1372 * @return array - array of all payment processor types
1375 public static function &paymentProcessorType($all = FALSE, $id = NULL, $return = 'title') {
1376 $cacheKey = $id . '_' .$return;
1377 if (empty(self
::$paymentProcessorType[$cacheKey])) {
1378 self
::populate(self
::$paymentProcessorType[$cacheKey], 'CRM_Financial_DAO_PaymentProcessorType', $all, $return, 'is_active', NULL, "is_default, $return", 'id');
1380 if ($id && CRM_Utils_Array
::value($id, self
::$paymentProcessorType[$cacheKey])) {
1381 return self
::$paymentProcessorType[$cacheKey][$id];
1383 return self
::$paymentProcessorType[$cacheKey];
1387 * Get all the World Regions from Database
1391 * @return array - array reference of all World Regions
1394 public static function &worldRegion($id = FALSE) {
1395 if (!self
::$worldRegions) {
1396 self
::populate(self
::$worldRegions, 'CRM_Core_DAO_Worldregion', TRUE, 'name', NULL, NULL, 'id');
1400 if (array_key_exists($id, self
::$worldRegions)) {
1401 return self
::$worldRegions[$id];
1404 return CRM_Core_DAO
::$_nullObject;
1408 return self
::$worldRegions;
1412 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1414 * Get all Activity Statuses.
1416 * The static array activityStatus is returned
1421 * @return array - array reference of all activity statuses
1423 public static function &activityStatus($column = 'label') {
1424 if (NULL === self
::$activityStatus) {
1425 self
::$activityStatus = array();
1427 if (!array_key_exists($column, self
::$activityStatus)) {
1428 self
::$activityStatus[$column] = array();
1430 self
::$activityStatus[$column] = CRM_Core_OptionGroup
::values('activity_status', FALSE, FALSE, FALSE, NULL, $column);
1433 return self
::$activityStatus[$column];
1437 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1439 * Get all Visibility levels.
1441 * The static array visibility is returned
1446 * @return array - array reference of all Visibility levels.
1449 public static function &visibility($column = 'label') {
1450 if (!isset(self
::$visibility)) {
1451 self
::$visibility = array( );
1454 if (!isset(self
::$visibility[$column])) {
1455 self
::$visibility[$column] = CRM_Core_OptionGroup
::values('visibility', FALSE, FALSE, FALSE, NULL, $column);
1458 return self
::$visibility[$column];
1461 public static function &stateProvinceForCountry($countryID, $field = 'name') {
1462 static $_cache = NULL;
1464 $cacheKey = "{$countryID}_{$field}";
1469 if (!empty($_cache[$cacheKey])) {
1470 return $_cache[$cacheKey];
1474 SELECT civicrm_state_province.{$field} name, civicrm_state_province.id id
1475 FROM civicrm_state_province
1476 WHERE country_id = %1
1485 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1488 while ($dao->fetch()) {
1489 $result[$dao->id
] = $dao->name
;
1492 // localise the stateProvince names if in an non-en_US locale
1493 $config = CRM_Core_Config
::singleton();
1495 if ($tsLocale != '' and $tsLocale != 'en_US') {
1496 $i18n = CRM_Core_I18n
::singleton();
1497 $i18n->localizeArray($result, array(
1498 'context' => 'province',
1500 $result = CRM_Utils_Array
::asort($result);
1503 $_cache[$cacheKey] = $result;
1505 CRM_Utils_Hook
::buildStateProvinceForCountry($countryID, $result);
1510 public static function &countyForState($stateID) {
1511 if (is_array($stateID)) {
1512 $states = implode(", ", $stateID);
1514 SELECT civicrm_county.name name, civicrm_county.id id, civicrm_state_province.abbreviation abbreviation
1516 LEFT JOIN civicrm_state_province ON civicrm_county.state_province_id = civicrm_state_province.id
1517 WHERE civicrm_county.state_province_id in ( $states )
1518 ORDER BY civicrm_state_province.abbreviation, civicrm_county.name";
1520 $dao = CRM_Core_DAO
::executeQuery($query);
1523 while ($dao->fetch()) {
1524 $result[$dao->id
] = $dao->abbreviation
. ': ' . $dao->name
;
1529 static $_cache = NULL;
1531 $cacheKey = "{$stateID}_name";
1536 if (!empty($_cache[$cacheKey])) {
1537 return $_cache[$cacheKey];
1541 SELECT civicrm_county.name name, civicrm_county.id id
1543 WHERE state_province_id = %1
1552 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1555 while ($dao->fetch()) {
1556 $result[$dao->id
] = $dao->name
;
1564 * Given a state ID return the country ID, this allows
1565 * us to populate forms and values for downstream code
1567 * @param $stateID int
1569 * @return int the country id that the state belongs to
1573 static function countryIDForStateID($stateID) {
1574 if (empty($stateID)) {
1575 return CRM_Core_DAO
::$_nullObject;
1580 FROM civicrm_state_province
1583 $params = array(1 => array($stateID, 'Integer'));
1585 return CRM_Core_DAO
::singleValueQuery($query, $params);
1589 * Get all types of Greetings.
1591 * The static array of greeting is returned
1596 * @param $filter - get All Email Greetings - default is to get only active ones.
1598 * @return array - array reference of all greetings.
1601 public static function greeting($filter, $columnName = 'label') {
1602 $index = $filter['greeting_type'] . '_' . $columnName;
1604 // also add contactType to the array
1605 $contactType = CRM_Utils_Array
::value('contact_type', $filter);
1607 $index .= '_' . $contactType;
1610 if (NULL === self
::$greeting) {
1611 self
::$greeting = array();
1614 if (!CRM_Utils_Array
::value($index, self
::$greeting)) {
1615 $filterCondition = NULL;
1617 $filterVal = 'v.filter =';
1618 switch ($contactType) {
1627 case 'Organization':
1631 $filterCondition .= "AND (v.filter = 0 OR {$filterVal}) ";
1634 self
::$greeting[$index] = CRM_Core_OptionGroup
::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName);
1637 return self
::$greeting[$index];
1641 * Construct array of default greeting values for contact type
1646 * @return array - array reference of default greetings.
1649 public static function &greetingDefaults() {
1650 if (!self
::$greetingDefaults) {
1651 $defaultGreetings = array();
1652 $contactTypes = self
::get('CRM_Contact_DAO_Contact', 'contact_type', array('keyColumn' => 'id', 'labelColumn' => 'name'));
1654 foreach ($contactTypes as $filter => $contactType) {
1655 $filterCondition = " AND (v.filter = 0 OR v.filter = $filter) AND v.is_default = 1 ";
1657 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
1658 $tokenVal = CRM_Core_OptionGroup
::values($greeting, NULL, NULL, NULL, $filterCondition, 'label');
1659 $defaultGreetings[$contactType][$greeting] = $tokenVal;
1663 self
::$greetingDefaults = $defaultGreetings;
1666 return self
::$greetingDefaults;
1670 * Get all extensions
1672 * The static array extensions
1674 * FIXME: This is called by civix but not by any core code. We
1675 * should provide an API call which civix can use instead.
1680 * @return array - array($fullyQualifiedName => $label) list of extensions
1682 public static function &getExtensions() {
1683 if (!self
::$extensions) {
1684 self
::$extensions = array();
1686 SELECT full_name, label
1687 FROM civicrm_extension
1690 $dao = CRM_Core_DAO
::executeQuery($sql);
1691 while ($dao->fetch()) {
1692 self
::$extensions[$dao->full_name
] = $dao->label
;
1696 return self
::$extensions;
1700 * Get all options values
1702 * The static array option values is returned
1707 * @param boolean $optionGroupName - get All Option Group values- default is to get only active ones.
1709 * @return array - array reference of all Option Group Name
1712 public static function accountOptionValues($optionGroupName, $id = null, $condition = null) {
1713 $cacheKey = $optionGroupName . '_' . $condition;
1714 if (empty(self
::$accountOptionValues[$cacheKey])) {
1715 self
::$accountOptionValues[$cacheKey] = CRM_Core_OptionGroup
::values($optionGroupName, false, false, false, $condition);
1718 return CRM_Utils_Array
::value($id, self
::$accountOptionValues[$cacheKey]);
1721 return self
::$accountOptionValues[$cacheKey];
1725 * Fetch the list of active extensions of type 'module'
1727 * @param $fresh bool whether to forcibly reload extensions list from canonical store
1731 * @return array - array(array('prefix' => $, 'file' => $))
1733 public static function getModuleExtensions($fresh = FALSE) {
1734 return CRM_Extension_System
::singleton()->getMapper()->getActiveModuleFiles($fresh);