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();
263 $fieldKey = $fieldKeys[$fieldName];
265 if (empty($fields[$fieldKey])) {
268 $fieldSpec = $fields[$fieldKey];
270 // If the field is an enum, explode the enum definition and return the array.
271 if (isset($fieldSpec['enumValues'])) {
272 // use of a space after the comma is inconsistent in xml
273 $enumStr = str_replace(', ', ',', $fieldSpec['enumValues']);
274 $output = explode(',', $enumStr);
275 return array_combine($output, $output);
278 elseif (!empty($fieldSpec['pseudoconstant'])) {
279 $pseudoconstant = $fieldSpec['pseudoconstant'];
280 // Merge params with schema defaults
282 'condition' => CRM_Utils_Array
::value('condition', $pseudoconstant, array()),
283 'keyColumn' => CRM_Utils_Array
::value('keyColumn', $pseudoconstant),
284 'labelColumn' => CRM_Utils_Array
::value('labelColumn', $pseudoconstant),
287 // Fetch option group from option_value table
288 if(!empty($pseudoconstant['optionGroupName'])) {
289 if ($context == 'validate') {
290 $params['labelColumn'] = 'name';
292 // Call our generic fn for retrieving from the option_value table
293 return CRM_Core_OptionGroup
::values(
294 $pseudoconstant['optionGroupName'],
298 $params['condition'] ?
' AND ' . implode(' AND ', (array) $params['condition']) : NULL,
299 $params['labelColumn'] ?
$params['labelColumn'] : 'label',
300 $params['onlyActive'],
302 $params['keyColumn'] ?
$params['keyColumn'] : 'value'
306 // Fetch options from other tables
307 if (!empty($pseudoconstant['table'])) {
308 // Normalize params so the serialized cache string will be consistent.
309 CRM_Utils_Array
::remove($params, 'flip', 'fresh');
311 $cacheKey = $daoName . $fieldName . serialize($params);
313 // Retrieve cached options
314 if (isset(self
::$cache[$cacheKey]) && empty($params['fresh'])) {
315 $output = self
::$cache[$cacheKey];
318 $daoName = CRM_Core_DAO_AllCoreTables
::getClassForTable($pseudoconstant['table']);
319 if (!class_exists($daoName)) {
322 // Get list of fields for the option table
324 $availableFields = array_keys($dao->fieldKeys());
327 $select = "SELECT %1 AS id, %2 AS label";
330 $order = "ORDER BY %2";
332 // Use machine name instead of label in validate context
333 if ($context == 'validate') {
334 if (!empty($pseudoconstant['nameColumn'])) {
335 $params['labelColumn'] = $pseudoconstant['nameColumn'];
337 elseif (in_array('name', $availableFields)) {
338 $params['labelColumn'] = 'name';
341 // Condition param can be passed as an sql clause string or an array of clauses
342 if (!empty($params['condition'])) {
343 $wheres[] = implode(' AND ', (array) $params['condition']);
345 // onlyActive param will automatically filter on common flags
346 if (!empty($params['onlyActive'])) {
347 foreach (array('is_active' => 1, 'is_deleted' => 0, 'is_test' => 0) as $flag => $val) {
348 if (in_array($flag, $availableFields)) {
349 $wheres[] = "$flag = $val";
353 // Filter domain specific options
354 if (in_array('domain_id', $availableFields)) {
355 $wheres[] = 'domain_id = ' . CRM_Core_Config
::domainID();
357 $queryParams = array(
358 1 => array($params['keyColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
359 2 => array($params['labelColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
360 3 => array($pseudoconstant['table'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
362 // Add orderColumn param
363 if (!empty($params['orderColumn'])) {
364 $queryParams[4] = array($params['orderColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
);
365 $order = "ORDER BY %4";
367 // Support no sorting if $params[orderColumn] is FALSE
368 elseif (isset($params['orderColumn']) && $params['orderColumn'] === FALSE) {
371 // Default to 'weight' if that column exists
372 elseif (in_array('weight', $availableFields)) {
373 $order = "ORDER BY weight";
377 $query = "$select $from";
379 $query .= " WHERE " . implode($wheres, ' AND ');
381 $query .= ' ' . $order;
382 $dao = CRM_Core_DAO
::executeQuery($query, $queryParams);
383 while ($dao->fetch()) {
384 $output[$dao->id
] = $dao->label
;
387 if (!empty($params['localize'])) {
388 $i18n = CRM_Core_I18n
::singleton();
389 $i18n->localizeArray($output);
390 // Maintain sort by label
391 if ($order == "ORDER BY %2") {
392 CRM_Utils_Array
::asort($output);
395 self
::$cache[$cacheKey] = $output;
397 return $flip ?
array_flip($output) : $output;
400 // If we're still here, it's an error. Return FALSE.
405 * Fetch the label (or other value) for a field given its key
407 * @param String $daoName
408 * @param String $fieldName
409 * @param String|Int $key
410 * @param Array $params will be passed into self::get
414 static function getValue($daoName, $fieldName, $key, $params = array()) {
415 $values = self
::get($daoName, $fieldName, $params);
416 return CRM_Utils_Array
::value($key, $values);
420 * Fetch the key for a field option given its label/name
422 * @param String $daoName
423 * @param String $fieldName
424 * @param String|Int $value
425 * @param Array $params will be passed into self::get
429 static function getKey($daoName, $fieldName, $value, $params = array()) {
430 $values = self
::get($daoName, $fieldName, $params);
431 return CRM_Utils_Array
::key($value, $values);
435 * DEPRECATED generic populate method
436 * All pseudoconstant functions that use this method are also deprecated.
438 * The static array $var is populated from the db
439 * using the <b>$name DAO</b>.
441 * Note: any database errors will be trapped by the DAO.
443 * @param array $var the associative array we will fill
444 * @param string $name the name of the DAO
445 * @param boolean $all get all objects. default is to get only active ones.
446 * @param string $retrieve the field that we are interested in (normally name, differs in some objects)
447 * @param string $filter the field that we want to filter the result set with
448 * @param string $condition the condition that gets passed to the final query as the WHERE clause
454 public static function populate(
459 $filter = 'is_active',
465 $cacheKey = "CRM_PC_{$name}_{$all}_{$key}_{$retrieve}_{$filter}_{$condition}_{$orderby}";
466 $cache = CRM_Utils_Cache
::singleton();
467 $var = $cache->get($cacheKey);
468 if ($var && empty($force)) {
472 $object = new $name ( );
474 $object->selectAdd();
475 $object->selectAdd("$key, $retrieve");
477 $object->whereAdd($condition);
481 $object->orderBy($retrieve);
484 $object->orderBy($orderby);
488 $object->$filter = 1;
493 while ($object->fetch()) {
494 $var[$object->$key] = $object->$retrieve;
497 $cache->set($cacheKey, $var);
501 * Flush given pseudoconstant so it can be reread from db
502 * nex time it's requested.
507 * @param boolean $name pseudoconstant to be flushed
510 public static function flush($name = 'cache') {
511 if (isset(self
::$
$name)) {
514 if ($name == 'cache') {
515 CRM_Core_OptionGroup
::flushAll();
520 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
522 * Get all Activty types.
524 * The static array activityType is returned
526 * @param boolean $all - get All Activity types - default is to get only active ones.
531 * @return array - array reference of all activity types.
533 public static function &activityType() {
534 $args = func_get_args();
535 $all = CRM_Utils_Array
::value(0, $args, TRUE);
536 $includeCaseActivities = CRM_Utils_Array
::value(1, $args, FALSE);
537 $reset = CRM_Utils_Array
::value(2, $args, FALSE);
538 $returnColumn = CRM_Utils_Array
::value(3, $args, 'label');
539 $includeCampaignActivities = CRM_Utils_Array
::value(4, $args, FALSE);
540 $onlyComponentActivities = CRM_Utils_Array
::value(5, $args, FALSE);
541 $index = (int) $all . '_' . $returnColumn . '_' . (int) $includeCaseActivities;
542 $index .= '_' . (int) $includeCampaignActivities;
543 $index .= '_' . (int) $onlyComponentActivities;
545 if (NULL === self
::$activityType) {
546 self
::$activityType = array();
549 if (!isset(self
::$activityType[$index]) ||
$reset) {
552 $condition = 'AND filter = 0';
554 $componentClause = " v.component_id IS NULL";
555 if ($onlyComponentActivities) {
556 $componentClause = " v.component_id IS NOT NULL";
559 $componentIds = array();
560 $compInfo = CRM_Core_Component
::getEnabledComponents();
562 // build filter for listing activity types only if their
563 // respective components are enabled
564 foreach ($compInfo as $compName => $compObj) {
565 if ($compName == 'CiviCase') {
566 if ($includeCaseActivities) {
567 $componentIds[] = $compObj->componentID
;
570 elseif ($compName == 'CiviCampaign') {
571 if ($includeCampaignActivities) {
572 $componentIds[] = $compObj->componentID
;
576 $componentIds[] = $compObj->componentID
;
580 if (count($componentIds)) {
581 $componentIds = implode(',', $componentIds);
582 $componentClause = " ($componentClause OR v.component_id IN ($componentIds))";
583 if ($onlyComponentActivities) {
584 $componentClause = " ( v.component_id IN ($componentIds ) )";
587 $condition = $condition . ' AND ' . $componentClause;
589 self
::$activityType[$index] = CRM_Core_OptionGroup
::values('activity_type', FALSE, FALSE, FALSE, $condition, $returnColumn);
591 return self
::$activityType[$index];
595 * Get all the State/Province from database.
597 * The static array stateProvince is returned, and if it's
598 * called the first time, the <b>State Province DAO</b> is used
599 * to get all the States.
601 * Note: any database errors will be trapped by the DAO.
606 * @param int $id - Optional id to return
608 * @return array - array reference of all State/Provinces.
611 public static function &stateProvince($id = FALSE, $limit = TRUE) {
612 if (($id && !CRM_Utils_Array
::value($id, self
::$stateProvince)) ||
!self
::$stateProvince ||
!$id) {
613 $whereClause = FALSE;
614 $config = CRM_Core_Config
::singleton();
616 $countryIsoCodes = self
::countryIsoCode();
617 $limitCodes = $config->provinceLimit();
619 foreach ($limitCodes as $code) {
620 $limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
622 if (!empty($limitIds)) {
623 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
626 $whereClause = FALSE;
629 self
::populate(self
::$stateProvince, 'CRM_Core_DAO_StateProvince', TRUE, 'name', 'is_active', $whereClause);
631 // localise the province names if in an non-en_US locale
633 if ($tsLocale != '' and $tsLocale != 'en_US') {
634 $i18n = CRM_Core_I18n
::singleton();
635 $i18n->localizeArray(self
::$stateProvince, array(
636 'context' => 'province',
638 self
::$stateProvince = CRM_Utils_Array
::asort(self
::$stateProvince);
642 if (array_key_exists($id, self
::$stateProvince)) {
643 return self
::$stateProvince[$id];
650 return self
::$stateProvince;
654 * Get all the State/Province abbreviations from the database.
656 * Same as above, except gets the abbreviations instead of the names.
661 * @param int $id - Optional id to return
663 * @return array - array reference of all State/Province abbreviations.
665 public static function &stateProvinceAbbreviation($id = FALSE, $limit = TRUE) {
669 FROM civicrm_state_province
677 return CRM_Core_DAO
::singleValueQuery($query, $params);
680 if (!self
::$stateProvinceAbbreviation ||
!$id) {
682 $whereClause = FALSE;
685 $config = CRM_Core_Config
::singleton();
686 $countryIsoCodes = self
::countryIsoCode();
687 $limitCodes = $config->provinceLimit();
689 foreach ($limitCodes as $code) {
690 $tmpArray = array_keys($countryIsoCodes, $code);
692 if (!empty($tmpArray)) {
693 $limitIds[] = array_shift($tmpArray);
696 if (!empty($limitIds)) {
697 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
700 self
::populate(self
::$stateProvinceAbbreviation, 'CRM_Core_DAO_StateProvince', TRUE, 'abbreviation', 'is_active', $whereClause);
704 if (array_key_exists($id, self
::$stateProvinceAbbreviation)) {
705 return self
::$stateProvinceAbbreviation[$id];
712 return self
::$stateProvinceAbbreviation;
716 * Get all the countries from database.
718 * The static array country is returned, and if it's
719 * called the first time, the <b>Country DAO</b> is used
720 * to get all the countries.
722 * Note: any database errors will be trapped by the DAO.
727 * @param int $id - Optional id to return
729 * @return array - array reference of all countries.
732 public static function country($id = FALSE, $applyLimit = TRUE) {
733 if (($id && !CRM_Utils_Array
::value($id, self
::$country)) ||
!self
::$country ||
!$id) {
735 $config = CRM_Core_Config
::singleton();
736 $limitCodes = array();
739 // limit the country list to the countries specified in CIVICRM_COUNTRY_LIMIT
740 // (ensuring it's a subset of the legal values)
741 // K/P: We need to fix this, i dont think it works with new setting files
742 $limitCodes = $config->countryLimit();
743 if (!is_array($limitCodes)) {
745 $config->countryLimit
=> 1,
749 $limitCodes = array_intersect(self
::countryIsoCode(), $limitCodes);
752 if (count($limitCodes)) {
753 $whereClause = "iso_code IN ('" . implode("', '", $limitCodes) . "')";
759 self
::populate(self
::$country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active', $whereClause);
761 // if default country is set, percolate it to the top
762 if ($config->defaultContactCountry()) {
763 $countryIsoCodes = self
::countryIsoCode();
764 $defaultID = array_search($config->defaultContactCountry(), $countryIsoCodes);
765 if ($defaultID !== FALSE) {
766 $default[$defaultID] = CRM_Utils_Array
::value($defaultID, self
::$country);
767 self
::$country = $default + self
::$country;
771 // localise the country names if in an non-en_US locale
773 if ($tsLocale != '' and $tsLocale != 'en_US') {
774 $i18n = CRM_Core_I18n
::singleton();
775 $i18n->localizeArray(self
::$country, array(
776 'context' => 'country',
778 self
::$country = CRM_Utils_Array
::asort(self
::$country);
782 if (array_key_exists($id, self
::$country)) {
783 return self
::$country[$id];
786 return CRM_Core_DAO
::$_nullObject;
789 return self
::$country;
793 * Get all the country ISO Code abbreviations from the database.
795 * The static array countryIsoCode is returned, and if it's
796 * called the first time, the <b>Country DAO</b> is used
797 * to get all the countries' ISO codes.
799 * Note: any database errors will be trapped by the DAO.
804 * @return array - array reference of all country ISO codes.
807 public static function &countryIsoCode($id = FALSE) {
808 if (!self
::$countryIsoCode) {
809 self
::populate(self
::$countryIsoCode, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
812 if (array_key_exists($id, self
::$countryIsoCode)) {
813 return self
::$countryIsoCode[$id];
816 return CRM_Core_DAO
::$_nullObject;
819 return self
::$countryIsoCode;
823 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
825 * Get all groups from database
827 * The static array group is returned, and if it's
828 * called the first time, the <b>Group DAO</b> is used
829 * to get all the groups.
831 * Note: any database errors will be trapped by the DAO.
833 * @param string $groupType type of group(Access/Mailing)
834 * @param boolen $excludeHidden exclude hidden groups.
839 * @return array - array reference of all groups.
842 public static function &allGroup($groupType = NULL, $excludeHidden = TRUE) {
843 $condition = CRM_Contact_BAO_Group
::groupTypeCondition($groupType, $excludeHidden);
846 self
::$group = array();
849 $groupKey = $groupType ?
$groupType : 'null';
851 if (!isset(self
::$group[$groupKey])) {
852 self
::$group[$groupKey] = NULL;
853 self
::populate(self
::$group[$groupKey], 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition);
855 return self
::$group[$groupKey];
859 * Create or get groups iterator (iterates over nested groups in a
862 * The GroupNesting instance is returned; it's created if this is being
863 * called for the first time
869 * @return mixed - instance of CRM_Contact_BAO_GroupNesting
872 public static function &groupIterator($styledLabels = FALSE) {
873 if (!self
::$groupIterator) {
875 When used as an object, GroupNesting implements Iterator
876 and iterates nested groups in a logical manner for us
878 self
::$groupIterator = new CRM_Contact_BAO_GroupNesting($styledLabels);
880 return self
::$groupIterator;
884 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
886 * Get all permissioned groups from database
888 * The static array group is returned, and if it's
889 * called the first time, the <b>Group DAO</b> is used
890 * to get all the groups.
892 * Note: any database errors will be trapped by the DAO.
894 * @param string $groupType type of group(Access/Mailing)
895 * @param boolen $excludeHidden exclude hidden groups.
900 * @return array - array reference of all groups.
903 public static function group($groupType = NULL, $excludeHidden = TRUE) {
904 return CRM_Core_Permission
::group($groupType, $excludeHidden);
908 * Get all permissioned groups from database
910 * The static array group is returned, and if it's
911 * called the first time, the <b>Group DAO</b> is used
912 * to get all the groups.
914 * Note: any database errors will be trapped by the DAO.
919 * @return array - array reference of all groups.
922 public static function &staticGroup($onlyPublic = FALSE, $groupType = NULL, $excludeHidden = TRUE) {
923 if (!self
::$staticGroup) {
924 $condition = 'saved_search_id = 0 OR saved_search_id IS NULL';
926 $condition .= " AND visibility != 'User and User Admin Only'";
930 $condition .= ' AND ' . CRM_Contact_BAO_Group
::groupTypeCondition($groupType);
933 if ($excludeHidden) {
934 $condition .= ' AND is_hidden != 1 ';
937 self
::populate(self
::$staticGroup, 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition, 'title');
940 return self
::$staticGroup;
944 * Get all Relationship Types from database.
946 * The static array group is returned, and if it's
947 * called the first time, the <b>RelationshipType DAO</b> is used
948 * to get all the relationship types.
950 * Note: any database errors will be trapped by the DAO.
952 * @param string $valueColumnName db column name/label.
953 * @param boolean $reset reset relationship types if true
958 * @return array - array reference of all relationship types.
960 public static function &relationshipType($valueColumnName = 'label', $reset = FALSE) {
961 if (!CRM_Utils_Array
::value($valueColumnName, self
::$relationshipType) ||
$reset) {
962 self
::$relationshipType[$valueColumnName] = array();
964 //now we have name/label columns CRM-3336
965 $column_a_b = "{$valueColumnName}_a_b";
966 $column_b_a = "{$valueColumnName}_b_a";
968 $relationshipTypeDAO = new CRM_Contact_DAO_RelationshipType();
969 $relationshipTypeDAO->selectAdd();
970 $relationshipTypeDAO->selectAdd("id, {$column_a_b}, {$column_b_a}, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b");
971 $relationshipTypeDAO->is_active
= 1;
972 $relationshipTypeDAO->find();
973 while ($relationshipTypeDAO->fetch()) {
975 self
::$relationshipType[$valueColumnName][$relationshipTypeDAO->id
] = array(
976 $column_a_b => $relationshipTypeDAO->$column_a_b,
977 $column_b_a => $relationshipTypeDAO->$column_b_a,
978 'contact_type_a' => "$relationshipTypeDAO->contact_type_a",
979 'contact_type_b' => "$relationshipTypeDAO->contact_type_b",
980 'contact_sub_type_a' => "$relationshipTypeDAO->contact_sub_type_a",
981 'contact_sub_type_b' => "$relationshipTypeDAO->contact_sub_type_b",
986 return self
::$relationshipType[$valueColumnName];
990 * get all the ISO 4217 currency codes
992 * so far, we use this for validation only, so there's no point of putting this into the database
996 * @return array - array reference of all currency codes
999 public static function ¤cyCode() {
1000 if (!self
::$currencyCode) {
1001 self
::$currencyCode = array(
1271 return self
::$currencyCode;
1275 * Get all the County from database.
1277 * The static array county is returned, and if it's
1278 * called the first time, the <b>County DAO</b> is used
1279 * to get all the Counties.
1281 * Note: any database errors will be trapped by the DAO.
1286 * @param int $id - Optional id to return
1288 * @return array - array reference of all Counties
1291 public static function &county($id = FALSE) {
1292 if (!self
::$county) {
1294 $config = CRM_Core_Config
::singleton();
1295 // order by id so users who populate civicrm_county can have more control over sort by the order they load the counties
1296 self
::populate(self
::$county, 'CRM_Core_DAO_County', TRUE, 'name', NULL, NULL, 'id');
1299 if (array_key_exists($id, self
::$county)) {
1300 return self
::$county[$id];
1303 return CRM_Core_DAO
::$_nullObject;
1306 return self
::$county;
1310 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1311 * Get all active payment processors
1313 * The static array paymentProcessor is returned
1318 * @param boolean $all - get payment processors - default is to get only active ones.
1319 * @param boolean $test - get test payment processors
1321 * @return array - array of all payment processors
1324 public static function &paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
1325 $condition = "is_test = ";
1326 $condition .= ($test) ?
'1' : '0';
1328 if ($additionalCond) {
1329 $condition .= " AND ( $additionalCond ) ";
1332 // CRM-7178. Make sure we only include payment processors valid in ths
1334 $condition .= " AND domain_id = " . CRM_Core_Config
::domainID();
1336 $cacheKey = $condition . '_' . (int) $all;
1337 if (!isset(self
::$paymentProcessor[$cacheKey])) {
1338 self
::populate(self
::$paymentProcessor[$cacheKey], 'CRM_Financial_DAO_PaymentProcessor', $all, 'name', 'is_active', $condition, 'is_default desc, name');
1341 return self
::$paymentProcessor[$cacheKey];
1345 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1347 * The static array paymentProcessorType is returned
1352 * @param boolean $all - get payment processors - default is to get only active ones.
1354 * @return array - array of all payment processor types
1357 public static function &paymentProcessorType($all = FALSE, $id = NULL, $return = 'title') {
1358 $cacheKey = $id . '_' .$return;
1359 if (empty(self
::$paymentProcessorType[$cacheKey])) {
1360 self
::populate(self
::$paymentProcessorType[$cacheKey], 'CRM_Financial_DAO_PaymentProcessorType', $all, $return, 'is_active', NULL, "is_default, $return", 'id');
1362 if ($id && CRM_Utils_Array
::value($id, self
::$paymentProcessorType[$cacheKey])) {
1363 return self
::$paymentProcessorType[$cacheKey][$id];
1365 return self
::$paymentProcessorType[$cacheKey];
1369 * Get all the World Regions from Database
1373 * @return array - array reference of all World Regions
1376 public static function &worldRegion($id = FALSE) {
1377 if (!self
::$worldRegions) {
1378 self
::populate(self
::$worldRegions, 'CRM_Core_DAO_Worldregion', TRUE, 'name', NULL, NULL, 'id');
1382 if (array_key_exists($id, self
::$worldRegions)) {
1383 return self
::$worldRegions[$id];
1386 return CRM_Core_DAO
::$_nullObject;
1390 return self
::$worldRegions;
1394 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1396 * Get all Activity Statuses.
1398 * The static array activityStatus is returned
1403 * @return array - array reference of all activity statuses
1405 public static function &activityStatus($column = 'label') {
1406 if (NULL === self
::$activityStatus) {
1407 self
::$activityStatus = array();
1409 if (!array_key_exists($column, self
::$activityStatus)) {
1410 self
::$activityStatus[$column] = array();
1412 self
::$activityStatus[$column] = CRM_Core_OptionGroup
::values('activity_status', FALSE, FALSE, FALSE, NULL, $column);
1415 return self
::$activityStatus[$column];
1419 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1421 * Get all Visibility levels.
1423 * The static array visibility is returned
1428 * @return array - array reference of all Visibility levels.
1431 public static function &visibility($column = 'label') {
1432 if (!isset(self
::$visibility)) {
1433 self
::$visibility = array( );
1436 if (!isset(self
::$visibility[$column])) {
1437 self
::$visibility[$column] = CRM_Core_OptionGroup
::values('visibility', FALSE, FALSE, FALSE, NULL, $column);
1440 return self
::$visibility[$column];
1443 public static function &stateProvinceForCountry($countryID, $field = 'name') {
1444 static $_cache = NULL;
1446 $cacheKey = "{$countryID}_{$field}";
1451 if (!empty($_cache[$cacheKey])) {
1452 return $_cache[$cacheKey];
1456 SELECT civicrm_state_province.{$field} name, civicrm_state_province.id id
1457 FROM civicrm_state_province
1458 WHERE country_id = %1
1467 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1470 while ($dao->fetch()) {
1471 $result[$dao->id
] = $dao->name
;
1474 // localise the stateProvince names if in an non-en_US locale
1475 $config = CRM_Core_Config
::singleton();
1477 if ($tsLocale != '' and $tsLocale != 'en_US') {
1478 $i18n = CRM_Core_I18n
::singleton();
1479 $i18n->localizeArray($result, array(
1480 'context' => 'province',
1482 $result = CRM_Utils_Array
::asort($result);
1485 $_cache[$cacheKey] = $result;
1487 CRM_Utils_Hook
::buildStateProvinceForCountry($countryID, $result);
1492 public static function &countyForState($stateID) {
1493 if (is_array($stateID)) {
1494 $states = implode(", ", $stateID);
1496 SELECT civicrm_county.name name, civicrm_county.id id, civicrm_state_province.abbreviation abbreviation
1498 LEFT JOIN civicrm_state_province ON civicrm_county.state_province_id = civicrm_state_province.id
1499 WHERE civicrm_county.state_province_id in ( $states )
1500 ORDER BY civicrm_state_province.abbreviation, civicrm_county.name";
1502 $dao = CRM_Core_DAO
::executeQuery($query);
1505 while ($dao->fetch()) {
1506 $result[$dao->id
] = $dao->abbreviation
. ': ' . $dao->name
;
1511 static $_cache = NULL;
1513 $cacheKey = "{$stateID}_name";
1518 if (!empty($_cache[$cacheKey])) {
1519 return $_cache[$cacheKey];
1523 SELECT civicrm_county.name name, civicrm_county.id id
1525 WHERE state_province_id = %1
1534 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1537 while ($dao->fetch()) {
1538 $result[$dao->id
] = $dao->name
;
1546 * Given a state ID return the country ID, this allows
1547 * us to populate forms and values for downstream code
1549 * @param $stateID int
1551 * @return int the country id that the state belongs to
1555 static function countryIDForStateID($stateID) {
1556 if (empty($stateID)) {
1557 return CRM_Core_DAO
::$_nullObject;
1562 FROM civicrm_state_province
1565 $params = array(1 => array($stateID, 'Integer'));
1567 return CRM_Core_DAO
::singleValueQuery($query, $params);
1571 * Get all types of Greetings.
1573 * The static array of greeting is returned
1578 * @param $filter - get All Email Greetings - default is to get only active ones.
1580 * @return array - array reference of all greetings.
1583 public static function greeting($filter, $columnName = 'label') {
1584 $index = $filter['greeting_type'] . '_' . $columnName;
1586 // also add contactType to the array
1587 $contactType = CRM_Utils_Array
::value('contact_type', $filter);
1589 $index .= '_' . $contactType;
1592 if (NULL === self
::$greeting) {
1593 self
::$greeting = array();
1596 if (!CRM_Utils_Array
::value($index, self
::$greeting)) {
1597 $filterCondition = NULL;
1599 $filterVal = 'v.filter =';
1600 switch ($contactType) {
1609 case 'Organization':
1613 $filterCondition .= "AND (v.filter = 0 OR {$filterVal}) ";
1616 self
::$greeting[$index] = CRM_Core_OptionGroup
::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName);
1619 return self
::$greeting[$index];
1623 * Construct array of default greeting values for contact type
1628 * @return array - array reference of default greetings.
1631 public static function &greetingDefaults() {
1632 if (!self
::$greetingDefaults) {
1633 $defaultGreetings = array();
1634 $contactTypes = self
::get('CRM_Contact_DAO_Contact', 'contact_type', array('keyColumn' => 'id', 'labelColumn' => 'name'));
1636 foreach ($contactTypes as $filter => $contactType) {
1637 $filterCondition = " AND (v.filter = 0 OR v.filter = $filter) AND v.is_default = 1 ";
1639 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
1640 $tokenVal = CRM_Core_OptionGroup
::values($greeting, NULL, NULL, NULL, $filterCondition, 'label');
1641 $defaultGreetings[$contactType][$greeting] = $tokenVal;
1645 self
::$greetingDefaults = $defaultGreetings;
1648 return self
::$greetingDefaults;
1652 * Get all extensions
1654 * The static array extensions
1656 * FIXME: This is called by civix but not by any core code. We
1657 * should provide an API call which civix can use instead.
1662 * @return array - array($fullyQualifiedName => $label) list of extensions
1664 public static function &getExtensions() {
1665 if (!self
::$extensions) {
1666 self
::$extensions = array();
1668 SELECT full_name, label
1669 FROM civicrm_extension
1672 $dao = CRM_Core_DAO
::executeQuery($sql);
1673 while ($dao->fetch()) {
1674 self
::$extensions[$dao->full_name
] = $dao->label
;
1678 return self
::$extensions;
1682 * Get all options values
1684 * The static array option values is returned
1689 * @param boolean $optionGroupName - get All Option Group values- default is to get only active ones.
1691 * @return array - array reference of all Option Group Name
1694 public static function accountOptionValues($optionGroupName, $id = null, $condition = null) {
1695 $cacheKey = $optionGroupName . '_' . $condition;
1696 if (empty(self
::$accountOptionValues[$cacheKey])) {
1697 self
::$accountOptionValues[$cacheKey] = CRM_Core_OptionGroup
::values($optionGroupName, false, false, false, $condition);
1700 return CRM_Utils_Array
::value($id, self
::$accountOptionValues[$cacheKey]);
1703 return self
::$accountOptionValues[$cacheKey];
1707 * Fetch the list of active extensions of type 'module'
1709 * @param $fresh bool whether to forcibly reload extensions list from canonical store
1713 * @return array - array(array('prefix' => $, 'file' => $))
1715 public static function getModuleExtensions($fresh = FALSE) {
1716 return CRM_Extension_System
::singleton()->getMapper()->getActiveModuleFiles($fresh);