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 $locationType;
71 private static $locationVcardName;
74 * location display name
78 private static $locationDisplayName;
85 private static $activityType;
88 * payment processor billing modes
92 private static $billingMode;
99 private static $component;
106 private static $individualPrefix;
113 private static $individualSuffix;
120 private static $gender;
127 private static $imProvider;
134 private static $websiteType;
141 private static $fromEmailAddress;
148 private static $stateProvince;
155 private static $county;
158 * states/provinces abbreviations
162 private static $stateProvinceAbbreviation;
169 private static $country;
176 private static $countryIsoCode;
190 private static $group;
197 private static $groupIterator;
204 private static $relationshipType;
207 * civicrm groups that are not smart groups
211 private static $staticGroup;
214 * user framework groups
218 private static $ufGroup;
225 private static $customGroup;
232 private static $currencyCode;
239 private static $currencySymbols;
242 * preferred communication methods
253 private static $paymentProcessor;
256 * payment processor types
260 private static $paymentProcessorType;
267 private static $worldRegions;
274 private static $honorType;
281 private static $activityStatus;
288 private static $priority;
295 private static $wysiwygEditor;
302 private static $mappingType;
309 private static $phoneType;
316 private static $visibility;
323 private static $mailProtocol;
330 private static $greeting;
337 private static $greetingDefaults;
340 * Extensions of type module
344 private static $extensions;
351 private static $activityContacts;
358 private static $eventContacts;
365 private static $autoRenew;
372 private static $batchModes;
379 private static $batchTypes;
382 * batch status options
386 private static $batchStatues;
393 private static $contactType;
396 * Financial Account Type
400 private static $accountOptionValues;
403 * Get options for a given field.
404 * @param String $daoName
405 * @param String $fieldName
406 * @param Array $params
408 * @return Array on success, FALSE on error.
412 public static function get($daoName, $fieldName, $params = array()) {
414 $fields = $dao->fields();
415 $fieldSpec = $fields[$fieldName];
417 // If the field is an enum, use explode the enum definition and return the array.
418 if (array_key_exists('enumValues', $fieldSpec)) {
419 // use of a space after the comma is inconsistent in xml
420 $enumStr = str_replace(', ', ',', $fieldSpec['enumValues']);
421 return explode(',', $enumStr);
423 elseif (!empty($fieldSpec['pseudoconstant'])) {
424 $pseudoconstant = $fieldSpec['pseudoconstant'];
425 if(!empty($pseudoconstant['optionGroupName'])) {
426 // Translate $params array into function arguments;
427 // populate default function params if not supplied in the array.
428 $ret = CRM_Core_OptionGroup
::values(
429 $pseudoconstant['optionGroupName'],
430 CRM_Utils_Array
::value('flip', $params, FALSE),
431 CRM_Utils_Array
::value('grouping', $params, FALSE),
432 CRM_Utils_Array
::value('localize', $params, FALSE),
433 CRM_Utils_Array
::value('condition', $params, NULL),
434 CRM_Utils_Array
::value('labelColumnName', $params, 'label'),
435 CRM_Utils_Array
::value('onlyActive', $params, TRUE),
436 CRM_Utils_Array
::value('fresh', $params, FALSE)
440 if (!empty($pseudoconstant['table'])) {
441 // Sort params so the serialized string will be consistent.
443 $cacheKey = "{$daoName}{$fieldName}" . serialize($params);
445 if (isset(self
::$cache[$cacheKey])) {
446 return self
::$cache[$cacheKey];
451 %1 AS id, %2 AS label
455 if (!empty($pseudoconstant['condition'])) {
456 $query .= " WHERE {$pseudoconstant['condition']}";
458 $query .= " ORDER BY %2";
459 $queryParams = array(
460 1 => array($pseudoconstant['keyColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
461 2 => array($pseudoconstant['labelColumn'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
462 3 => array($pseudoconstant['table'], 'String', CRM_Core_DAO
::QUERY_FORMAT_NO_QUOTES
),
465 self
::$cache[$cacheKey] = array();
466 $dao = CRM_Core_DAO
::executeQuery($query, $queryParams);
467 while ($dao->fetch()) {
468 self
::$cache[$cacheKey][$dao->id
] = $dao->label
;
470 return self
::$cache[$cacheKey];
473 // If we're still here, it's an error. Return FALSE.
478 * populate the object from the database. generic populate
481 * The static array $var is populated from the db
482 * using the <b>$name DAO</b>.
484 * Note: any database errors will be trapped by the DAO.
486 * @param array $var the associative array we will fill
487 * @param string $name the name of the DAO
488 * @param boolean $all get all objects. default is to get only active ones.
489 * @param string $retrieve the field that we are interested in (normally name, differs in some objects)
490 * @param string $filter the field that we want to filter the result set with
491 * @param string $condition the condition that gets passed to the final query as the WHERE clause
497 public static function populate(
502 $filter = 'is_active',
508 $cacheKey = "CRM_PC_{$name}_{$all}_{$key}_{$retrieve}_{$filter}_{$condition}_{$orderby}";
509 $cache = CRM_Utils_Cache
::singleton();
510 $var = $cache->get($cacheKey);
511 if ($var && empty($force)) {
515 $object = new $name ( );
517 $object->selectAdd();
518 $object->selectAdd("$key, $retrieve");
520 $object->whereAdd($condition);
524 $object->orderBy($retrieve);
527 $object->orderBy($orderby);
531 $object->$filter = 1;
536 while ($object->fetch()) {
537 $var[$object->$key] = $object->$retrieve;
540 $cache->set($cacheKey, $var);
544 * Flush given pseudoconstant so it can be reread from db
545 * nex time it's requested.
550 * @param boolean $name pseudoconstant to be flushed
553 public static function flush($name) {
554 if (isset(self
::$
$name)) {
560 * Get all location types.
562 * The static array locationType is returned
567 * @param boolean $all - get All location types - default is to get only active ones.
569 * @return array - array reference of all location types.
572 public static function &locationType($all = FALSE) {
573 if (!self
::$locationType) {
574 self
::populate(self
::$locationType, 'CRM_Core_DAO_LocationType', $all);
576 return self
::$locationType;
580 * Get all location vCard names.
582 * The static array locationVcardName is returned
587 * @param boolean $all - get All location vCard names - default is to get only active ones.
589 * @return array - array reference of all location vCard names.
592 public static function &locationVcardName($all = FALSE) {
593 if (!self
::$locationVcardName) {
594 self
::populate(self
::$locationVcardName, 'CRM_Core_DAO_LocationType', $all, 'vcard_name');
596 return self
::$locationVcardName;
600 * Get all location Display names.
602 * The static array locationDisplayName is returned
607 * @param boolean $all - get All location display names - default is to get only active ones.
609 * @return array - array reference of all location display names.
612 public static function &locationDisplayName($all = FALSE) {
613 if (!self
::$locationDisplayName) {
614 self
::populate(self
::$locationDisplayName, 'CRM_Core_DAO_LocationType', $all, 'display_name');
616 return self
::$locationDisplayName;
620 * Get all Activty types.
622 * The static array activityType is returned
624 * @param boolean $all - get All Activity types - default is to get only active ones.
629 * @return array - array reference of all activity types.
631 public static function &activityType() {
632 $args = func_get_args();
633 $all = CRM_Utils_Array
::value(0, $args, TRUE);
634 $includeCaseActivities = CRM_Utils_Array
::value(1, $args, FALSE);
635 $reset = CRM_Utils_Array
::value(2, $args, FALSE);
636 $returnColumn = CRM_Utils_Array
::value(3, $args, 'label');
637 $includeCampaignActivities = CRM_Utils_Array
::value(4, $args, FALSE);
638 $onlyComponentActivities = CRM_Utils_Array
::value(5, $args, FALSE);
639 $index = (int) $all . '_' . $returnColumn . '_' . (int) $includeCaseActivities;
640 $index .= '_' . (int) $includeCampaignActivities;
641 $index .= '_' . (int) $onlyComponentActivities;
643 if (NULL === self
::$activityType) {
644 self
::$activityType = array();
647 if (!isset(self
::$activityType[$index]) ||
$reset) {
650 $condition = 'AND filter = 0';
652 $componentClause = " v.component_id IS NULL";
653 if ($onlyComponentActivities) {
654 $componentClause = " v.component_id IS NOT NULL";
657 $componentIds = array();
658 $compInfo = CRM_Core_Component
::getEnabledComponents();
660 // build filter for listing activity types only if their
661 // respective components are enabled
662 foreach ($compInfo as $compName => $compObj) {
663 if ($compName == 'CiviCase') {
664 if ($includeCaseActivities) {
665 $componentIds[] = $compObj->componentID
;
668 elseif ($compName == 'CiviCampaign') {
669 if ($includeCampaignActivities) {
670 $componentIds[] = $compObj->componentID
;
674 $componentIds[] = $compObj->componentID
;
678 if (count($componentIds)) {
679 $componentIds = implode(',', $componentIds);
680 $componentClause = " ($componentClause OR v.component_id IN ($componentIds))";
681 if ($onlyComponentActivities) {
682 $componentClause = " ( v.component_id IN ($componentIds ) )";
685 $condition = $condition . ' AND ' . $componentClause;
687 self
::$activityType[$index] = CRM_Core_OptionGroup
::values('activity_type', FALSE, FALSE, FALSE, $condition, $returnColumn);
689 return self
::$activityType[$index];
693 * Get all payment-processor billing modes
698 * @return array ($id => $name)
700 public static function billingMode() {
701 if (!self
::$billingMode) {
702 self
::$billingMode = array(
703 CRM_Core_Payment
::BILLING_MODE_FORM
=> 'form',
704 CRM_Core_Payment
::BILLING_MODE_BUTTON
=> 'button',
705 CRM_Core_Payment
::BILLING_MODE_NOTIFY
=> 'notify',
708 return self
::$billingMode;
712 * Get all component names
717 * @return array - array reference of all location display names.
720 public static function &component() {
721 if (!self
::$component) {
722 self
::populate(self
::$component, 'CRM_Core_DAO_Component', TRUE, 'name');
724 return self
::$component;
729 * Get all Individual Prefix.
731 * The static array individualPrefix is returned
736 * @param boolean $all - get All Individual Prefix - default is to get only active ones.
738 * @return array - array reference of all individual prefix.
741 public static function &individualPrefix() {
742 if (!self
::$individualPrefix) {
743 self
::$individualPrefix = CRM_Core_OptionGroup
::values('individual_prefix');
745 return self
::$individualPrefix;
750 * The static array phoneType is returned
755 * @param boolean $all - get All phone type - default is to get
758 * @return array - array reference of all phone types.
761 public static function &phoneType() {
762 if (!self
::$phoneType) {
763 self
::$phoneType = CRM_Core_OptionGroup
::values('phone_type');
765 return self
::$phoneType;
769 * Get all Individual Suffix.
771 * The static array individualSuffix is returned
776 * @param boolean $all - get All Individual Suffix - default is to get only active ones.
778 * @return array - array reference of all individual suffix.
781 public static function &individualSuffix() {
782 if (!self
::$individualSuffix) {
783 self
::$individualSuffix = CRM_Core_OptionGroup
::values('individual_suffix');
785 return self
::$individualSuffix;
791 * The static array gender is returned
796 * @param boolean $all - get All Gender - default is to get only active ones.
798 * @return array - array reference of all gender.
801 public static function &gender($localize = FALSE) {
802 if (!self
::$gender) {
803 self
::$gender = CRM_Core_OptionGroup
::values('gender', FALSE, FALSE, $localize);
805 return self
::$gender;
809 * Get all the IM Providers from database.
811 * The static array imProvider is returned, and if it's
812 * called the first time, the <b>IM DAO</b> is used
813 * to get all the IM Providers.
815 * Note: any database errors will be trapped by the DAO.
820 * @return array - array reference of all IM providers.
823 public static function &IMProvider($localize = FALSE) {
824 if (!self
::$imProvider) {
825 self
::$imProvider = CRM_Core_OptionGroup
::values('instant_messenger_service', FALSE, FALSE, $localize);
827 return self
::$imProvider;
831 * Get all the website types from database.
833 * The static array websiteType is returned, and if it's
834 * called the first time, the <b>Website DAO</b> is used
835 * to get all the Website Types.
837 * Note: any database errors will be trapped by the DAO.
842 * @return array - array reference of all Website types.
845 public static function &websiteType() {
846 if (!self
::$websiteType) {
847 self
::$websiteType = CRM_Core_OptionGroup
::values('website_type');
849 return self
::$websiteType;
853 * Get the all From Email Address from database.
855 * The static array $fromEmailAddress is returned, and if it's
856 * called the first time, DAO is used
857 * to get all the From Email Address
859 * Note: any database errors will be trapped by the DAO.
864 * @return array - array reference of all From Email Address.
866 public static function &fromEmailAddress() {
867 if (!self
::$fromEmailAddress) {
868 self
::$fromEmailAddress = CRM_Core_OptionGroup
::values('from_email_address');
870 return self
::$fromEmailAddress;
874 * Get the all Mail Protocols from database.
876 * The static array mailProtocol is returned, and if it's
877 * called the first time, the DAO is used
878 * to get all the Mail Protocol.
880 * Note: any database errors will be trapped by the DAO.
885 * @return array - array reference of all Mail Protocols.
887 public static function &mailProtocol() {
888 if (!self
::$mailProtocol) {
889 self
::$mailProtocol = CRM_Core_OptionGroup
::values('mail_protocol');
891 return self
::$mailProtocol;
895 * Get all the State/Province from database.
897 * The static array stateProvince is returned, and if it's
898 * called the first time, the <b>State Province DAO</b> is used
899 * to get all the States.
901 * Note: any database errors will be trapped by the DAO.
906 * @param int $id - Optional id to return
908 * @return array - array reference of all State/Provinces.
911 public static function &stateProvince($id = FALSE, $limit = TRUE) {
912 if (($id && !CRM_Utils_Array
::value($id, self
::$stateProvince)) ||
!self
::$stateProvince ||
!$id) {
913 $whereClause = FALSE;
914 $config = CRM_Core_Config
::singleton();
916 $countryIsoCodes = self
::countryIsoCode();
917 $limitCodes = $config->provinceLimit();
919 foreach ($limitCodes as $code) {
920 $limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
922 if (!empty($limitIds)) {
923 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
926 $whereClause = FALSE;
929 self
::populate(self
::$stateProvince, 'CRM_Core_DAO_StateProvince', TRUE, 'name', 'is_active', $whereClause);
931 // localise the province names if in an non-en_US locale
933 if ($tsLocale != '' and $tsLocale != 'en_US') {
934 $i18n = CRM_Core_I18n
::singleton();
935 $i18n->localizeArray(self
::$stateProvince, array(
936 'context' => 'province',
938 self
::$stateProvince = CRM_Utils_Array
::asort(self
::$stateProvince);
942 if (array_key_exists($id, self
::$stateProvince)) {
943 return self
::$stateProvince[$id];
950 return self
::$stateProvince;
954 * Get all the State/Province abbreviations from the database.
956 * Same as above, except gets the abbreviations instead of the names.
961 * @param int $id - Optional id to return
963 * @return array - array reference of all State/Province abbreviations.
965 public static function &stateProvinceAbbreviation($id = FALSE, $limit = TRUE) {
969 FROM civicrm_state_province
977 return CRM_Core_DAO
::singleValueQuery($query, $params);
980 if (!self
::$stateProvinceAbbreviation ||
!$id) {
982 $whereClause = FALSE;
985 $config = CRM_Core_Config
::singleton();
986 $countryIsoCodes = self
::countryIsoCode();
987 $limitCodes = $config->provinceLimit();
989 foreach ($limitCodes as $code) {
990 $tmpArray = array_keys($countryIsoCodes, $code);
992 if (!empty($tmpArray)) {
993 $limitIds[] = array_shift($tmpArray);
996 if (!empty($limitIds)) {
997 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
1000 self
::populate(self
::$stateProvinceAbbreviation, 'CRM_Core_DAO_StateProvince', TRUE, 'abbreviation', 'is_active', $whereClause);
1004 if (array_key_exists($id, self
::$stateProvinceAbbreviation)) {
1005 return self
::$stateProvinceAbbreviation[$id];
1012 return self
::$stateProvinceAbbreviation;
1016 * Get all the countries from database.
1018 * The static array country is returned, and if it's
1019 * called the first time, the <b>Country DAO</b> is used
1020 * to get all the countries.
1022 * Note: any database errors will be trapped by the DAO.
1027 * @param int $id - Optional id to return
1029 * @return array - array reference of all countries.
1032 public static function country($id = FALSE, $applyLimit = TRUE) {
1033 if (($id && !CRM_Utils_Array
::value($id, self
::$country)) ||
!self
::$country ||
!$id) {
1035 $config = CRM_Core_Config
::singleton();
1036 $limitCodes = array();
1039 // limit the country list to the countries specified in CIVICRM_COUNTRY_LIMIT
1040 // (ensuring it's a subset of the legal values)
1041 // K/P: We need to fix this, i dont think it works with new setting files
1042 $limitCodes = $config->countryLimit();
1043 if (!is_array($limitCodes)) {
1044 $limitCodes = array(
1045 $config->countryLimit
=> 1,
1049 $limitCodes = array_intersect(self
::countryIsoCode(), $limitCodes);
1052 if (count($limitCodes)) {
1053 $whereClause = "iso_code IN ('" . implode("', '", $limitCodes) . "')";
1056 $whereClause = NULL;
1059 self
::populate(self
::$country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active', $whereClause);
1061 // if default country is set, percolate it to the top
1062 if ($config->defaultContactCountry()) {
1063 $countryIsoCodes = self
::countryIsoCode();
1064 $defaultID = array_search($config->defaultContactCountry(), $countryIsoCodes);
1065 if ($defaultID !== FALSE) {
1066 $default[$defaultID] = CRM_Utils_Array
::value($defaultID, self
::$country);
1067 self
::$country = $default + self
::$country;
1071 // localise the country names if in an non-en_US locale
1073 if ($tsLocale != '' and $tsLocale != 'en_US') {
1074 $i18n = CRM_Core_I18n
::singleton();
1075 $i18n->localizeArray(self
::$country, array(
1076 'context' => 'country',
1078 self
::$country = CRM_Utils_Array
::asort(self
::$country);
1082 if (array_key_exists($id, self
::$country)) {
1083 return self
::$country[$id];
1086 return CRM_Core_DAO
::$_nullObject;
1089 return self
::$country;
1093 * Get all the country ISO Code abbreviations from the database.
1095 * The static array countryIsoCode is returned, and if it's
1096 * called the first time, the <b>Country DAO</b> is used
1097 * to get all the countries' ISO codes.
1099 * Note: any database errors will be trapped by the DAO.
1104 * @return array - array reference of all country ISO codes.
1107 public static function &countryIsoCode($id = FALSE) {
1108 if (!self
::$countryIsoCode) {
1109 self
::populate(self
::$countryIsoCode, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
1112 if (array_key_exists($id, self
::$countryIsoCode)) {
1113 return self
::$countryIsoCode[$id];
1116 return CRM_Core_DAO
::$_nullObject;
1119 return self
::$countryIsoCode;
1123 * Get all the categories from database.
1125 * The static array tag is returned, and if it's
1126 * called the first time, the <b>Tag DAO</b> is used
1127 * to get all the categories.
1129 * Note: any database errors will be trapped by the DAO.
1134 * @return array - array reference of all categories.
1137 public static function &tag() {
1139 self
::populate(self
::$tag, 'CRM_Core_DAO_Tag', TRUE);
1145 * Get all groups from database
1147 * The static array group is returned, and if it's
1148 * called the first time, the <b>Group DAO</b> is used
1149 * to get all the groups.
1151 * Note: any database errors will be trapped by the DAO.
1153 * @param string $groupType type of group(Access/Mailing)
1154 * @param boolen $excludeHidden exclude hidden groups.
1159 * @return array - array reference of all groups.
1162 public static function &allGroup($groupType = NULL, $excludeHidden = TRUE) {
1163 $condition = CRM_Contact_BAO_Group
::groupTypeCondition($groupType, $excludeHidden);
1165 if (!self
::$group) {
1166 self
::$group = array();
1169 $groupKey = $groupType ?
$groupType : 'null';
1171 if (!isset(self
::$group[$groupKey])) {
1172 self
::$group[$groupKey] = NULL;
1173 self
::populate(self
::$group[$groupKey], 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition);
1175 return self
::$group[$groupKey];
1179 * Create or get groups iterator (iterates over nested groups in a
1182 * The GroupNesting instance is returned; it's created if this is being
1183 * called for the first time
1189 * @return mixed - instance of CRM_Contact_BAO_GroupNesting
1192 public static function &groupIterator($styledLabels = FALSE) {
1193 if (!self
::$groupIterator) {
1195 When used as an object, GroupNesting implements Iterator
1196 and iterates nested groups in a logical manner for us
1198 self
::$groupIterator = new CRM_Contact_BAO_GroupNesting($styledLabels);
1200 return self
::$groupIterator;
1204 * Get all permissioned groups from database
1206 * The static array group is returned, and if it's
1207 * called the first time, the <b>Group DAO</b> is used
1208 * to get all the groups.
1210 * Note: any database errors will be trapped by the DAO.
1212 * @param string $groupType type of group(Access/Mailing)
1213 * @param boolen $excludeHidden exclude hidden groups.
1218 * @return array - array reference of all groups.
1221 public static function group($groupType = NULL, $excludeHidden = TRUE) {
1222 return CRM_Core_Permission
::group($groupType, $excludeHidden);
1226 * Get all permissioned groups from database
1228 * The static array group is returned, and if it's
1229 * called the first time, the <b>Group DAO</b> is used
1230 * to get all the groups.
1232 * Note: any database errors will be trapped by the DAO.
1237 * @return array - array reference of all groups.
1240 public static function &staticGroup($onlyPublic = FALSE, $groupType = NULL, $excludeHidden = TRUE) {
1241 if (!self
::$staticGroup) {
1242 $condition = 'saved_search_id = 0 OR saved_search_id IS NULL';
1244 $condition .= " AND visibility != 'User and User Admin Only'";
1248 $condition .= ' AND ' . CRM_Contact_BAO_Group
::groupTypeCondition($groupType);
1251 if ($excludeHidden) {
1252 $condition .= ' AND is_hidden != 1 ';
1255 self
::populate(self
::$staticGroup, 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition, 'title');
1258 return self
::$staticGroup;
1262 * Get all the custom groups
1266 * @return array - array reference of all groups.
1269 public static function &customGroup($reset = FALSE) {
1270 if (!self
::$customGroup ||
$reset) {
1271 self
::populate(self
::$customGroup, 'CRM_Core_DAO_CustomGroup', FALSE, 'title', 'is_active', NULL, 'title');
1273 return self
::$customGroup;
1277 * Get all the user framework groups
1281 * @return array - array reference of all groups.
1284 public static function &ufGroup() {
1285 if (!self
::$ufGroup) {
1286 self
::populate(self
::$ufGroup, 'CRM_Core_DAO_UFGroup', FALSE, 'title', 'is_active', NULL, 'title');
1288 return self
::$ufGroup;
1292 * Get all Relationship Types from database.
1294 * The static array group is returned, and if it's
1295 * called the first time, the <b>RelationshipType DAO</b> is used
1296 * to get all the relationship types.
1298 * Note: any database errors will be trapped by the DAO.
1300 * @param string $valueColumnName db column name/label.
1301 * @param boolean $reset reset relationship types if true
1306 * @return array - array reference of all relationship types.
1308 public static function &relationshipType($valueColumnName = 'label', $reset = FALSE) {
1309 if (!CRM_Utils_Array
::value($valueColumnName, self
::$relationshipType) ||
$reset) {
1310 self
::$relationshipType[$valueColumnName] = array();
1312 //now we have name/label columns CRM-3336
1313 $column_a_b = "{$valueColumnName}_a_b";
1314 $column_b_a = "{$valueColumnName}_b_a";
1316 $relationshipTypeDAO = new CRM_Contact_DAO_RelationshipType();
1317 $relationshipTypeDAO->selectAdd();
1318 $relationshipTypeDAO->selectAdd("id, {$column_a_b}, {$column_b_a}, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b");
1319 $relationshipTypeDAO->is_active
= 1;
1320 $relationshipTypeDAO->find();
1321 while ($relationshipTypeDAO->fetch()) {
1323 self
::$relationshipType[$valueColumnName][$relationshipTypeDAO->id
] = array(
1324 $column_a_b => $relationshipTypeDAO->$column_a_b,
1325 $column_b_a => $relationshipTypeDAO->$column_b_a,
1326 'contact_type_a' => "$relationshipTypeDAO->contact_type_a",
1327 'contact_type_b' => "$relationshipTypeDAO->contact_type_b",
1328 'contact_sub_type_a' => "$relationshipTypeDAO->contact_sub_type_a",
1329 'contact_sub_type_b' => "$relationshipTypeDAO->contact_sub_type_b",
1334 return self
::$relationshipType[$valueColumnName];
1338 * Get all the Currency Symbols from Database
1342 * @return array - array reference of all Currency Symbols
1345 public static function ¤cySymbols($name = 'symbol', $key = 'id') {
1346 $cacheKey = "{$name}_{$key}";
1347 if (!isset(self
::$currencySymbols[$cacheKey])) {
1348 self
::populate(self
::$currencySymbols[$cacheKey], 'CRM_Financial_DAO_Currency', TRUE, $name, NULL, NULL, 'name', $key);
1351 return self
::$currencySymbols[$cacheKey];
1355 * get all the ISO 4217 currency codes
1357 * so far, we use this for validation only, so there's no point of putting this into the database
1361 * @return array - array reference of all currency codes
1364 public static function ¤cyCode() {
1365 if (!self
::$currencyCode) {
1366 self
::$currencyCode = array(
1636 return self
::$currencyCode;
1640 * Get all the County from database.
1642 * The static array county is returned, and if it's
1643 * called the first time, the <b>County DAO</b> is used
1644 * to get all the Counties.
1646 * Note: any database errors will be trapped by the DAO.
1651 * @param int $id - Optional id to return
1653 * @return array - array reference of all Counties
1656 public static function &county($id = FALSE) {
1657 if (!self
::$county) {
1659 $config = CRM_Core_Config
::singleton();
1660 // order by id so users who populate civicrm_county can have more control over sort by the order they load the counties
1661 self
::populate(self
::$county, 'CRM_Core_DAO_County', TRUE, 'name', NULL, NULL, 'id');
1664 if (array_key_exists($id, self
::$county)) {
1665 return self
::$county[$id];
1668 return CRM_Core_DAO
::$_nullObject;
1671 return self
::$county;
1675 * Get all the Preferred Communication Methods from database.
1680 * @return array self::pcm - array reference of all preferred communication methods.
1683 public static function &pcm($localize = FALSE) {
1685 self
::$pcm = CRM_Core_OptionGroup
::values('preferred_communication_method', FALSE, FALSE, $localize);
1693 public static function preferredCommunicationMethod($localize = FALSE) {
1694 return self
::pcm($localize);
1698 * Get all active payment processors
1700 * The static array paymentProcessor is returned
1705 * @param boolean $all - get payment processors - default is to get only active ones.
1706 * @param boolean $test - get test payment processors
1708 * @return array - array of all payment processors
1711 public static function &paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
1712 $condition = "is_test = ";
1713 $condition .= ($test) ?
'1' : '0';
1715 if ($additionalCond) {
1716 $condition .= " AND ( $additionalCond ) ";
1719 // CRM-7178. Make sure we only include payment processors valid in ths
1721 $condition .= " AND domain_id = " . CRM_Core_Config
::domainID();
1723 $cacheKey = $condition . '_' . (int) $all;
1724 if (!isset(self
::$paymentProcessor[$cacheKey])) {
1725 self
::populate(self
::$paymentProcessor[$cacheKey], 'CRM_Financial_DAO_PaymentProcessor', $all, 'name', 'is_active', $condition, 'is_default desc, name');
1728 return self
::$paymentProcessor[$cacheKey];
1732 * Get all active payment processors
1734 * The static array paymentProcessorType is returned
1739 * @param boolean $all - get payment processors - default is to get only active ones.
1741 * @return array - array of all payment processor types
1744 public static function &paymentProcessorType($all = FALSE, $id = NULL, $return = 'title') {
1745 $cacheKey = $id . '_' .$return;
1746 if (empty(self
::$paymentProcessorType[$cacheKey])) {
1747 self
::populate(self
::$paymentProcessorType[$cacheKey], 'CRM_Financial_DAO_PaymentProcessorType', $all, $return, 'is_active', NULL, "is_default, $return", 'id');
1749 if ($id && CRM_Utils_Array
::value($id, self
::$paymentProcessorType[$cacheKey])) {
1750 return self
::$paymentProcessorType[$cacheKey][$id];
1752 return self
::$paymentProcessorType[$cacheKey];
1756 * Get all the World Regions from Database
1760 * @return array - array reference of all World Regions
1763 public static function &worldRegion($id = FALSE) {
1764 if (!self
::$worldRegions) {
1765 self
::populate(self
::$worldRegions, 'CRM_Core_DAO_Worldregion', TRUE, 'name', NULL, NULL, 'id');
1769 if (array_key_exists($id, self
::$worldRegions)) {
1770 return self
::$worldRegions[$id];
1773 return CRM_Core_DAO
::$_nullObject;
1777 return self
::$worldRegions;
1781 * Get all Honor Type.
1783 * The static array honorType is returned
1788 * @param boolean $all - get All Honor Type.
1790 * @return array - array reference of all Honor Types.
1793 public static function &honor() {
1794 if (!self
::$honorType) {
1795 self
::$honorType = CRM_Core_OptionGroup
::values('honor_type');
1797 return self
::$honorType;
1801 * Get all Activity Statuses.
1803 * The static array activityStatus is returned
1808 * @return array - array reference of all activity statuses
1810 public static function &activityStatus($column = 'label') {
1811 if (NULL === self
::$activityStatus) {
1812 self
::$activityStatus = array();
1814 if (!array_key_exists($column, self
::$activityStatus)) {
1815 self
::$activityStatus[$column] = array();
1817 self
::$activityStatus[$column] = CRM_Core_OptionGroup
::values('activity_status', FALSE, FALSE, FALSE, NULL, $column);
1820 return self
::$activityStatus[$column];
1824 * Get all Priorities
1826 * The static array Priority is returned
1831 * @return array - array reference of all Priority
1833 public static function &priority() {
1834 if (!self
::$priority) {
1835 self
::$priority = CRM_Core_OptionGroup
::values('priority');
1838 return self
::$priority;
1842 * Get all WYSIWYG Editors.
1844 * The static array wysiwygEditor is returned
1849 * @return array - array reference of all wysiwygEditors
1851 public static function &wysiwygEditor() {
1852 if (!self
::$wysiwygEditor) {
1853 self
::$wysiwygEditor = CRM_Core_OptionGroup
::values('wysiwyg_editor');
1855 return self
::$wysiwygEditor;
1859 * Get all Visibility levels.
1861 * The static array visibility is returned
1866 * @return array - array reference of all Visibility levels.
1869 public static function &visibility($column = 'label') {
1870 if (!isset(self
::$visibility)) {
1871 self
::$visibility = array( );
1874 if (!isset(self
::$visibility[$column])) {
1875 self
::$visibility[$column] = CRM_Core_OptionGroup
::values('visibility', FALSE, FALSE, FALSE, NULL, $column);
1878 return self
::$visibility[$column];
1882 * Get all mapping types
1884 * @return array - array reference of all mapping types
1888 public static function &mappingTypes() {
1889 if (!self
::$mappingType) {
1890 self
::$mappingType = CRM_Core_OptionGroup
::values('mapping_type');
1892 return self
::$mappingType;
1895 public static function &stateProvinceForCountry($countryID, $field = 'name') {
1896 static $_cache = NULL;
1898 $cacheKey = "{$countryID}_{$field}";
1903 if (!empty($_cache[$cacheKey])) {
1904 return $_cache[$cacheKey];
1908 SELECT civicrm_state_province.{$field} name, civicrm_state_province.id id
1909 FROM civicrm_state_province
1910 WHERE country_id = %1
1919 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1922 while ($dao->fetch()) {
1923 $result[$dao->id
] = $dao->name
;
1926 // localise the stateProvince names if in an non-en_US locale
1927 $config = CRM_Core_Config
::singleton();
1929 if ($tsLocale != '' and $tsLocale != 'en_US') {
1930 $i18n = CRM_Core_I18n
::singleton();
1931 $i18n->localizeArray($result, array(
1932 'context' => 'province',
1934 $result = CRM_Utils_Array
::asort($result);
1937 $_cache[$cacheKey] = $result;
1939 CRM_Utils_Hook
::buildStateProvinceForCountry($countryID, $result);
1944 public static function &countyForState($stateID) {
1945 if (is_array($stateID)) {
1946 $states = implode(", ", $stateID);
1948 SELECT civicrm_county.name name, civicrm_county.id id, civicrm_state_province.abbreviation abbreviation
1950 LEFT JOIN civicrm_state_province ON civicrm_county.state_province_id = civicrm_state_province.id
1951 WHERE civicrm_county.state_province_id in ( $states )
1952 ORDER BY civicrm_state_province.abbreviation, civicrm_county.name";
1954 $dao = CRM_Core_DAO
::executeQuery($query);
1957 while ($dao->fetch()) {
1958 $result[$dao->id
] = $dao->abbreviation
. ': ' . $dao->name
;
1963 static $_cache = NULL;
1965 $cacheKey = "{$stateID}_name";
1970 if (!empty($_cache[$cacheKey])) {
1971 return $_cache[$cacheKey];
1975 SELECT civicrm_county.name name, civicrm_county.id id
1977 WHERE state_province_id = %1
1986 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1989 while ($dao->fetch()) {
1990 $result[$dao->id
] = $dao->name
;
1998 * Given a state ID return the country ID, this allows
1999 * us to populate forms and values for downstream code
2001 * @param $stateID int
2003 * @return int the country id that the state belongs to
2007 static function countryIDForStateID($stateID) {
2008 if (empty($stateID)) {
2009 return CRM_Core_DAO
::$_nullObject;
2014 FROM civicrm_state_province
2017 $params = array(1 => array($stateID, 'Integer'));
2019 return CRM_Core_DAO
::singleValueQuery($query, $params);
2023 * Get all types of Greetings.
2025 * The static array of greeting is returned
2030 * @param $filter - get All Email Greetings - default is to get only active ones.
2032 * @return array - array reference of all greetings.
2035 public static function greeting($filter, $columnName = 'label') {
2036 $index = $filter['greeting_type'] . '_' . $columnName;
2038 // also add contactType to the array
2039 $contactType = CRM_Utils_Array
::value('contact_type', $filter);
2041 $index .= '_' . $contactType;
2044 if (NULL === self
::$greeting) {
2045 self
::$greeting = array();
2048 if (!CRM_Utils_Array
::value($index, self
::$greeting)) {
2049 $filterCondition = NULL;
2051 $filterVal = 'v.filter =';
2052 switch ($contactType) {
2061 case 'Organization':
2065 $filterCondition .= "AND (v.filter = 0 OR {$filterVal}) ";
2068 self
::$greeting[$index] = CRM_Core_OptionGroup
::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName);
2071 return self
::$greeting[$index];
2075 * Construct array of default greeting values for contact type
2080 * @return array - array reference of default greetings.
2083 public static function &greetingDefaults() {
2084 if (!self
::$greetingDefaults) {
2085 $defaultGreetings = array();
2086 $contactTypes = array(
2089 'Organization' => 3,
2092 foreach ($contactTypes as $contactType => $filter) {
2093 $filterCondition = " AND (v.filter = 0 OR v.filter = $filter) AND v.is_default = 1 ";
2095 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
2096 $tokenVal = CRM_Core_OptionGroup
::values($greeting, NULL, NULL, NULL, $filterCondition, 'label');
2097 $defaultGreetings[$contactType][$greeting] = $tokenVal;
2101 self
::$greetingDefaults = $defaultGreetings;
2104 return self
::$greetingDefaults;
2108 * Get all the Languages from database.
2113 * @return array self::languages - array reference of all languages
2116 public static function &languages() {
2117 return CRM_Core_I18n_PseudoConstant
::languages();
2123 public static function &preferredLanguage() {
2124 return CRM_Core_I18n_PseudoConstant
::languages();
2128 * Get all extensions
2130 * The static array extensions
2132 * FIXME: This is called by civix but not by any core code. We
2133 * should provide an API call which civix can use instead.
2138 * @return array - array($fullyQualifiedName => $label) list of extensions
2140 public static function &getExtensions() {
2141 if (!self
::$extensions) {
2142 self
::$extensions = array();
2144 SELECT full_name, label
2145 FROM civicrm_extension
2148 $dao = CRM_Core_DAO
::executeQuery($sql);
2149 while ($dao->fetch()) {
2150 self
::$extensions[$dao->full_name
] = $dao->label
;
2154 return self
::$extensions;
2158 * Fetch the list of active extensions of type 'module'
2160 * @param $fresh bool whether to forcibly reload extensions list from canonical store
2164 * @return array - array(array('prefix' => $, 'file' => $))
2166 public static function getModuleExtensions($fresh = FALSE) {
2167 return CRM_Extension_System
::singleton()->getMapper()->getActiveModuleFiles($fresh);
2171 * Get all Activity Contacts
2173 * The static array activityContacts is returned
2178 * @param string $column db column name/label.
2180 * @return array - array reference of all activity Contacts
2183 public static function &activityContacts($column = 'label') {
2184 if (!self
::$activityContacts) {
2185 self
::$activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, $column);
2187 return self
::$activityContacts;
2191 * Get all Event Contacts
2193 * The static array eventContacts is returned
2198 * @param string $column db column name/label.
2200 * @return array - array reference of all event Contacts
2203 public static function &eventContacts($column = 'label') {
2204 if (!self
::$eventContacts) {
2205 self
::$eventContacts = CRM_Core_OptionGroup
::values('event_contacts', FALSE, FALSE, FALSE, NULL, $column);
2207 return self
::$eventContacts;
2211 * Get all options values
2213 * The static array option values is returned
2218 * @param boolean $optionGroupName - get All Option Group values- default is to get only active ones.
2220 * @return array - array reference of all Option Group Name
2223 public static function accountOptionValues($optionGroupName, $id = null, $condition = null) {
2224 $cacheKey = $optionGroupName . '_' . $condition;
2225 if (empty(self
::$accountOptionValues[$cacheKey])) {
2226 self
::$accountOptionValues[$cacheKey] = CRM_Core_OptionGroup
::values($optionGroupName, false, false, false, $condition);
2229 return CRM_Utils_Array
::value($id, self
::$accountOptionValues[$cacheKey]);
2232 return self
::$accountOptionValues[$cacheKey];
2236 * Get all batch modes
2238 * The static array batchModes
2243 * @return array - array reference of all batch modes
2245 public static function &getBatchMode($columnName = 'label') {
2246 if (!self
::$batchModes) {
2247 self
::$batchModes = CRM_Core_OptionGroup
::values('batch_mode', false, false, false, null, $columnName);
2250 return self
::$batchModes;
2254 * Get all batch types
2256 * The static array batchTypes
2261 * @return array - array reference of all batch types
2263 public static function &getBatchType() {
2264 if (!self
::$batchTypes) {
2265 self
::$batchTypes = CRM_Core_OptionGroup
::values('batch_type');
2268 return self
::$batchTypes;
2272 * Get all batch statuses
2274 * The static array batchStatues
2279 * @return array - array reference of all batch statuses
2281 public static function &getBatchStatus() {
2282 if (!self
::$batchStatues) {
2283 self
::$batchStatues = CRM_Core_OptionGroup
::values('batch_status');
2286 return self
::$batchStatues;
2290 * The static array contactType is returned
2294 * @param string $column db column name/label.
2296 * @return array - array reference of all Types
2300 public static function &contactType($column = 'label') {
2301 if (!self
::$contactType) {
2302 self
::$contactType = CRM_Contact_BAO_ContactType
::basicTypePairs(TRUE);
2304 return self
::$contactType;
2308 * Get all the auto renew options
2313 * @return array self::autoRenew - array reference of all autoRenew
2316 public static function &autoRenew() {
2317 if (!self
::$autoRenew) {
2318 self
::$autoRenew = CRM_Core_OptionGroup
::values('auto_renew_options', FALSE, FALSE);
2320 return self
::$autoRenew;