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;
69 * payment processor billing modes
73 private static $billingMode;
80 private static $stateProvince;
87 private static $county;
90 * states/provinces abbreviations
94 private static $stateProvinceAbbreviation;
101 private static $country;
108 private static $countryIsoCode;
111 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
117 private static $group;
124 private static $groupIterator;
131 private static $relationshipType;
134 * civicrm groups that are not smart groups
138 private static $staticGroup;
145 private static $currencyCode;
152 private static $paymentProcessor;
155 * payment processor types
159 private static $paymentProcessorType;
166 private static $worldRegions;
169 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
175 private static $activityStatus;
182 private static $visibility;
189 private static $greeting;
196 private static $greetingDefaults;
199 * Extensions of type module
203 private static $extensions;
206 * Get options for a given field.
207 * @param String $daoName
208 * @param String $fieldName
209 * @param Array $params
210 * - name string name of the option group
211 * - flip boolean results are return in id => label format if false
212 * if true, the results are reversed
213 * - grouping boolean if true, return the value in 'grouping' column (currently unsupported for tables other than option_value)
214 * - localize boolean if true, localize the results before returning
215 * - condition string add another condition to the sql query
216 * - keyColumn string the column to use for 'id'
217 * - labelColumn string the column to use for 'label'
218 * - orderColumn string the column to use for sorting, defaults to 'weight'
219 * - onlyActive boolean return only the action option values
220 * - fresh boolean ignore cache entries and go back to DB
222 * @return Array on success, FALSE on error.
226 public static function get($daoName, $fieldName, $params = array()) {
228 $fields = $dao->fields();
229 $fieldKeys = $dao->fieldKeys();
230 $fieldKey = $fieldKeys[$fieldName];
232 if (empty($fields[$fieldKey])) {
235 $fieldSpec = $fields[$fieldKey];
236 $flip = !empty($params['flip']);
238 // If the field is an enum, explode the enum definition and return the array.
239 if (isset($fieldSpec['enumValues'])) {
240 // use of a space after the comma is inconsistent in xml
241 $enumStr = str_replace(', ', ',', $fieldSpec['enumValues']);
242 $output = explode(',', $enumStr);
243 return $flip ?
array_flip($output) : $output;
246 elseif (!empty($fieldSpec['pseudoconstant'])) {
247 $pseudoconstant = $fieldSpec['pseudoconstant'];
248 // Merge params with defaults
252 'condition' => CRM_Utils_Array
::value('condition', $pseudoconstant),
253 'keyColumn' => CRM_Utils_Array
::value('keyColumn', $pseudoconstant),
254 'labelColumn' => CRM_Utils_Array
::value('labelColumn', $pseudoconstant),
255 'onlyActive' => TRUE,
259 // Fetch option group from option_value table
260 if(!empty($pseudoconstant['optionGroupName'])) {
261 // Call our generic fn for retrieving from the option_value table
262 return CRM_Core_OptionGroup
::values(
263 $pseudoconstant['optionGroupName'],
267 $params['condition'],
268 $params['labelColumn'] ?
$params['labelColumn'] : 'label',
269 $params['onlyActive'],
274 // Fetch options from other tables
275 if (!empty($pseudoconstant['table'])) {
276 // Normalize params so the serialized cache string will be consistent.
277 CRM_Utils_Array
::remove($params, 'flip', 'fresh');
279 $cacheKey = $daoName . $fieldName . serialize($params);
281 // Retrieve cached options
282 if (isset(self
::$cache[$cacheKey]) && empty($params['fresh'])) {
283 $output = self
::$cache[$cacheKey];
286 $daoName = CRM_Core_AllCoreTables
::getClassForTable($pseudoconstant['table']);
287 if (!class_exists($daoName)) {
290 // Get list of fields for the option table
292 $availableFields = array_keys($dao->fieldKeys());
293 if (in_array('is_active', $availableFields)) {
294 $wheres[] = 'is_active = 1';
298 $select = "SELECT %1 AS id, %2 AS label";
301 $order = "ORDER BY %2";
302 // Condition param can be passed as an sql string
303 if (!empty($params['condition'])) {
304 $wheres[] = $params['condition'];
306 // Support for onlyActive param if option table contains is_active field
307 if (!empty($params['onlyActive'])) {
308 if (in_array('is_active', $availableFields)) {
309 $wheres[] = 'is_active = 1';
312 $queryParams = array(
313 1 => array($params['keyColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
314 2 => array($params['labelColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
315 3 => array($pseudoconstant['table'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
317 // Add orderColumn param
318 if (!empty($params['orderColumn'])) {
319 $queryParams[4] = array($params['orderColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
);
320 $order = "ORDER BY %4";
322 // Support no sorting if $params[orderColumn] is FALSE
323 elseif (isset($params['orderColumn']) && $params['orderColumn'] === FALSE) {
326 // Default to 'weight' if that column exists
327 elseif (in_array('weight', $availableFields)) {
328 $order = "ORDER BY weight";
332 $query = "$select $from";
334 $query .= " WHERE " . implode($wheres, ' AND ');
336 $query .= ' ' . $order;
337 $dao = CRM_Core_DAO
::executeQuery($query, $queryParams);
338 while ($dao->fetch()) {
339 $output[$dao->id
] = $dao->label
;
342 if (!empty($params['localize'])) {
343 $i18n = CRM_Core_I18n
::singleton();
344 $i18n->localizeArray($output);
345 // Maintain sort by label
346 if ($order == "ORDER BY %2") {
347 CRM_Utils_Array
::asort($output);
350 self
::$cache[$cacheKey] = $output;
352 return $flip ?
array_flip($output) : $output;
355 // If we're still here, it's an error. Return FALSE.
360 * Fetch the label (or other value) for a field given its key
362 * @param String $daoName
363 * @param String $fieldName
364 * @param String|Int $key
365 * @param Array $params will be passed into self::get
369 function getValue($daoName, $fieldName, $key, $params = array()) {
370 $values = self
::get($daoName, $fieldName, $params);
371 return CRM_Utils_Array
::value($key, $values);
375 * Fetch the key for a field option given its label/name
377 * @param String $daoName
378 * @param String $fieldName
379 * @param String|Int $value
380 * @param Array $params will be passed into self::get
384 function getKey($daoName, $fieldName, $value, $params = array()) {
385 $values = self
::get($daoName, $fieldName, $params);
386 return CRM_Utils_Array
::key($value, $values);
390 * DEPRECATED generic populate method
391 * All pseudoconstant functions that use this method are also deprecated.
393 * The static array $var is populated from the db
394 * using the <b>$name DAO</b>.
396 * Note: any database errors will be trapped by the DAO.
398 * @param array $var the associative array we will fill
399 * @param string $name the name of the DAO
400 * @param boolean $all get all objects. default is to get only active ones.
401 * @param string $retrieve the field that we are interested in (normally name, differs in some objects)
402 * @param string $filter the field that we want to filter the result set with
403 * @param string $condition the condition that gets passed to the final query as the WHERE clause
409 public static function populate(
414 $filter = 'is_active',
420 $cacheKey = "CRM_PC_{$name}_{$all}_{$key}_{$retrieve}_{$filter}_{$condition}_{$orderby}";
421 $cache = CRM_Utils_Cache
::singleton();
422 $var = $cache->get($cacheKey);
423 if ($var && empty($force)) {
427 $object = new $name ( );
429 $object->selectAdd();
430 $object->selectAdd("$key, $retrieve");
432 $object->whereAdd($condition);
436 $object->orderBy($retrieve);
439 $object->orderBy($orderby);
443 $object->$filter = 1;
448 while ($object->fetch()) {
449 $var[$object->$key] = $object->$retrieve;
452 $cache->set($cacheKey, $var);
456 * Flush given pseudoconstant so it can be reread from db
457 * nex time it's requested.
462 * @param boolean $name pseudoconstant to be flushed
465 public static function flush($name = 'cache') {
466 if (property_exists(self
, $name)) {
472 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
474 * Get all Activty types.
476 * The static array activityType is returned
478 * @param boolean $all - get All Activity types - default is to get only active ones.
483 * @return array - array reference of all activity types.
485 public static function &activityType() {
486 $args = func_get_args();
487 $all = CRM_Utils_Array
::value(0, $args, TRUE);
488 $includeCaseActivities = CRM_Utils_Array
::value(1, $args, FALSE);
489 $reset = CRM_Utils_Array
::value(2, $args, FALSE);
490 $returnColumn = CRM_Utils_Array
::value(3, $args, 'label');
491 $includeCampaignActivities = CRM_Utils_Array
::value(4, $args, FALSE);
492 $onlyComponentActivities = CRM_Utils_Array
::value(5, $args, FALSE);
493 $index = (int) $all . '_' . $returnColumn . '_' . (int) $includeCaseActivities;
494 $index .= '_' . (int) $includeCampaignActivities;
495 $index .= '_' . (int) $onlyComponentActivities;
497 if (NULL === self
::$activityType) {
498 self
::$activityType = array();
501 if (!isset(self
::$activityType[$index]) ||
$reset) {
504 $condition = 'AND filter = 0';
506 $componentClause = " v.component_id IS NULL";
507 if ($onlyComponentActivities) {
508 $componentClause = " v.component_id IS NOT NULL";
511 $componentIds = array();
512 $compInfo = CRM_Core_Component
::getEnabledComponents();
514 // build filter for listing activity types only if their
515 // respective components are enabled
516 foreach ($compInfo as $compName => $compObj) {
517 if ($compName == 'CiviCase') {
518 if ($includeCaseActivities) {
519 $componentIds[] = $compObj->componentID
;
522 elseif ($compName == 'CiviCampaign') {
523 if ($includeCampaignActivities) {
524 $componentIds[] = $compObj->componentID
;
528 $componentIds[] = $compObj->componentID
;
532 if (count($componentIds)) {
533 $componentIds = implode(',', $componentIds);
534 $componentClause = " ($componentClause OR v.component_id IN ($componentIds))";
535 if ($onlyComponentActivities) {
536 $componentClause = " ( v.component_id IN ($componentIds ) )";
539 $condition = $condition . ' AND ' . $componentClause;
541 self
::$activityType[$index] = CRM_Core_OptionGroup
::values('activity_type', FALSE, FALSE, FALSE, $condition, $returnColumn);
543 return self
::$activityType[$index];
547 * Get all payment-processor billing modes
552 * @return array ($id => $name)
554 public static function billingMode() {
555 if (!self
::$billingMode) {
556 self
::$billingMode = array(
557 CRM_Core_Payment
::BILLING_MODE_FORM
=> 'form',
558 CRM_Core_Payment
::BILLING_MODE_BUTTON
=> 'button',
559 CRM_Core_Payment
::BILLING_MODE_NOTIFY
=> 'notify',
562 return self
::$billingMode;
566 * Get all the State/Province from database.
568 * The static array stateProvince is returned, and if it's
569 * called the first time, the <b>State Province DAO</b> is used
570 * to get all the States.
572 * Note: any database errors will be trapped by the DAO.
577 * @param int $id - Optional id to return
579 * @return array - array reference of all State/Provinces.
582 public static function &stateProvince($id = FALSE, $limit = TRUE) {
583 if (($id && !CRM_Utils_Array
::value($id, self
::$stateProvince)) ||
!self
::$stateProvince ||
!$id) {
584 $whereClause = FALSE;
585 $config = CRM_Core_Config
::singleton();
587 $countryIsoCodes = self
::countryIsoCode();
588 $limitCodes = $config->provinceLimit();
590 foreach ($limitCodes as $code) {
591 $limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
593 if (!empty($limitIds)) {
594 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
597 $whereClause = FALSE;
600 self
::populate(self
::$stateProvince, 'CRM_Core_DAO_StateProvince', TRUE, 'name', 'is_active', $whereClause);
602 // localise the province names if in an non-en_US locale
604 if ($tsLocale != '' and $tsLocale != 'en_US') {
605 $i18n = CRM_Core_I18n
::singleton();
606 $i18n->localizeArray(self
::$stateProvince, array(
607 'context' => 'province',
609 self
::$stateProvince = CRM_Utils_Array
::asort(self
::$stateProvince);
613 if (array_key_exists($id, self
::$stateProvince)) {
614 return self
::$stateProvince[$id];
621 return self
::$stateProvince;
625 * Get all the State/Province abbreviations from the database.
627 * Same as above, except gets the abbreviations instead of the names.
632 * @param int $id - Optional id to return
634 * @return array - array reference of all State/Province abbreviations.
636 public static function &stateProvinceAbbreviation($id = FALSE, $limit = TRUE) {
640 FROM civicrm_state_province
648 return CRM_Core_DAO
::singleValueQuery($query, $params);
651 if (!self
::$stateProvinceAbbreviation ||
!$id) {
653 $whereClause = FALSE;
656 $config = CRM_Core_Config
::singleton();
657 $countryIsoCodes = self
::countryIsoCode();
658 $limitCodes = $config->provinceLimit();
660 foreach ($limitCodes as $code) {
661 $tmpArray = array_keys($countryIsoCodes, $code);
663 if (!empty($tmpArray)) {
664 $limitIds[] = array_shift($tmpArray);
667 if (!empty($limitIds)) {
668 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
671 self
::populate(self
::$stateProvinceAbbreviation, 'CRM_Core_DAO_StateProvince', TRUE, 'abbreviation', 'is_active', $whereClause);
675 if (array_key_exists($id, self
::$stateProvinceAbbreviation)) {
676 return self
::$stateProvinceAbbreviation[$id];
683 return self
::$stateProvinceAbbreviation;
687 * Get all the countries from database.
689 * The static array country is returned, and if it's
690 * called the first time, the <b>Country DAO</b> is used
691 * to get all the countries.
693 * Note: any database errors will be trapped by the DAO.
698 * @param int $id - Optional id to return
700 * @return array - array reference of all countries.
703 public static function country($id = FALSE, $applyLimit = TRUE) {
704 if (($id && !CRM_Utils_Array
::value($id, self
::$country)) ||
!self
::$country ||
!$id) {
706 $config = CRM_Core_Config
::singleton();
707 $limitCodes = array();
710 // limit the country list to the countries specified in CIVICRM_COUNTRY_LIMIT
711 // (ensuring it's a subset of the legal values)
712 // K/P: We need to fix this, i dont think it works with new setting files
713 $limitCodes = $config->countryLimit();
714 if (!is_array($limitCodes)) {
716 $config->countryLimit
=> 1,
720 $limitCodes = array_intersect(self
::countryIsoCode(), $limitCodes);
723 if (count($limitCodes)) {
724 $whereClause = "iso_code IN ('" . implode("', '", $limitCodes) . "')";
730 self
::populate(self
::$country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active', $whereClause);
732 // if default country is set, percolate it to the top
733 if ($config->defaultContactCountry()) {
734 $countryIsoCodes = self
::countryIsoCode();
735 $defaultID = array_search($config->defaultContactCountry(), $countryIsoCodes);
736 if ($defaultID !== FALSE) {
737 $default[$defaultID] = CRM_Utils_Array
::value($defaultID, self
::$country);
738 self
::$country = $default + self
::$country;
742 // localise the country names if in an non-en_US locale
744 if ($tsLocale != '' and $tsLocale != 'en_US') {
745 $i18n = CRM_Core_I18n
::singleton();
746 $i18n->localizeArray(self
::$country, array(
747 'context' => 'country',
749 self
::$country = CRM_Utils_Array
::asort(self
::$country);
753 if (array_key_exists($id, self
::$country)) {
754 return self
::$country[$id];
757 return CRM_Core_DAO
::$_nullObject;
760 return self
::$country;
764 * Get all the country ISO Code abbreviations from the database.
766 * The static array countryIsoCode is returned, and if it's
767 * called the first time, the <b>Country DAO</b> is used
768 * to get all the countries' ISO codes.
770 * Note: any database errors will be trapped by the DAO.
775 * @return array - array reference of all country ISO codes.
778 public static function &countryIsoCode($id = FALSE) {
779 if (!self
::$countryIsoCode) {
780 self
::populate(self
::$countryIsoCode, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
783 if (array_key_exists($id, self
::$countryIsoCode)) {
784 return self
::$countryIsoCode[$id];
787 return CRM_Core_DAO
::$_nullObject;
790 return self
::$countryIsoCode;
794 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
796 * Get all groups from database
798 * The static array group is returned, and if it's
799 * called the first time, the <b>Group DAO</b> is used
800 * to get all the groups.
802 * Note: any database errors will be trapped by the DAO.
804 * @param string $groupType type of group(Access/Mailing)
805 * @param boolen $excludeHidden exclude hidden groups.
810 * @return array - array reference of all groups.
813 public static function &allGroup($groupType = NULL, $excludeHidden = TRUE) {
814 $condition = CRM_Contact_BAO_Group
::groupTypeCondition($groupType, $excludeHidden);
817 self
::$group = array();
820 $groupKey = $groupType ?
$groupType : 'null';
822 if (!isset(self
::$group[$groupKey])) {
823 self
::$group[$groupKey] = NULL;
824 self
::populate(self
::$group[$groupKey], 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition);
826 return self
::$group[$groupKey];
830 * Create or get groups iterator (iterates over nested groups in a
833 * The GroupNesting instance is returned; it's created if this is being
834 * called for the first time
840 * @return mixed - instance of CRM_Contact_BAO_GroupNesting
843 public static function &groupIterator($styledLabels = FALSE) {
844 if (!self
::$groupIterator) {
846 When used as an object, GroupNesting implements Iterator
847 and iterates nested groups in a logical manner for us
849 self
::$groupIterator = new CRM_Contact_BAO_GroupNesting($styledLabels);
851 return self
::$groupIterator;
855 * Get all permissioned groups from database
857 * The static array group is returned, and if it's
858 * called the first time, the <b>Group DAO</b> is used
859 * to get all the groups.
861 * Note: any database errors will be trapped by the DAO.
863 * @param string $groupType type of group(Access/Mailing)
864 * @param boolen $excludeHidden exclude hidden groups.
869 * @return array - array reference of all groups.
872 public static function group($groupType = NULL, $excludeHidden = TRUE) {
873 return CRM_Core_Permission
::group($groupType, $excludeHidden);
877 * Get all permissioned groups from database
879 * The static array group is returned, and if it's
880 * called the first time, the <b>Group DAO</b> is used
881 * to get all the groups.
883 * Note: any database errors will be trapped by the DAO.
888 * @return array - array reference of all groups.
891 public static function &staticGroup($onlyPublic = FALSE, $groupType = NULL, $excludeHidden = TRUE) {
892 if (!self
::$staticGroup) {
893 $condition = 'saved_search_id = 0 OR saved_search_id IS NULL';
895 $condition .= " AND visibility != 'User and User Admin Only'";
899 $condition .= ' AND ' . CRM_Contact_BAO_Group
::groupTypeCondition($groupType);
902 if ($excludeHidden) {
903 $condition .= ' AND is_hidden != 1 ';
906 self
::populate(self
::$staticGroup, 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition, 'title');
909 return self
::$staticGroup;
913 * Get all Relationship Types from database.
915 * The static array group is returned, and if it's
916 * called the first time, the <b>RelationshipType DAO</b> is used
917 * to get all the relationship types.
919 * Note: any database errors will be trapped by the DAO.
921 * @param string $valueColumnName db column name/label.
922 * @param boolean $reset reset relationship types if true
927 * @return array - array reference of all relationship types.
929 public static function &relationshipType($valueColumnName = 'label', $reset = FALSE) {
930 if (!CRM_Utils_Array
::value($valueColumnName, self
::$relationshipType) ||
$reset) {
931 self
::$relationshipType[$valueColumnName] = array();
933 //now we have name/label columns CRM-3336
934 $column_a_b = "{$valueColumnName}_a_b";
935 $column_b_a = "{$valueColumnName}_b_a";
937 $relationshipTypeDAO = new CRM_Contact_DAO_RelationshipType();
938 $relationshipTypeDAO->selectAdd();
939 $relationshipTypeDAO->selectAdd("id, {$column_a_b}, {$column_b_a}, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b");
940 $relationshipTypeDAO->is_active
= 1;
941 $relationshipTypeDAO->find();
942 while ($relationshipTypeDAO->fetch()) {
944 self
::$relationshipType[$valueColumnName][$relationshipTypeDAO->id
] = array(
945 $column_a_b => $relationshipTypeDAO->$column_a_b,
946 $column_b_a => $relationshipTypeDAO->$column_b_a,
947 'contact_type_a' => "$relationshipTypeDAO->contact_type_a",
948 'contact_type_b' => "$relationshipTypeDAO->contact_type_b",
949 'contact_sub_type_a' => "$relationshipTypeDAO->contact_sub_type_a",
950 'contact_sub_type_b' => "$relationshipTypeDAO->contact_sub_type_b",
955 return self
::$relationshipType[$valueColumnName];
959 * get all the ISO 4217 currency codes
961 * so far, we use this for validation only, so there's no point of putting this into the database
965 * @return array - array reference of all currency codes
968 public static function ¤cyCode() {
969 if (!self
::$currencyCode) {
970 self
::$currencyCode = array(
1240 return self
::$currencyCode;
1244 * Get all the County from database.
1246 * The static array county is returned, and if it's
1247 * called the first time, the <b>County DAO</b> is used
1248 * to get all the Counties.
1250 * Note: any database errors will be trapped by the DAO.
1255 * @param int $id - Optional id to return
1257 * @return array - array reference of all Counties
1260 public static function &county($id = FALSE) {
1261 if (!self
::$county) {
1263 $config = CRM_Core_Config
::singleton();
1264 // order by id so users who populate civicrm_county can have more control over sort by the order they load the counties
1265 self
::populate(self
::$county, 'CRM_Core_DAO_County', TRUE, 'name', NULL, NULL, 'id');
1268 if (array_key_exists($id, self
::$county)) {
1269 return self
::$county[$id];
1272 return CRM_Core_DAO
::$_nullObject;
1275 return self
::$county;
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 * Get all active payment processors
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 the Languages from database.
1625 * @return array self::languages - array reference of all languages
1628 public static function &languages() {
1629 return CRM_Core_I18n_PseudoConstant
::languages();
1635 public static function &preferredLanguage() {
1636 return CRM_Core_I18n_PseudoConstant
::languages();
1640 * Get all extensions
1642 * The static array extensions
1644 * FIXME: This is called by civix but not by any core code. We
1645 * should provide an API call which civix can use instead.
1650 * @return array - array($fullyQualifiedName => $label) list of extensions
1652 public static function &getExtensions() {
1653 if (!self
::$extensions) {
1654 self
::$extensions = array();
1656 SELECT full_name, label
1657 FROM civicrm_extension
1660 $dao = CRM_Core_DAO
::executeQuery($sql);
1661 while ($dao->fetch()) {
1662 self
::$extensions[$dao->full_name
] = $dao->label
;
1666 return self
::$extensions;
1670 * Fetch the list of active extensions of type 'module'
1672 * @param $fresh bool whether to forcibly reload extensions list from canonical store
1676 * @return array - array(array('prefix' => $, 'file' => $))
1678 public static function getModuleExtensions($fresh = FALSE) {
1679 return CRM_Extension_System
::singleton()->getMapper()->getActiveModuleFiles($fresh);