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;
64 private static $activityType;
67 * payment processor billing modes
71 private static $billingMode;
78 private static $stateProvince;
85 private static $county;
88 * states/provinces abbreviations
92 private static $stateProvinceAbbreviation;
99 private static $country;
106 private static $countryIsoCode;
113 private static $group;
120 private static $groupIterator;
127 private static $relationshipType;
130 * civicrm groups that are not smart groups
134 private static $staticGroup;
141 private static $currencyCode;
148 private static $paymentProcessor;
151 * payment processor types
155 private static $paymentProcessorType;
162 private static $worldRegions;
169 private static $activityStatus;
176 private static $visibility;
183 private static $greeting;
190 private static $greetingDefaults;
193 * Extensions of type module
197 private static $extensions;
200 * Get options for a given field.
201 * @param String $daoName
202 * @param String $fieldName
203 * @param Array $params
204 * - name string name of the option group
205 * - flip boolean results are return in id => label format if false
206 * if true, the results are reversed
207 * - grouping boolean if true, return the value in 'grouping' column (currently unsupported for tables other than option_value)
208 * - localize boolean if true, localize the results before returning
209 * - condition string add another condition to the sql query
210 * - keyColumn string the column to use for 'id'
211 * - labelColumn string the column to use for 'label'
212 * - orderColumn string the column to use for sorting, defaults to 'weight'
213 * - onlyActive boolean return only the action option values
214 * - fresh boolean ignore cache entries and go back to DB
216 * @return Array on success, FALSE on error.
220 public static function get($daoName, $fieldName, $params = array()) {
222 $fields = $dao->fields();
223 $fieldKeys = $dao->fieldKeys();
224 $fieldKey = $fieldKeys[$fieldName];
226 if (empty($fields[$fieldKey])) {
229 $fieldSpec = $fields[$fieldKey];
230 $flip = !empty($params['flip']);
232 // If the field is an enum, explode the enum definition and return the array.
233 if (isset($fieldSpec['enumValues'])) {
234 // use of a space after the comma is inconsistent in xml
235 $enumStr = str_replace(', ', ',', $fieldSpec['enumValues']);
236 $output = explode(',', $enumStr);
237 return $flip ?
array_flip($output) : $output;
240 elseif (!empty($fieldSpec['pseudoconstant'])) {
241 $pseudoconstant = $fieldSpec['pseudoconstant'];
242 // Merge params with defaults
246 'condition' => CRM_Utils_Array
::value('condition', $pseudoconstant),
247 'keyColumn' => CRM_Utils_Array
::value('keyColumn', $pseudoconstant),
248 'labelColumn' => CRM_Utils_Array
::value('labelColumn', $pseudoconstant),
249 'onlyActive' => TRUE,
253 // Fetch option group from option_value table
254 if(!empty($pseudoconstant['optionGroupName'])) {
255 // Call our generic fn for retrieving from the option_value table
256 return CRM_Core_OptionGroup
::values(
257 $pseudoconstant['optionGroupName'],
261 $params['condition'],
262 $params['labelColumn'] ?
$params['labelColumn'] : 'label',
263 $params['onlyActive'],
268 // Fetch options from other tables
269 if (!empty($pseudoconstant['table'])) {
270 // Normalize params so the serialized cache string will be consistent.
271 CRM_Utils_Array
::remove($params, 'flip', 'fresh');
273 $cacheKey = $daoName . $fieldName . serialize($params);
275 // Retrieve cached options
276 if (isset(self
::$cache[$cacheKey]) && empty($params['fresh'])) {
277 $output = self
::$cache[$cacheKey];
280 // Get list of fields for the option table
281 $daoName = CRM_Core_AllCoreTables
::getClassForTable($pseudoconstant['table']);
283 $availableFields = array_keys($dao->fieldKeys());
284 if (in_array('is_active', $availableFields)) {
285 $wheres[] = 'is_active = 1';
289 $select = "SELECT %1 AS id, %2 AS label";
292 $order = "ORDER BY %2";
293 // Condition param can be passed as an sql string
294 if (!empty($params['condition'])) {
295 $wheres[] = $params['condition'];
297 // Support for onlyActive param if option table contains is_active field
298 if (!empty($params['onlyActive'])) {
299 if (in_array('is_active', $availableFields)) {
300 $wheres[] = 'is_active = 1';
303 $queryParams = array(
304 1 => array($params['keyColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
305 2 => array($params['labelColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
306 3 => array($pseudoconstant['table'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
308 // Add orderColumn param
309 if (!empty($params['orderColumn'])) {
310 $queryParams[4] = array($params['orderColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
);
311 $order = "ORDER BY %4";
313 // Support no sorting if $params[orderColumn] is FALSE
314 elseif (isset($params['orderColumn']) && $params['orderColumn'] === FALSE) {
317 // Default to 'weight' if that column exists
318 elseif (in_array('weight', $availableFields)) {
319 $order = "ORDER BY weight";
323 $query = "$select $from";
325 $query .= " WHERE " . implode($wheres, ' AND ');
327 $query .= ' ' . $order;
328 $dao = CRM_Core_DAO
::executeQuery($query, $queryParams);
329 while ($dao->fetch()) {
330 $output[$dao->id
] = $dao->label
;
333 if (!empty($params['localize'])) {
334 $i18n = CRM_Core_I18n
::singleton();
335 $i18n->localizeArray($output);
336 // Maintain sort by label
337 if ($order == "ORDER BY %2") {
338 CRM_Utils_Array
::asort($output);
341 self
::$cache[$cacheKey] = $output;
343 return $flip ?
array_flip($output) : $output;
346 // If we're still here, it's an error. Return FALSE.
351 * populate the object from the database. generic populate
354 * The static array $var is populated from the db
355 * using the <b>$name DAO</b>.
357 * Note: any database errors will be trapped by the DAO.
359 * @param array $var the associative array we will fill
360 * @param string $name the name of the DAO
361 * @param boolean $all get all objects. default is to get only active ones.
362 * @param string $retrieve the field that we are interested in (normally name, differs in some objects)
363 * @param string $filter the field that we want to filter the result set with
364 * @param string $condition the condition that gets passed to the final query as the WHERE clause
370 public static function populate(
375 $filter = 'is_active',
381 $cacheKey = "CRM_PC_{$name}_{$all}_{$key}_{$retrieve}_{$filter}_{$condition}_{$orderby}";
382 $cache = CRM_Utils_Cache
::singleton();
383 $var = $cache->get($cacheKey);
384 if ($var && empty($force)) {
388 $object = new $name ( );
390 $object->selectAdd();
391 $object->selectAdd("$key, $retrieve");
393 $object->whereAdd($condition);
397 $object->orderBy($retrieve);
400 $object->orderBy($orderby);
404 $object->$filter = 1;
409 while ($object->fetch()) {
410 $var[$object->$key] = $object->$retrieve;
413 $cache->set($cacheKey, $var);
417 * Flush given pseudoconstant so it can be reread from db
418 * nex time it's requested.
423 * @param boolean $name pseudoconstant to be flushed
426 public static function flush($name = 'cache') {
427 if (property_exists(self
, $name)) {
433 * Get all Activty types.
435 * The static array activityType is returned
437 * @param boolean $all - get All Activity types - default is to get only active ones.
442 * @return array - array reference of all activity types.
444 public static function &activityType() {
445 $args = func_get_args();
446 $all = CRM_Utils_Array
::value(0, $args, TRUE);
447 $includeCaseActivities = CRM_Utils_Array
::value(1, $args, FALSE);
448 $reset = CRM_Utils_Array
::value(2, $args, FALSE);
449 $returnColumn = CRM_Utils_Array
::value(3, $args, 'label');
450 $includeCampaignActivities = CRM_Utils_Array
::value(4, $args, FALSE);
451 $onlyComponentActivities = CRM_Utils_Array
::value(5, $args, FALSE);
452 $index = (int) $all . '_' . $returnColumn . '_' . (int) $includeCaseActivities;
453 $index .= '_' . (int) $includeCampaignActivities;
454 $index .= '_' . (int) $onlyComponentActivities;
456 if (NULL === self
::$activityType) {
457 self
::$activityType = array();
460 if (!isset(self
::$activityType[$index]) ||
$reset) {
463 $condition = 'AND filter = 0';
465 $componentClause = " v.component_id IS NULL";
466 if ($onlyComponentActivities) {
467 $componentClause = " v.component_id IS NOT NULL";
470 $componentIds = array();
471 $compInfo = CRM_Core_Component
::getEnabledComponents();
473 // build filter for listing activity types only if their
474 // respective components are enabled
475 foreach ($compInfo as $compName => $compObj) {
476 if ($compName == 'CiviCase') {
477 if ($includeCaseActivities) {
478 $componentIds[] = $compObj->componentID
;
481 elseif ($compName == 'CiviCampaign') {
482 if ($includeCampaignActivities) {
483 $componentIds[] = $compObj->componentID
;
487 $componentIds[] = $compObj->componentID
;
491 if (count($componentIds)) {
492 $componentIds = implode(',', $componentIds);
493 $componentClause = " ($componentClause OR v.component_id IN ($componentIds))";
494 if ($onlyComponentActivities) {
495 $componentClause = " ( v.component_id IN ($componentIds ) )";
498 $condition = $condition . ' AND ' . $componentClause;
500 self
::$activityType[$index] = CRM_Core_OptionGroup
::values('activity_type', FALSE, FALSE, FALSE, $condition, $returnColumn);
502 return self
::$activityType[$index];
506 * Get all payment-processor billing modes
511 * @return array ($id => $name)
513 public static function billingMode() {
514 if (!self
::$billingMode) {
515 self
::$billingMode = array(
516 CRM_Core_Payment
::BILLING_MODE_FORM
=> 'form',
517 CRM_Core_Payment
::BILLING_MODE_BUTTON
=> 'button',
518 CRM_Core_Payment
::BILLING_MODE_NOTIFY
=> 'notify',
521 return self
::$billingMode;
525 * Get all the State/Province from database.
527 * The static array stateProvince is returned, and if it's
528 * called the first time, the <b>State Province DAO</b> is used
529 * to get all the States.
531 * Note: any database errors will be trapped by the DAO.
536 * @param int $id - Optional id to return
538 * @return array - array reference of all State/Provinces.
541 public static function &stateProvince($id = FALSE, $limit = TRUE) {
542 if (($id && !CRM_Utils_Array
::value($id, self
::$stateProvince)) ||
!self
::$stateProvince ||
!$id) {
543 $whereClause = FALSE;
544 $config = CRM_Core_Config
::singleton();
546 $countryIsoCodes = self
::countryIsoCode();
547 $limitCodes = $config->provinceLimit();
549 foreach ($limitCodes as $code) {
550 $limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
552 if (!empty($limitIds)) {
553 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
556 $whereClause = FALSE;
559 self
::populate(self
::$stateProvince, 'CRM_Core_DAO_StateProvince', TRUE, 'name', 'is_active', $whereClause);
561 // localise the province names if in an non-en_US locale
563 if ($tsLocale != '' and $tsLocale != 'en_US') {
564 $i18n = CRM_Core_I18n
::singleton();
565 $i18n->localizeArray(self
::$stateProvince, array(
566 'context' => 'province',
568 self
::$stateProvince = CRM_Utils_Array
::asort(self
::$stateProvince);
572 if (array_key_exists($id, self
::$stateProvince)) {
573 return self
::$stateProvince[$id];
580 return self
::$stateProvince;
584 * Get all the State/Province abbreviations from the database.
586 * Same as above, except gets the abbreviations instead of the names.
591 * @param int $id - Optional id to return
593 * @return array - array reference of all State/Province abbreviations.
595 public static function &stateProvinceAbbreviation($id = FALSE, $limit = TRUE) {
599 FROM civicrm_state_province
607 return CRM_Core_DAO
::singleValueQuery($query, $params);
610 if (!self
::$stateProvinceAbbreviation ||
!$id) {
612 $whereClause = FALSE;
615 $config = CRM_Core_Config
::singleton();
616 $countryIsoCodes = self
::countryIsoCode();
617 $limitCodes = $config->provinceLimit();
619 foreach ($limitCodes as $code) {
620 $tmpArray = array_keys($countryIsoCodes, $code);
622 if (!empty($tmpArray)) {
623 $limitIds[] = array_shift($tmpArray);
626 if (!empty($limitIds)) {
627 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
630 self
::populate(self
::$stateProvinceAbbreviation, 'CRM_Core_DAO_StateProvince', TRUE, 'abbreviation', 'is_active', $whereClause);
634 if (array_key_exists($id, self
::$stateProvinceAbbreviation)) {
635 return self
::$stateProvinceAbbreviation[$id];
642 return self
::$stateProvinceAbbreviation;
646 * Get all the countries from database.
648 * The static array country is returned, and if it's
649 * called the first time, the <b>Country DAO</b> is used
650 * to get all the countries.
652 * Note: any database errors will be trapped by the DAO.
657 * @param int $id - Optional id to return
659 * @return array - array reference of all countries.
662 public static function country($id = FALSE, $applyLimit = TRUE) {
663 if (($id && !CRM_Utils_Array
::value($id, self
::$country)) ||
!self
::$country ||
!$id) {
665 $config = CRM_Core_Config
::singleton();
666 $limitCodes = array();
669 // limit the country list to the countries specified in CIVICRM_COUNTRY_LIMIT
670 // (ensuring it's a subset of the legal values)
671 // K/P: We need to fix this, i dont think it works with new setting files
672 $limitCodes = $config->countryLimit();
673 if (!is_array($limitCodes)) {
675 $config->countryLimit
=> 1,
679 $limitCodes = array_intersect(self
::countryIsoCode(), $limitCodes);
682 if (count($limitCodes)) {
683 $whereClause = "iso_code IN ('" . implode("', '", $limitCodes) . "')";
689 self
::populate(self
::$country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active', $whereClause);
691 // if default country is set, percolate it to the top
692 if ($config->defaultContactCountry()) {
693 $countryIsoCodes = self
::countryIsoCode();
694 $defaultID = array_search($config->defaultContactCountry(), $countryIsoCodes);
695 if ($defaultID !== FALSE) {
696 $default[$defaultID] = CRM_Utils_Array
::value($defaultID, self
::$country);
697 self
::$country = $default + self
::$country;
701 // localise the country names if in an non-en_US locale
703 if ($tsLocale != '' and $tsLocale != 'en_US') {
704 $i18n = CRM_Core_I18n
::singleton();
705 $i18n->localizeArray(self
::$country, array(
706 'context' => 'country',
708 self
::$country = CRM_Utils_Array
::asort(self
::$country);
712 if (array_key_exists($id, self
::$country)) {
713 return self
::$country[$id];
716 return CRM_Core_DAO
::$_nullObject;
719 return self
::$country;
723 * Get all the country ISO Code abbreviations from the database.
725 * The static array countryIsoCode is returned, and if it's
726 * called the first time, the <b>Country DAO</b> is used
727 * to get all the countries' ISO codes.
729 * Note: any database errors will be trapped by the DAO.
734 * @return array - array reference of all country ISO codes.
737 public static function &countryIsoCode($id = FALSE) {
738 if (!self
::$countryIsoCode) {
739 self
::populate(self
::$countryIsoCode, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
742 if (array_key_exists($id, self
::$countryIsoCode)) {
743 return self
::$countryIsoCode[$id];
746 return CRM_Core_DAO
::$_nullObject;
749 return self
::$countryIsoCode;
753 * Get all groups from database
755 * The static array group is returned, and if it's
756 * called the first time, the <b>Group DAO</b> is used
757 * to get all the groups.
759 * Note: any database errors will be trapped by the DAO.
761 * @param string $groupType type of group(Access/Mailing)
762 * @param boolen $excludeHidden exclude hidden groups.
767 * @return array - array reference of all groups.
770 public static function &allGroup($groupType = NULL, $excludeHidden = TRUE) {
771 $condition = CRM_Contact_BAO_Group
::groupTypeCondition($groupType, $excludeHidden);
774 self
::$group = array();
777 $groupKey = $groupType ?
$groupType : 'null';
779 if (!isset(self
::$group[$groupKey])) {
780 self
::$group[$groupKey] = NULL;
781 self
::populate(self
::$group[$groupKey], 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition);
783 return self
::$group[$groupKey];
787 * Create or get groups iterator (iterates over nested groups in a
790 * The GroupNesting instance is returned; it's created if this is being
791 * called for the first time
797 * @return mixed - instance of CRM_Contact_BAO_GroupNesting
800 public static function &groupIterator($styledLabels = FALSE) {
801 if (!self
::$groupIterator) {
803 When used as an object, GroupNesting implements Iterator
804 and iterates nested groups in a logical manner for us
806 self
::$groupIterator = new CRM_Contact_BAO_GroupNesting($styledLabels);
808 return self
::$groupIterator;
812 * Get all permissioned groups from database
814 * The static array group is returned, and if it's
815 * called the first time, the <b>Group DAO</b> is used
816 * to get all the groups.
818 * Note: any database errors will be trapped by the DAO.
820 * @param string $groupType type of group(Access/Mailing)
821 * @param boolen $excludeHidden exclude hidden groups.
826 * @return array - array reference of all groups.
829 public static function group($groupType = NULL, $excludeHidden = TRUE) {
830 return CRM_Core_Permission
::group($groupType, $excludeHidden);
834 * Get all permissioned groups from database
836 * The static array group is returned, and if it's
837 * called the first time, the <b>Group DAO</b> is used
838 * to get all the groups.
840 * Note: any database errors will be trapped by the DAO.
845 * @return array - array reference of all groups.
848 public static function &staticGroup($onlyPublic = FALSE, $groupType = NULL, $excludeHidden = TRUE) {
849 if (!self
::$staticGroup) {
850 $condition = 'saved_search_id = 0 OR saved_search_id IS NULL';
852 $condition .= " AND visibility != 'User and User Admin Only'";
856 $condition .= ' AND ' . CRM_Contact_BAO_Group
::groupTypeCondition($groupType);
859 if ($excludeHidden) {
860 $condition .= ' AND is_hidden != 1 ';
863 self
::populate(self
::$staticGroup, 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition, 'title');
866 return self
::$staticGroup;
870 * Get all Relationship Types from database.
872 * The static array group is returned, and if it's
873 * called the first time, the <b>RelationshipType DAO</b> is used
874 * to get all the relationship types.
876 * Note: any database errors will be trapped by the DAO.
878 * @param string $valueColumnName db column name/label.
879 * @param boolean $reset reset relationship types if true
884 * @return array - array reference of all relationship types.
886 public static function &relationshipType($valueColumnName = 'label', $reset = FALSE) {
887 if (!CRM_Utils_Array
::value($valueColumnName, self
::$relationshipType) ||
$reset) {
888 self
::$relationshipType[$valueColumnName] = array();
890 //now we have name/label columns CRM-3336
891 $column_a_b = "{$valueColumnName}_a_b";
892 $column_b_a = "{$valueColumnName}_b_a";
894 $relationshipTypeDAO = new CRM_Contact_DAO_RelationshipType();
895 $relationshipTypeDAO->selectAdd();
896 $relationshipTypeDAO->selectAdd("id, {$column_a_b}, {$column_b_a}, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b");
897 $relationshipTypeDAO->is_active
= 1;
898 $relationshipTypeDAO->find();
899 while ($relationshipTypeDAO->fetch()) {
901 self
::$relationshipType[$valueColumnName][$relationshipTypeDAO->id
] = array(
902 $column_a_b => $relationshipTypeDAO->$column_a_b,
903 $column_b_a => $relationshipTypeDAO->$column_b_a,
904 'contact_type_a' => "$relationshipTypeDAO->contact_type_a",
905 'contact_type_b' => "$relationshipTypeDAO->contact_type_b",
906 'contact_sub_type_a' => "$relationshipTypeDAO->contact_sub_type_a",
907 'contact_sub_type_b' => "$relationshipTypeDAO->contact_sub_type_b",
912 return self
::$relationshipType[$valueColumnName];
916 * get all the ISO 4217 currency codes
918 * so far, we use this for validation only, so there's no point of putting this into the database
922 * @return array - array reference of all currency codes
925 public static function ¤cyCode() {
926 if (!self
::$currencyCode) {
927 self
::$currencyCode = array(
1197 return self
::$currencyCode;
1201 * Get all the County from database.
1203 * The static array county is returned, and if it's
1204 * called the first time, the <b>County DAO</b> is used
1205 * to get all the Counties.
1207 * Note: any database errors will be trapped by the DAO.
1212 * @param int $id - Optional id to return
1214 * @return array - array reference of all Counties
1217 public static function &county($id = FALSE) {
1218 if (!self
::$county) {
1220 $config = CRM_Core_Config
::singleton();
1221 // order by id so users who populate civicrm_county can have more control over sort by the order they load the counties
1222 self
::populate(self
::$county, 'CRM_Core_DAO_County', TRUE, 'name', NULL, NULL, 'id');
1225 if (array_key_exists($id, self
::$county)) {
1226 return self
::$county[$id];
1229 return CRM_Core_DAO
::$_nullObject;
1232 return self
::$county;
1236 * Get all active payment processors
1238 * The static array paymentProcessor is returned
1243 * @param boolean $all - get payment processors - default is to get only active ones.
1244 * @param boolean $test - get test payment processors
1246 * @return array - array of all payment processors
1249 public static function &paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
1250 $condition = "is_test = ";
1251 $condition .= ($test) ?
'1' : '0';
1253 if ($additionalCond) {
1254 $condition .= " AND ( $additionalCond ) ";
1257 // CRM-7178. Make sure we only include payment processors valid in ths
1259 $condition .= " AND domain_id = " . CRM_Core_Config
::domainID();
1261 $cacheKey = $condition . '_' . (int) $all;
1262 if (!isset(self
::$paymentProcessor[$cacheKey])) {
1263 self
::populate(self
::$paymentProcessor[$cacheKey], 'CRM_Financial_DAO_PaymentProcessor', $all, 'name', 'is_active', $condition, 'is_default desc, name');
1266 return self
::$paymentProcessor[$cacheKey];
1270 * Get all active payment processors
1272 * The static array paymentProcessorType is returned
1277 * @param boolean $all - get payment processors - default is to get only active ones.
1279 * @return array - array of all payment processor types
1282 public static function &paymentProcessorType($all = FALSE, $id = NULL, $return = 'title') {
1283 $cacheKey = $id . '_' .$return;
1284 if (empty(self
::$paymentProcessorType[$cacheKey])) {
1285 self
::populate(self
::$paymentProcessorType[$cacheKey], 'CRM_Financial_DAO_PaymentProcessorType', $all, $return, 'is_active', NULL, "is_default, $return", 'id');
1287 if ($id && CRM_Utils_Array
::value($id, self
::$paymentProcessorType[$cacheKey])) {
1288 return self
::$paymentProcessorType[$cacheKey][$id];
1290 return self
::$paymentProcessorType[$cacheKey];
1294 * Get all the World Regions from Database
1298 * @return array - array reference of all World Regions
1301 public static function &worldRegion($id = FALSE) {
1302 if (!self
::$worldRegions) {
1303 self
::populate(self
::$worldRegions, 'CRM_Core_DAO_Worldregion', TRUE, 'name', NULL, NULL, 'id');
1307 if (array_key_exists($id, self
::$worldRegions)) {
1308 return self
::$worldRegions[$id];
1311 return CRM_Core_DAO
::$_nullObject;
1315 return self
::$worldRegions;
1319 * Get all Activity Statuses.
1321 * The static array activityStatus is returned
1326 * @return array - array reference of all activity statuses
1328 public static function &activityStatus($column = 'label') {
1329 if (NULL === self
::$activityStatus) {
1330 self
::$activityStatus = array();
1332 if (!array_key_exists($column, self
::$activityStatus)) {
1333 self
::$activityStatus[$column] = array();
1335 self
::$activityStatus[$column] = CRM_Core_OptionGroup
::values('activity_status', FALSE, FALSE, FALSE, NULL, $column);
1338 return self
::$activityStatus[$column];
1342 * Get all Visibility levels.
1344 * The static array visibility is returned
1349 * @return array - array reference of all Visibility levels.
1352 public static function &visibility($column = 'label') {
1353 if (!isset(self
::$visibility)) {
1354 self
::$visibility = array( );
1357 if (!isset(self
::$visibility[$column])) {
1358 self
::$visibility[$column] = CRM_Core_OptionGroup
::values('visibility', FALSE, FALSE, FALSE, NULL, $column);
1361 return self
::$visibility[$column];
1364 public static function &stateProvinceForCountry($countryID, $field = 'name') {
1365 static $_cache = NULL;
1367 $cacheKey = "{$countryID}_{$field}";
1372 if (!empty($_cache[$cacheKey])) {
1373 return $_cache[$cacheKey];
1377 SELECT civicrm_state_province.{$field} name, civicrm_state_province.id id
1378 FROM civicrm_state_province
1379 WHERE country_id = %1
1388 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1391 while ($dao->fetch()) {
1392 $result[$dao->id
] = $dao->name
;
1395 // localise the stateProvince names if in an non-en_US locale
1396 $config = CRM_Core_Config
::singleton();
1398 if ($tsLocale != '' and $tsLocale != 'en_US') {
1399 $i18n = CRM_Core_I18n
::singleton();
1400 $i18n->localizeArray($result, array(
1401 'context' => 'province',
1403 $result = CRM_Utils_Array
::asort($result);
1406 $_cache[$cacheKey] = $result;
1408 CRM_Utils_Hook
::buildStateProvinceForCountry($countryID, $result);
1413 public static function &countyForState($stateID) {
1414 if (is_array($stateID)) {
1415 $states = implode(", ", $stateID);
1417 SELECT civicrm_county.name name, civicrm_county.id id, civicrm_state_province.abbreviation abbreviation
1419 LEFT JOIN civicrm_state_province ON civicrm_county.state_province_id = civicrm_state_province.id
1420 WHERE civicrm_county.state_province_id in ( $states )
1421 ORDER BY civicrm_state_province.abbreviation, civicrm_county.name";
1423 $dao = CRM_Core_DAO
::executeQuery($query);
1426 while ($dao->fetch()) {
1427 $result[$dao->id
] = $dao->abbreviation
. ': ' . $dao->name
;
1432 static $_cache = NULL;
1434 $cacheKey = "{$stateID}_name";
1439 if (!empty($_cache[$cacheKey])) {
1440 return $_cache[$cacheKey];
1444 SELECT civicrm_county.name name, civicrm_county.id id
1446 WHERE state_province_id = %1
1455 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1458 while ($dao->fetch()) {
1459 $result[$dao->id
] = $dao->name
;
1467 * Given a state ID return the country ID, this allows
1468 * us to populate forms and values for downstream code
1470 * @param $stateID int
1472 * @return int the country id that the state belongs to
1476 static function countryIDForStateID($stateID) {
1477 if (empty($stateID)) {
1478 return CRM_Core_DAO
::$_nullObject;
1483 FROM civicrm_state_province
1486 $params = array(1 => array($stateID, 'Integer'));
1488 return CRM_Core_DAO
::singleValueQuery($query, $params);
1492 * Get all types of Greetings.
1494 * The static array of greeting is returned
1499 * @param $filter - get All Email Greetings - default is to get only active ones.
1501 * @return array - array reference of all greetings.
1504 public static function greeting($filter, $columnName = 'label') {
1505 $index = $filter['greeting_type'] . '_' . $columnName;
1507 // also add contactType to the array
1508 $contactType = CRM_Utils_Array
::value('contact_type', $filter);
1510 $index .= '_' . $contactType;
1513 if (NULL === self
::$greeting) {
1514 self
::$greeting = array();
1517 if (!CRM_Utils_Array
::value($index, self
::$greeting)) {
1518 $filterCondition = NULL;
1520 $filterVal = 'v.filter =';
1521 switch ($contactType) {
1530 case 'Organization':
1534 $filterCondition .= "AND (v.filter = 0 OR {$filterVal}) ";
1537 self
::$greeting[$index] = CRM_Core_OptionGroup
::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName);
1540 return self
::$greeting[$index];
1544 * Construct array of default greeting values for contact type
1549 * @return array - array reference of default greetings.
1552 public static function &greetingDefaults() {
1553 if (!self
::$greetingDefaults) {
1554 $defaultGreetings = array();
1555 $contactTypes = self
::get('CRM_Contact_DAO_Contact', 'contact_type', array('keyColumn' => 'id', 'labelColumn' => 'name'));
1557 foreach ($contactTypes as $filter => $contactType) {
1558 $filterCondition = " AND (v.filter = 0 OR v.filter = $filter) AND v.is_default = 1 ";
1560 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
1561 $tokenVal = CRM_Core_OptionGroup
::values($greeting, NULL, NULL, NULL, $filterCondition, 'label');
1562 $defaultGreetings[$contactType][$greeting] = $tokenVal;
1566 self
::$greetingDefaults = $defaultGreetings;
1569 return self
::$greetingDefaults;
1573 * Get all the Languages from database.
1578 * @return array self::languages - array reference of all languages
1581 public static function &languages() {
1582 return CRM_Core_I18n_PseudoConstant
::languages();
1588 public static function &preferredLanguage() {
1589 return CRM_Core_I18n_PseudoConstant
::languages();
1593 * Get all extensions
1595 * The static array extensions
1597 * FIXME: This is called by civix but not by any core code. We
1598 * should provide an API call which civix can use instead.
1603 * @return array - array($fullyQualifiedName => $label) list of extensions
1605 public static function &getExtensions() {
1606 if (!self
::$extensions) {
1607 self
::$extensions = array();
1609 SELECT full_name, label
1610 FROM civicrm_extension
1613 $dao = CRM_Core_DAO
::executeQuery($sql);
1614 while ($dao->fetch()) {
1615 self
::$extensions[$dao->full_name
] = $dao->label
;
1619 return self
::$extensions;
1623 * Fetch the list of active extensions of type 'module'
1625 * @param $fresh bool whether to forcibly reload extensions list from canonical store
1629 * @return array - array(array('prefix' => $, 'file' => $))
1631 public static function getModuleExtensions($fresh = FALSE) {
1632 return CRM_Extension_System
::singleton()->getMapper()->getActiveModuleFiles($fresh);