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 * Low-level option getter, rarely accessed directly.
200 * NOTE: Rather than calling this function directly use CRM_*_BAO_*::buildOptions()
202 * @param String $daoName
203 * @param String $fieldName
204 * @param Array $params
205 * - name string name of the option group
206 * - flip boolean results are return in id => label format if false
207 * if true, the results are reversed
208 * - grouping boolean if true, return the value in 'grouping' column (currently unsupported for tables other than option_value)
209 * - localize boolean if true, localize the results before returning
210 * - condition string|array add condition(s) to the sql query
211 * - keyColumn string the column to use for 'id'
212 * - labelColumn string the column to use for 'label'
213 * - orderColumn string the column to use for sorting, defaults to 'weight' column if one exists, else defaults to labelColumn
214 * - onlyActive boolean return only the action option values
215 * - fresh boolean ignore cache entries and go back to DB
217 * @return Array on success, FALSE on error.
221 public static function get($daoName, $fieldName, $params = array()) {
222 $flip = !empty($params['flip']);
224 // Custom fields are not in the schema
225 if (strpos($fieldName, 'custom') === 0) {
226 $dao = new CRM_Core_DAO_CustomField
;
227 $dao->id
= (int) substr($fieldName, 7);
229 $customField = (array) $dao;
232 CRM_Core_BAO_CustomField
::buildOption($customField, $output);
233 return $flip ?
array_flip($output) : $output;
236 // Core field: load schema
238 $fields = $dao->fields();
239 $fieldKeys = $dao->fieldKeys();
240 $fieldKey = $fieldKeys[$fieldName];
242 if (empty($fields[$fieldKey])) {
245 $fieldSpec = $fields[$fieldKey];
247 // If the field is an enum, explode the enum definition and return the array.
248 if (isset($fieldSpec['enumValues'])) {
249 // use of a space after the comma is inconsistent in xml
250 $enumStr = str_replace(', ', ',', $fieldSpec['enumValues']);
251 $output = explode(',', $enumStr);
252 return $flip ?
array_flip($output) : $output;
255 elseif (!empty($fieldSpec['pseudoconstant'])) {
256 $pseudoconstant = $fieldSpec['pseudoconstant'];
257 // Merge params with defaults
261 'condition' => CRM_Utils_Array
::value('condition', $pseudoconstant),
262 'keyColumn' => CRM_Utils_Array
::value('keyColumn', $pseudoconstant),
263 'labelColumn' => CRM_Utils_Array
::value('labelColumn', $pseudoconstant),
264 'onlyActive' => TRUE,
268 // Fetch option group from option_value table
269 if(!empty($pseudoconstant['optionGroupName'])) {
270 // Call our generic fn for retrieving from the option_value table
271 return CRM_Core_OptionGroup
::values(
272 $pseudoconstant['optionGroupName'],
276 $params['condition'],
277 $params['labelColumn'] ?
$params['labelColumn'] : 'label',
278 $params['onlyActive'],
280 $params['keyColumn'] ?
$params['keyColumn'] : 'value'
284 // Fetch options from other tables
285 if (!empty($pseudoconstant['table'])) {
286 // Normalize params so the serialized cache string will be consistent.
287 CRM_Utils_Array
::remove($params, 'flip', 'fresh');
289 $cacheKey = $daoName . $fieldName . serialize($params);
291 // Retrieve cached options
292 if (isset(self
::$cache[$cacheKey]) && empty($params['fresh'])) {
293 $output = self
::$cache[$cacheKey];
296 $daoName = CRM_Core_AllCoreTables
::getClassForTable($pseudoconstant['table']);
297 if (!class_exists($daoName)) {
300 // Get list of fields for the option table
302 $availableFields = array_keys($dao->fieldKeys());
303 if (in_array('is_active', $availableFields)) {
304 $wheres[] = 'is_active = 1';
308 $select = "SELECT %1 AS id, %2 AS label";
311 $order = "ORDER BY %2";
312 // Condition param can be passed as an sql clause string or an array of clauses
313 if (!empty($params['condition'])) {
314 $wheres[] = implode(' AND ', (array) $params['condition']);
316 // onlyActive param will automatically filter on common flags
317 if (!empty($params['onlyActive'])) {
318 foreach (array('is_active' => 1, 'is_deleted' => 0, 'is_test' => 0) as $flag => $val) {
319 if (in_array($flag, $availableFields)) {
320 $wheres[] = "$flag = $val";
324 // Filter domain specific options
325 if (in_array('domain_id', $availableFields)) {
326 $wheres[] = 'domain_id = ' . CRM_Core_Config
::domainID();
328 $queryParams = array(
329 1 => array($params['keyColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
330 2 => array($params['labelColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
331 3 => array($pseudoconstant['table'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
333 // Add orderColumn param
334 if (!empty($params['orderColumn'])) {
335 $queryParams[4] = array($params['orderColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
);
336 $order = "ORDER BY %4";
338 // Support no sorting if $params[orderColumn] is FALSE
339 elseif (isset($params['orderColumn']) && $params['orderColumn'] === FALSE) {
342 // Default to 'weight' if that column exists
343 elseif (in_array('weight', $availableFields)) {
344 $order = "ORDER BY weight";
348 $query = "$select $from";
350 $query .= " WHERE " . implode($wheres, ' AND ');
352 $query .= ' ' . $order;
353 $dao = CRM_Core_DAO
::executeQuery($query, $queryParams);
354 while ($dao->fetch()) {
355 $output[$dao->id
] = $dao->label
;
358 if (!empty($params['localize'])) {
359 $i18n = CRM_Core_I18n
::singleton();
360 $i18n->localizeArray($output);
361 // Maintain sort by label
362 if ($order == "ORDER BY %2") {
363 CRM_Utils_Array
::asort($output);
366 self
::$cache[$cacheKey] = $output;
368 return $flip ?
array_flip($output) : $output;
371 // If we're still here, it's an error. Return FALSE.
376 * Fetch the label (or other value) for a field given its key
378 * @param String $daoName
379 * @param String $fieldName
380 * @param String|Int $key
381 * @param Array $params will be passed into self::get
385 function getValue($daoName, $fieldName, $key, $params = array()) {
386 $values = self
::get($daoName, $fieldName, $params);
387 return CRM_Utils_Array
::value($key, $values);
391 * Fetch the key for a field option given its label/name
393 * @param String $daoName
394 * @param String $fieldName
395 * @param String|Int $value
396 * @param Array $params will be passed into self::get
400 function getKey($daoName, $fieldName, $value, $params = array()) {
401 $values = self
::get($daoName, $fieldName, $params);
402 return CRM_Utils_Array
::key($value, $values);
406 * DEPRECATED generic populate method
407 * All pseudoconstant functions that use this method are also deprecated.
409 * The static array $var is populated from the db
410 * using the <b>$name DAO</b>.
412 * Note: any database errors will be trapped by the DAO.
414 * @param array $var the associative array we will fill
415 * @param string $name the name of the DAO
416 * @param boolean $all get all objects. default is to get only active ones.
417 * @param string $retrieve the field that we are interested in (normally name, differs in some objects)
418 * @param string $filter the field that we want to filter the result set with
419 * @param string $condition the condition that gets passed to the final query as the WHERE clause
425 public static function populate(
430 $filter = 'is_active',
436 $cacheKey = "CRM_PC_{$name}_{$all}_{$key}_{$retrieve}_{$filter}_{$condition}_{$orderby}";
437 $cache = CRM_Utils_Cache
::singleton();
438 $var = $cache->get($cacheKey);
439 if ($var && empty($force)) {
443 $object = new $name ( );
445 $object->selectAdd();
446 $object->selectAdd("$key, $retrieve");
448 $object->whereAdd($condition);
452 $object->orderBy($retrieve);
455 $object->orderBy($orderby);
459 $object->$filter = 1;
464 while ($object->fetch()) {
465 $var[$object->$key] = $object->$retrieve;
468 $cache->set($cacheKey, $var);
472 * Flush given pseudoconstant so it can be reread from db
473 * nex time it's requested.
478 * @param boolean $name pseudoconstant to be flushed
481 public static function flush($name = 'cache') {
482 if (property_exists(self
, $name)) {
488 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
490 * Get all Activty types.
492 * The static array activityType is returned
494 * @param boolean $all - get All Activity types - default is to get only active ones.
499 * @return array - array reference of all activity types.
501 public static function &activityType() {
502 $args = func_get_args();
503 $all = CRM_Utils_Array
::value(0, $args, TRUE);
504 $includeCaseActivities = CRM_Utils_Array
::value(1, $args, FALSE);
505 $reset = CRM_Utils_Array
::value(2, $args, FALSE);
506 $returnColumn = CRM_Utils_Array
::value(3, $args, 'label');
507 $includeCampaignActivities = CRM_Utils_Array
::value(4, $args, FALSE);
508 $onlyComponentActivities = CRM_Utils_Array
::value(5, $args, FALSE);
509 $index = (int) $all . '_' . $returnColumn . '_' . (int) $includeCaseActivities;
510 $index .= '_' . (int) $includeCampaignActivities;
511 $index .= '_' . (int) $onlyComponentActivities;
513 if (NULL === self
::$activityType) {
514 self
::$activityType = array();
517 if (!isset(self
::$activityType[$index]) ||
$reset) {
520 $condition = 'AND filter = 0';
522 $componentClause = " v.component_id IS NULL";
523 if ($onlyComponentActivities) {
524 $componentClause = " v.component_id IS NOT NULL";
527 $componentIds = array();
528 $compInfo = CRM_Core_Component
::getEnabledComponents();
530 // build filter for listing activity types only if their
531 // respective components are enabled
532 foreach ($compInfo as $compName => $compObj) {
533 if ($compName == 'CiviCase') {
534 if ($includeCaseActivities) {
535 $componentIds[] = $compObj->componentID
;
538 elseif ($compName == 'CiviCampaign') {
539 if ($includeCampaignActivities) {
540 $componentIds[] = $compObj->componentID
;
544 $componentIds[] = $compObj->componentID
;
548 if (count($componentIds)) {
549 $componentIds = implode(',', $componentIds);
550 $componentClause = " ($componentClause OR v.component_id IN ($componentIds))";
551 if ($onlyComponentActivities) {
552 $componentClause = " ( v.component_id IN ($componentIds ) )";
555 $condition = $condition . ' AND ' . $componentClause;
557 self
::$activityType[$index] = CRM_Core_OptionGroup
::values('activity_type', FALSE, FALSE, FALSE, $condition, $returnColumn);
559 return self
::$activityType[$index];
563 * Get all the State/Province from database.
565 * The static array stateProvince is returned, and if it's
566 * called the first time, the <b>State Province DAO</b> is used
567 * to get all the States.
569 * Note: any database errors will be trapped by the DAO.
574 * @param int $id - Optional id to return
576 * @return array - array reference of all State/Provinces.
579 public static function &stateProvince($id = FALSE, $limit = TRUE) {
580 if (($id && !CRM_Utils_Array
::value($id, self
::$stateProvince)) ||
!self
::$stateProvince ||
!$id) {
581 $whereClause = FALSE;
582 $config = CRM_Core_Config
::singleton();
584 $countryIsoCodes = self
::countryIsoCode();
585 $limitCodes = $config->provinceLimit();
587 foreach ($limitCodes as $code) {
588 $limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
590 if (!empty($limitIds)) {
591 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
594 $whereClause = FALSE;
597 self
::populate(self
::$stateProvince, 'CRM_Core_DAO_StateProvince', TRUE, 'name', 'is_active', $whereClause);
599 // localise the province names if in an non-en_US locale
601 if ($tsLocale != '' and $tsLocale != 'en_US') {
602 $i18n = CRM_Core_I18n
::singleton();
603 $i18n->localizeArray(self
::$stateProvince, array(
604 'context' => 'province',
606 self
::$stateProvince = CRM_Utils_Array
::asort(self
::$stateProvince);
610 if (array_key_exists($id, self
::$stateProvince)) {
611 return self
::$stateProvince[$id];
618 return self
::$stateProvince;
622 * Get all the State/Province abbreviations from the database.
624 * Same as above, except gets the abbreviations instead of the names.
629 * @param int $id - Optional id to return
631 * @return array - array reference of all State/Province abbreviations.
633 public static function &stateProvinceAbbreviation($id = FALSE, $limit = TRUE) {
637 FROM civicrm_state_province
645 return CRM_Core_DAO
::singleValueQuery($query, $params);
648 if (!self
::$stateProvinceAbbreviation ||
!$id) {
650 $whereClause = FALSE;
653 $config = CRM_Core_Config
::singleton();
654 $countryIsoCodes = self
::countryIsoCode();
655 $limitCodes = $config->provinceLimit();
657 foreach ($limitCodes as $code) {
658 $tmpArray = array_keys($countryIsoCodes, $code);
660 if (!empty($tmpArray)) {
661 $limitIds[] = array_shift($tmpArray);
664 if (!empty($limitIds)) {
665 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
668 self
::populate(self
::$stateProvinceAbbreviation, 'CRM_Core_DAO_StateProvince', TRUE, 'abbreviation', 'is_active', $whereClause);
672 if (array_key_exists($id, self
::$stateProvinceAbbreviation)) {
673 return self
::$stateProvinceAbbreviation[$id];
680 return self
::$stateProvinceAbbreviation;
684 * Get all the countries from database.
686 * The static array country is returned, and if it's
687 * called the first time, the <b>Country DAO</b> is used
688 * to get all the countries.
690 * Note: any database errors will be trapped by the DAO.
695 * @param int $id - Optional id to return
697 * @return array - array reference of all countries.
700 public static function country($id = FALSE, $applyLimit = TRUE) {
701 if (($id && !CRM_Utils_Array
::value($id, self
::$country)) ||
!self
::$country ||
!$id) {
703 $config = CRM_Core_Config
::singleton();
704 $limitCodes = array();
707 // limit the country list to the countries specified in CIVICRM_COUNTRY_LIMIT
708 // (ensuring it's a subset of the legal values)
709 // K/P: We need to fix this, i dont think it works with new setting files
710 $limitCodes = $config->countryLimit();
711 if (!is_array($limitCodes)) {
713 $config->countryLimit
=> 1,
717 $limitCodes = array_intersect(self
::countryIsoCode(), $limitCodes);
720 if (count($limitCodes)) {
721 $whereClause = "iso_code IN ('" . implode("', '", $limitCodes) . "')";
727 self
::populate(self
::$country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active', $whereClause);
729 // if default country is set, percolate it to the top
730 if ($config->defaultContactCountry()) {
731 $countryIsoCodes = self
::countryIsoCode();
732 $defaultID = array_search($config->defaultContactCountry(), $countryIsoCodes);
733 if ($defaultID !== FALSE) {
734 $default[$defaultID] = CRM_Utils_Array
::value($defaultID, self
::$country);
735 self
::$country = $default + self
::$country;
739 // localise the country names if in an non-en_US locale
741 if ($tsLocale != '' and $tsLocale != 'en_US') {
742 $i18n = CRM_Core_I18n
::singleton();
743 $i18n->localizeArray(self
::$country, array(
744 'context' => 'country',
746 self
::$country = CRM_Utils_Array
::asort(self
::$country);
750 if (array_key_exists($id, self
::$country)) {
751 return self
::$country[$id];
754 return CRM_Core_DAO
::$_nullObject;
757 return self
::$country;
761 * Get all the country ISO Code abbreviations from the database.
763 * The static array countryIsoCode is returned, and if it's
764 * called the first time, the <b>Country DAO</b> is used
765 * to get all the countries' ISO codes.
767 * Note: any database errors will be trapped by the DAO.
772 * @return array - array reference of all country ISO codes.
775 public static function &countryIsoCode($id = FALSE) {
776 if (!self
::$countryIsoCode) {
777 self
::populate(self
::$countryIsoCode, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
780 if (array_key_exists($id, self
::$countryIsoCode)) {
781 return self
::$countryIsoCode[$id];
784 return CRM_Core_DAO
::$_nullObject;
787 return self
::$countryIsoCode;
791 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
793 * Get all groups from database
795 * The static array group is returned, and if it's
796 * called the first time, the <b>Group DAO</b> is used
797 * to get all the groups.
799 * Note: any database errors will be trapped by the DAO.
801 * @param string $groupType type of group(Access/Mailing)
802 * @param boolen $excludeHidden exclude hidden groups.
807 * @return array - array reference of all groups.
810 public static function &allGroup($groupType = NULL, $excludeHidden = TRUE) {
811 $condition = CRM_Contact_BAO_Group
::groupTypeCondition($groupType, $excludeHidden);
814 self
::$group = array();
817 $groupKey = $groupType ?
$groupType : 'null';
819 if (!isset(self
::$group[$groupKey])) {
820 self
::$group[$groupKey] = NULL;
821 self
::populate(self
::$group[$groupKey], 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition);
823 return self
::$group[$groupKey];
827 * Create or get groups iterator (iterates over nested groups in a
830 * The GroupNesting instance is returned; it's created if this is being
831 * called for the first time
837 * @return mixed - instance of CRM_Contact_BAO_GroupNesting
840 public static function &groupIterator($styledLabels = FALSE) {
841 if (!self
::$groupIterator) {
843 When used as an object, GroupNesting implements Iterator
844 and iterates nested groups in a logical manner for us
846 self
::$groupIterator = new CRM_Contact_BAO_GroupNesting($styledLabels);
848 return self
::$groupIterator;
852 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
854 * Get all permissioned groups from database
856 * The static array group is returned, and if it's
857 * called the first time, the <b>Group DAO</b> is used
858 * to get all the groups.
860 * Note: any database errors will be trapped by the DAO.
862 * @param string $groupType type of group(Access/Mailing)
863 * @param boolen $excludeHidden exclude hidden groups.
868 * @return array - array reference of all groups.
871 public static function group($groupType = NULL, $excludeHidden = TRUE) {
872 return CRM_Core_Permission
::group($groupType, $excludeHidden);
876 * Get all permissioned groups from database
878 * The static array group is returned, and if it's
879 * called the first time, the <b>Group DAO</b> is used
880 * to get all the groups.
882 * Note: any database errors will be trapped by the DAO.
887 * @return array - array reference of all groups.
890 public static function &staticGroup($onlyPublic = FALSE, $groupType = NULL, $excludeHidden = TRUE) {
891 if (!self
::$staticGroup) {
892 $condition = 'saved_search_id = 0 OR saved_search_id IS NULL';
894 $condition .= " AND visibility != 'User and User Admin Only'";
898 $condition .= ' AND ' . CRM_Contact_BAO_Group
::groupTypeCondition($groupType);
901 if ($excludeHidden) {
902 $condition .= ' AND is_hidden != 1 ';
905 self
::populate(self
::$staticGroup, 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition, 'title');
908 return self
::$staticGroup;
912 * Get all Relationship Types from database.
914 * The static array group is returned, and if it's
915 * called the first time, the <b>RelationshipType DAO</b> is used
916 * to get all the relationship types.
918 * Note: any database errors will be trapped by the DAO.
920 * @param string $valueColumnName db column name/label.
921 * @param boolean $reset reset relationship types if true
926 * @return array - array reference of all relationship types.
928 public static function &relationshipType($valueColumnName = 'label', $reset = FALSE) {
929 if (!CRM_Utils_Array
::value($valueColumnName, self
::$relationshipType) ||
$reset) {
930 self
::$relationshipType[$valueColumnName] = array();
932 //now we have name/label columns CRM-3336
933 $column_a_b = "{$valueColumnName}_a_b";
934 $column_b_a = "{$valueColumnName}_b_a";
936 $relationshipTypeDAO = new CRM_Contact_DAO_RelationshipType();
937 $relationshipTypeDAO->selectAdd();
938 $relationshipTypeDAO->selectAdd("id, {$column_a_b}, {$column_b_a}, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b");
939 $relationshipTypeDAO->is_active
= 1;
940 $relationshipTypeDAO->find();
941 while ($relationshipTypeDAO->fetch()) {
943 self
::$relationshipType[$valueColumnName][$relationshipTypeDAO->id
] = array(
944 $column_a_b => $relationshipTypeDAO->$column_a_b,
945 $column_b_a => $relationshipTypeDAO->$column_b_a,
946 'contact_type_a' => "$relationshipTypeDAO->contact_type_a",
947 'contact_type_b' => "$relationshipTypeDAO->contact_type_b",
948 'contact_sub_type_a' => "$relationshipTypeDAO->contact_sub_type_a",
949 'contact_sub_type_b' => "$relationshipTypeDAO->contact_sub_type_b",
954 return self
::$relationshipType[$valueColumnName];
958 * get all the ISO 4217 currency codes
960 * so far, we use this for validation only, so there's no point of putting this into the database
964 * @return array - array reference of all currency codes
967 public static function ¤cyCode() {
968 if (!self
::$currencyCode) {
969 self
::$currencyCode = array(
1239 return self
::$currencyCode;
1243 * Get all the County from database.
1245 * The static array county is returned, and if it's
1246 * called the first time, the <b>County DAO</b> is used
1247 * to get all the Counties.
1249 * Note: any database errors will be trapped by the DAO.
1254 * @param int $id - Optional id to return
1256 * @return array - array reference of all Counties
1259 public static function &county($id = FALSE) {
1260 if (!self
::$county) {
1262 $config = CRM_Core_Config
::singleton();
1263 // order by id so users who populate civicrm_county can have more control over sort by the order they load the counties
1264 self
::populate(self
::$county, 'CRM_Core_DAO_County', TRUE, 'name', NULL, NULL, 'id');
1267 if (array_key_exists($id, self
::$county)) {
1268 return self
::$county[$id];
1271 return CRM_Core_DAO
::$_nullObject;
1274 return self
::$county;
1278 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1279 * Get all active payment processors
1281 * The static array paymentProcessor is returned
1286 * @param boolean $all - get payment processors - default is to get only active ones.
1287 * @param boolean $test - get test payment processors
1289 * @return array - array of all payment processors
1292 public static function &paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
1293 $condition = "is_test = ";
1294 $condition .= ($test) ?
'1' : '0';
1296 if ($additionalCond) {
1297 $condition .= " AND ( $additionalCond ) ";
1300 // CRM-7178. Make sure we only include payment processors valid in ths
1302 $condition .= " AND domain_id = " . CRM_Core_Config
::domainID();
1304 $cacheKey = $condition . '_' . (int) $all;
1305 if (!isset(self
::$paymentProcessor[$cacheKey])) {
1306 self
::populate(self
::$paymentProcessor[$cacheKey], 'CRM_Financial_DAO_PaymentProcessor', $all, 'name', 'is_active', $condition, 'is_default desc, name');
1309 return self
::$paymentProcessor[$cacheKey];
1313 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1315 * The static array paymentProcessorType is returned
1320 * @param boolean $all - get payment processors - default is to get only active ones.
1322 * @return array - array of all payment processor types
1325 public static function &paymentProcessorType($all = FALSE, $id = NULL, $return = 'title') {
1326 $cacheKey = $id . '_' .$return;
1327 if (empty(self
::$paymentProcessorType[$cacheKey])) {
1328 self
::populate(self
::$paymentProcessorType[$cacheKey], 'CRM_Financial_DAO_PaymentProcessorType', $all, $return, 'is_active', NULL, "is_default, $return", 'id');
1330 if ($id && CRM_Utils_Array
::value($id, self
::$paymentProcessorType[$cacheKey])) {
1331 return self
::$paymentProcessorType[$cacheKey][$id];
1333 return self
::$paymentProcessorType[$cacheKey];
1337 * Get all the World Regions from Database
1341 * @return array - array reference of all World Regions
1344 public static function &worldRegion($id = FALSE) {
1345 if (!self
::$worldRegions) {
1346 self
::populate(self
::$worldRegions, 'CRM_Core_DAO_Worldregion', TRUE, 'name', NULL, NULL, 'id');
1350 if (array_key_exists($id, self
::$worldRegions)) {
1351 return self
::$worldRegions[$id];
1354 return CRM_Core_DAO
::$_nullObject;
1358 return self
::$worldRegions;
1362 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1364 * Get all Activity Statuses.
1366 * The static array activityStatus is returned
1371 * @return array - array reference of all activity statuses
1373 public static function &activityStatus($column = 'label') {
1374 if (NULL === self
::$activityStatus) {
1375 self
::$activityStatus = array();
1377 if (!array_key_exists($column, self
::$activityStatus)) {
1378 self
::$activityStatus[$column] = array();
1380 self
::$activityStatus[$column] = CRM_Core_OptionGroup
::values('activity_status', FALSE, FALSE, FALSE, NULL, $column);
1383 return self
::$activityStatus[$column];
1387 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1389 * Get all Visibility levels.
1391 * The static array visibility is returned
1396 * @return array - array reference of all Visibility levels.
1399 public static function &visibility($column = 'label') {
1400 if (!isset(self
::$visibility)) {
1401 self
::$visibility = array( );
1404 if (!isset(self
::$visibility[$column])) {
1405 self
::$visibility[$column] = CRM_Core_OptionGroup
::values('visibility', FALSE, FALSE, FALSE, NULL, $column);
1408 return self
::$visibility[$column];
1411 public static function &stateProvinceForCountry($countryID, $field = 'name') {
1412 static $_cache = NULL;
1414 $cacheKey = "{$countryID}_{$field}";
1419 if (!empty($_cache[$cacheKey])) {
1420 return $_cache[$cacheKey];
1424 SELECT civicrm_state_province.{$field} name, civicrm_state_province.id id
1425 FROM civicrm_state_province
1426 WHERE country_id = %1
1435 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1438 while ($dao->fetch()) {
1439 $result[$dao->id
] = $dao->name
;
1442 // localise the stateProvince names if in an non-en_US locale
1443 $config = CRM_Core_Config
::singleton();
1445 if ($tsLocale != '' and $tsLocale != 'en_US') {
1446 $i18n = CRM_Core_I18n
::singleton();
1447 $i18n->localizeArray($result, array(
1448 'context' => 'province',
1450 $result = CRM_Utils_Array
::asort($result);
1453 $_cache[$cacheKey] = $result;
1455 CRM_Utils_Hook
::buildStateProvinceForCountry($countryID, $result);
1460 public static function &countyForState($stateID) {
1461 if (is_array($stateID)) {
1462 $states = implode(", ", $stateID);
1464 SELECT civicrm_county.name name, civicrm_county.id id, civicrm_state_province.abbreviation abbreviation
1466 LEFT JOIN civicrm_state_province ON civicrm_county.state_province_id = civicrm_state_province.id
1467 WHERE civicrm_county.state_province_id in ( $states )
1468 ORDER BY civicrm_state_province.abbreviation, civicrm_county.name";
1470 $dao = CRM_Core_DAO
::executeQuery($query);
1473 while ($dao->fetch()) {
1474 $result[$dao->id
] = $dao->abbreviation
. ': ' . $dao->name
;
1479 static $_cache = NULL;
1481 $cacheKey = "{$stateID}_name";
1486 if (!empty($_cache[$cacheKey])) {
1487 return $_cache[$cacheKey];
1491 SELECT civicrm_county.name name, civicrm_county.id id
1493 WHERE state_province_id = %1
1502 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1505 while ($dao->fetch()) {
1506 $result[$dao->id
] = $dao->name
;
1514 * Given a state ID return the country ID, this allows
1515 * us to populate forms and values for downstream code
1517 * @param $stateID int
1519 * @return int the country id that the state belongs to
1523 static function countryIDForStateID($stateID) {
1524 if (empty($stateID)) {
1525 return CRM_Core_DAO
::$_nullObject;
1530 FROM civicrm_state_province
1533 $params = array(1 => array($stateID, 'Integer'));
1535 return CRM_Core_DAO
::singleValueQuery($query, $params);
1539 * Get all types of Greetings.
1541 * The static array of greeting is returned
1546 * @param $filter - get All Email Greetings - default is to get only active ones.
1548 * @return array - array reference of all greetings.
1551 public static function greeting($filter, $columnName = 'label') {
1552 $index = $filter['greeting_type'] . '_' . $columnName;
1554 // also add contactType to the array
1555 $contactType = CRM_Utils_Array
::value('contact_type', $filter);
1557 $index .= '_' . $contactType;
1560 if (NULL === self
::$greeting) {
1561 self
::$greeting = array();
1564 if (!CRM_Utils_Array
::value($index, self
::$greeting)) {
1565 $filterCondition = NULL;
1567 $filterVal = 'v.filter =';
1568 switch ($contactType) {
1577 case 'Organization':
1581 $filterCondition .= "AND (v.filter = 0 OR {$filterVal}) ";
1584 self
::$greeting[$index] = CRM_Core_OptionGroup
::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName);
1587 return self
::$greeting[$index];
1591 * Construct array of default greeting values for contact type
1596 * @return array - array reference of default greetings.
1599 public static function &greetingDefaults() {
1600 if (!self
::$greetingDefaults) {
1601 $defaultGreetings = array();
1602 $contactTypes = self
::get('CRM_Contact_DAO_Contact', 'contact_type', array('keyColumn' => 'id', 'labelColumn' => 'name'));
1604 foreach ($contactTypes as $filter => $contactType) {
1605 $filterCondition = " AND (v.filter = 0 OR v.filter = $filter) AND v.is_default = 1 ";
1607 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
1608 $tokenVal = CRM_Core_OptionGroup
::values($greeting, NULL, NULL, NULL, $filterCondition, 'label');
1609 $defaultGreetings[$contactType][$greeting] = $tokenVal;
1613 self
::$greetingDefaults = $defaultGreetings;
1616 return self
::$greetingDefaults;
1620 * Get all extensions
1622 * The static array extensions
1624 * FIXME: This is called by civix but not by any core code. We
1625 * should provide an API call which civix can use instead.
1630 * @return array - array($fullyQualifiedName => $label) list of extensions
1632 public static function &getExtensions() {
1633 if (!self
::$extensions) {
1634 self
::$extensions = array();
1636 SELECT full_name, label
1637 FROM civicrm_extension
1640 $dao = CRM_Core_DAO
::executeQuery($sql);
1641 while ($dao->fetch()) {
1642 self
::$extensions[$dao->full_name
] = $dao->label
;
1646 return self
::$extensions;
1650 * Fetch the list of active extensions of type 'module'
1652 * @param $fresh bool whether to forcibly reload extensions list from canonical store
1656 * @return array - array(array('prefix' => $, 'file' => $))
1658 public static function getModuleExtensions($fresh = FALSE) {
1659 return CRM_Extension_System
::singleton()->getMapper()->getActiveModuleFiles($fresh);