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
{
57 private static $locationType;
64 private static $locationVcardName;
67 * location display name
71 private static $locationDisplayName;
78 private static $activityType;
81 * payment processor billing modes
85 private static $billingMode;
92 private static $component;
99 private static $individualPrefix;
106 private static $individualSuffix;
113 private static $gender;
120 private static $imProvider;
127 private static $websiteType;
134 private static $fromEmailAddress;
141 private static $stateProvince;
148 private static $county;
151 * states/provinces abbreviations
155 private static $stateProvinceAbbreviation;
162 private static $country;
169 private static $countryIsoCode;
183 private static $group;
190 private static $groupIterator;
197 private static $relationshipType;
200 * civicrm groups that are not smart groups
204 private static $staticGroup;
207 * user framework groups
211 private static $ufGroup;
218 private static $customGroup;
225 private static $currencyCode;
232 private static $currencySymbols;
239 private static $tasks;
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 * populate the object from the database. generic populate
406 * The static array $var is populated from the db
407 * using the <b>$name DAO</b>.
409 * Note: any database errors will be trapped by the DAO.
411 * @param array $var the associative array we will fill
412 * @param string $name the name of the DAO
413 * @param boolean $all get all objects. default is to get only active ones.
414 * @param string $retrieve the field that we are interested in (normally name, differs in some objects)
415 * @param string $filter the field that we want to filter the result set with
416 * @param string $condition the condition that gets passed to the final query as the WHERE clause
422 public static function populate(
427 $filter = 'is_active',
433 $cacheKey = "CRM_PC_{$name}_{$all}_{$key}_{$retrieve}_{$filter}_{$condition}_{$orderby}";
434 $cache = CRM_Utils_Cache
::singleton();
435 $var = $cache->get($cacheKey);
436 if ($var && empty($force)) {
440 $object = new $name ( );
442 $object->selectAdd();
443 $object->selectAdd("$key, $retrieve");
445 $object->whereAdd($condition);
449 $object->orderBy($retrieve);
452 $object->orderBy($orderby);
456 $object->$filter = 1;
461 while ($object->fetch()) {
462 $var[$object->$key] = $object->$retrieve;
465 $cache->set($cacheKey, $var);
469 * Flush given pseudoconstant so it can be reread from db
470 * nex time it's requested.
475 * @param boolean $name pseudoconstant to be flushed
478 public static function flush($name) {
483 * Get all location types.
485 * The static array locationType is returned
490 * @param boolean $all - get All location types - default is to get only active ones.
492 * @return array - array reference of all location types.
495 public static function &locationType($all = FALSE) {
496 if (!self
::$locationType) {
497 self
::populate(self
::$locationType, 'CRM_Core_DAO_LocationType', $all);
499 return self
::$locationType;
503 * Get all location vCard names.
505 * The static array locationVcardName is returned
510 * @param boolean $all - get All location vCard names - default is to get only active ones.
512 * @return array - array reference of all location vCard names.
515 public static function &locationVcardName($all = FALSE) {
516 if (!self
::$locationVcardName) {
517 self
::populate(self
::$locationVcardName, 'CRM_Core_DAO_LocationType', $all, 'vcard_name');
519 return self
::$locationVcardName;
523 * Get all location Display names.
525 * The static array locationDisplayName is returned
530 * @param boolean $all - get All location display names - default is to get only active ones.
532 * @return array - array reference of all location display names.
535 public static function &locationDisplayName($all = FALSE) {
536 if (!self
::$locationDisplayName) {
537 self
::populate(self
::$locationDisplayName, 'CRM_Core_DAO_LocationType', $all, 'display_name');
539 return self
::$locationDisplayName;
543 * Get all Activty types.
545 * The static array activityType is returned
547 * @param boolean $all - get All Activity types - default is to get only active ones.
552 * @return array - array reference of all activity types.
554 public static function &activityType() {
555 $args = func_get_args();
556 $all = CRM_Utils_Array
::value(0, $args, TRUE);
557 $includeCaseActivities = CRM_Utils_Array
::value(1, $args, FALSE);
558 $reset = CRM_Utils_Array
::value(2, $args, FALSE);
559 $returnColumn = CRM_Utils_Array
::value(3, $args, 'label');
560 $includeCampaignActivities = CRM_Utils_Array
::value(4, $args, FALSE);
561 $onlyComponentActivities = CRM_Utils_Array
::value(5, $args, FALSE);
562 $index = (int) $all . '_' . $returnColumn . '_' . (int) $includeCaseActivities;
563 $index .= '_' . (int) $includeCampaignActivities;
564 $index .= '_' . (int) $onlyComponentActivities;
566 if (NULL === self
::$activityType) {
567 self
::$activityType = array();
570 if (!isset(self
::$activityType[$index]) ||
$reset) {
573 $condition = 'AND filter = 0';
575 $componentClause = " v.component_id IS NULL";
576 if ($onlyComponentActivities) {
577 $componentClause = " v.component_id IS NOT NULL";
580 $componentIds = array();
581 $compInfo = CRM_Core_Component
::getEnabledComponents();
583 // build filter for listing activity types only if their
584 // respective components are enabled
585 foreach ($compInfo as $compName => $compObj) {
586 if ($compName == 'CiviCase') {
587 if ($includeCaseActivities) {
588 $componentIds[] = $compObj->componentID
;
591 elseif ($compName == 'CiviCampaign') {
592 if ($includeCampaignActivities) {
593 $componentIds[] = $compObj->componentID
;
597 $componentIds[] = $compObj->componentID
;
601 if (count($componentIds)) {
602 $componentIds = implode(',', $componentIds);
603 $componentClause = " ($componentClause OR v.component_id IN ($componentIds))";
604 if ($onlyComponentActivities) {
605 $componentClause = " ( v.component_id IN ($componentIds ) )";
608 $condition = $condition . ' AND ' . $componentClause;
610 self
::$activityType[$index] = CRM_Core_OptionGroup
::values('activity_type', FALSE, FALSE, FALSE, $condition, $returnColumn);
612 return self
::$activityType[$index];
616 * Get all payment-processor billing modes
621 * @return array ($id => $name)
623 public static function billingMode() {
624 if (!self
::$billingMode) {
625 self
::$billingMode = array(
626 CRM_Core_Payment
::BILLING_MODE_FORM
=> 'form',
627 CRM_Core_Payment
::BILLING_MODE_BUTTON
=> 'button',
628 CRM_Core_Payment
::BILLING_MODE_NOTIFY
=> 'notify',
631 return self
::$billingMode;
635 * Get all component names
640 * @return array - array reference of all location display names.
643 public static function &component() {
644 if (!self
::$component) {
645 self
::populate(self
::$component, 'CRM_Core_DAO_Component', TRUE, 'name');
647 return self
::$component;
652 * Get all Individual Prefix.
654 * The static array individualPrefix is returned
659 * @param boolean $all - get All Individual Prefix - default is to get only active ones.
661 * @return array - array reference of all individual prefix.
664 public static function &individualPrefix() {
665 if (!self
::$individualPrefix) {
666 self
::$individualPrefix = CRM_Core_OptionGroup
::values('individual_prefix');
668 return self
::$individualPrefix;
673 * The static array phoneType is returned
678 * @param boolean $all - get All phone type - default is to get
681 * @return array - array reference of all phone types.
684 public static function &phoneType() {
685 if (!self
::$phoneType) {
686 self
::$phoneType = CRM_Core_OptionGroup
::values('phone_type');
688 return self
::$phoneType;
692 * Get all Individual Suffix.
694 * The static array individualSuffix is returned
699 * @param boolean $all - get All Individual Suffix - default is to get only active ones.
701 * @return array - array reference of all individual suffix.
704 public static function &individualSuffix() {
705 if (!self
::$individualSuffix) {
706 self
::$individualSuffix = CRM_Core_OptionGroup
::values('individual_suffix');
708 return self
::$individualSuffix;
714 * The static array gender is returned
719 * @param boolean $all - get All Gender - default is to get only active ones.
721 * @return array - array reference of all gender.
724 public static function &gender($localize = FALSE) {
725 if (!self
::$gender) {
726 self
::$gender = CRM_Core_OptionGroup
::values('gender', FALSE, FALSE, $localize);
728 return self
::$gender;
732 * Get all the IM Providers from database.
734 * The static array imProvider is returned, and if it's
735 * called the first time, the <b>IM DAO</b> is used
736 * to get all the IM Providers.
738 * Note: any database errors will be trapped by the DAO.
743 * @return array - array reference of all IM providers.
746 public static function &IMProvider($localize = FALSE) {
747 if (!self
::$imProvider) {
748 self
::$imProvider = CRM_Core_OptionGroup
::values('instant_messenger_service', FALSE, FALSE, $localize);
750 return self
::$imProvider;
754 * Get all the website types from database.
756 * The static array websiteType is returned, and if it's
757 * called the first time, the <b>Website DAO</b> is used
758 * to get all the Website Types.
760 * Note: any database errors will be trapped by the DAO.
765 * @return array - array reference of all Website types.
768 public static function &websiteType() {
769 if (!self
::$websiteType) {
770 self
::$websiteType = CRM_Core_OptionGroup
::values('website_type');
772 return self
::$websiteType;
776 * Get the all From Email Address from database.
778 * The static array $fromEmailAddress is returned, and if it's
779 * called the first time, DAO is used
780 * to get all the From Email Address
782 * Note: any database errors will be trapped by the DAO.
787 * @return array - array reference of all From Email Address.
789 public static function &fromEmailAddress() {
790 if (!self
::$fromEmailAddress) {
791 self
::$fromEmailAddress = CRM_Core_OptionGroup
::values('from_email_address');
793 return self
::$fromEmailAddress;
797 * Get the all Mail Protocols from database.
799 * The static array mailProtocol is returned, and if it's
800 * called the first time, the DAO is used
801 * to get all the Mail Protocol.
803 * Note: any database errors will be trapped by the DAO.
808 * @return array - array reference of all Mail Protocols.
810 public static function &mailProtocol() {
811 if (!self
::$mailProtocol) {
812 self
::$mailProtocol = CRM_Core_OptionGroup
::values('mail_protocol');
814 return self
::$mailProtocol;
818 * Get all the State/Province from database.
820 * The static array stateProvince is returned, and if it's
821 * called the first time, the <b>State Province DAO</b> is used
822 * to get all the States.
824 * Note: any database errors will be trapped by the DAO.
829 * @param int $id - Optional id to return
831 * @return array - array reference of all State/Provinces.
834 public static function &stateProvince($id = FALSE, $limit = TRUE) {
835 if (($id && !CRM_Utils_Array
::value($id, self
::$stateProvince)) ||
!self
::$stateProvince ||
!$id) {
836 $whereClause = FALSE;
837 $config = CRM_Core_Config
::singleton();
839 $countryIsoCodes = self
::countryIsoCode();
840 $limitCodes = $config->provinceLimit();
842 foreach ($limitCodes as $code) {
843 $limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
845 if (!empty($limitIds)) {
846 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
849 $whereClause = FALSE;
852 self
::populate(self
::$stateProvince, 'CRM_Core_DAO_StateProvince', TRUE, 'name', 'is_active', $whereClause);
854 // localise the province names if in an non-en_US locale
856 if ($tsLocale != '' and $tsLocale != 'en_US') {
857 $i18n = CRM_Core_I18n
::singleton();
858 $i18n->localizeArray(self
::$stateProvince, array(
859 'context' => 'province',
861 self
::$stateProvince = CRM_Utils_Array
::asort(self
::$stateProvince);
865 if (array_key_exists($id, self
::$stateProvince)) {
866 return self
::$stateProvince[$id];
873 return self
::$stateProvince;
877 * Get all the State/Province abbreviations from the database.
879 * Same as above, except gets the abbreviations instead of the names.
884 * @param int $id - Optional id to return
886 * @return array - array reference of all State/Province abbreviations.
888 public static function &stateProvinceAbbreviation($id = FALSE, $limit = TRUE) {
892 FROM civicrm_state_province
900 return CRM_Core_DAO
::singleValueQuery($query, $params);
903 if (!self
::$stateProvinceAbbreviation ||
!$id) {
905 $whereClause = FALSE;
908 $config = CRM_Core_Config
::singleton();
909 $countryIsoCodes = self
::countryIsoCode();
910 $limitCodes = $config->provinceLimit();
912 foreach ($limitCodes as $code) {
913 $tmpArray = array_keys($countryIsoCodes, $code);
915 if (!empty($tmpArray)) {
916 $limitIds[] = array_shift($tmpArray);
919 if (!empty($limitIds)) {
920 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
923 self
::populate(self
::$stateProvinceAbbreviation, 'CRM_Core_DAO_StateProvince', TRUE, 'abbreviation', 'is_active', $whereClause);
927 if (array_key_exists($id, self
::$stateProvinceAbbreviation)) {
928 return self
::$stateProvinceAbbreviation[$id];
935 return self
::$stateProvinceAbbreviation;
939 * Get all the countries from database.
941 * The static array country is returned, and if it's
942 * called the first time, the <b>Country DAO</b> is used
943 * to get all the countries.
945 * Note: any database errors will be trapped by the DAO.
950 * @param int $id - Optional id to return
952 * @return array - array reference of all countries.
955 public static function country($id = FALSE, $applyLimit = TRUE) {
956 if (($id && !CRM_Utils_Array
::value($id, self
::$country)) ||
!self
::$country ||
!$id) {
958 $config = CRM_Core_Config
::singleton();
959 $limitCodes = array();
962 // limit the country list to the countries specified in CIVICRM_COUNTRY_LIMIT
963 // (ensuring it's a subset of the legal values)
964 // K/P: We need to fix this, i dont think it works with new setting files
965 $limitCodes = $config->countryLimit();
966 if (!is_array($limitCodes)) {
968 $config->countryLimit
=> 1,
972 $limitCodes = array_intersect(self
::countryIsoCode(), $limitCodes);
975 if (count($limitCodes)) {
976 $whereClause = "iso_code IN ('" . implode("', '", $limitCodes) . "')";
982 self
::populate(self
::$country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active', $whereClause);
984 // if default country is set, percolate it to the top
985 if ($config->defaultContactCountry()) {
986 $countryIsoCodes = self
::countryIsoCode();
987 $defaultID = array_search($config->defaultContactCountry(), $countryIsoCodes);
988 if ($defaultID !== FALSE) {
989 $default[$defaultID] = CRM_Utils_Array
::value($defaultID, self
::$country);
990 self
::$country = $default + self
::$country;
994 // localise the country names if in an non-en_US locale
996 if ($tsLocale != '' and $tsLocale != 'en_US') {
997 $i18n = CRM_Core_I18n
::singleton();
998 $i18n->localizeArray(self
::$country, array(
999 'context' => 'country',
1001 self
::$country = CRM_Utils_Array
::asort(self
::$country);
1005 if (array_key_exists($id, self
::$country)) {
1006 return self
::$country[$id];
1012 return self
::$country;
1016 * Get all the country ISO Code abbreviations from the database.
1018 * The static array countryIsoCode is returned, and if it's
1019 * called the first time, the <b>Country DAO</b> is used
1020 * to get all the countries' ISO codes.
1022 * Note: any database errors will be trapped by the DAO.
1027 * @return array - array reference of all country ISO codes.
1030 public static function &countryIsoCode($id = FALSE) {
1031 if (!self
::$countryIsoCode) {
1032 self
::populate(self
::$countryIsoCode, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
1035 if (array_key_exists($id, self
::$countryIsoCode)) {
1036 return self
::$countryIsoCode[$id];
1042 return self
::$countryIsoCode;
1046 * Get all the categories from database.
1048 * The static array tag is returned, and if it's
1049 * called the first time, the <b>Tag DAO</b> is used
1050 * to get all the categories.
1052 * Note: any database errors will be trapped by the DAO.
1057 * @return array - array reference of all categories.
1060 public static function &tag() {
1062 self
::populate(self
::$tag, 'CRM_Core_DAO_Tag', TRUE);
1068 * Get all groups from database
1070 * The static array group is returned, and if it's
1071 * called the first time, the <b>Group DAO</b> is used
1072 * to get all the groups.
1074 * Note: any database errors will be trapped by the DAO.
1076 * @param string $groupType type of group(Access/Mailing)
1077 * @param boolen $excludeHidden exclude hidden groups.
1082 * @return array - array reference of all groups.
1085 public static function &allGroup($groupType = NULL, $excludeHidden = TRUE) {
1086 $condition = CRM_Contact_BAO_Group
::groupTypeCondition($groupType, $excludeHidden);
1088 if (!self
::$group) {
1089 self
::$group = array();
1092 $groupKey = $groupType ?
$groupType : 'null';
1094 if (!isset(self
::$group[$groupKey])) {
1095 self
::$group[$groupKey] = NULL;
1096 self
::populate(self
::$group[$groupKey], 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition);
1098 return self
::$group[$groupKey];
1102 * Create or get groups iterator (iterates over nested groups in a
1105 * The GroupNesting instance is returned; it's created if this is being
1106 * called for the first time
1112 * @return mixed - instance of CRM_Contact_BAO_GroupNesting
1115 public static function &groupIterator($styledLabels = FALSE) {
1116 if (!self
::$groupIterator) {
1118 When used as an object, GroupNesting implements Iterator
1119 and iterates nested groups in a logical manner for us
1121 self
::$groupIterator = new CRM_Contact_BAO_GroupNesting($styledLabels);
1123 return self
::$groupIterator;
1127 * Get all permissioned groups from database
1129 * The static array group is returned, and if it's
1130 * called the first time, the <b>Group DAO</b> is used
1131 * to get all the groups.
1133 * Note: any database errors will be trapped by the DAO.
1135 * @param string $groupType type of group(Access/Mailing)
1136 * @param boolen $excludeHidden exclude hidden groups.
1141 * @return array - array reference of all groups.
1144 public static function group($groupType = NULL, $excludeHidden = TRUE) {
1145 return CRM_Core_Permission
::group($groupType, $excludeHidden);
1149 * Get all permissioned groups from database
1151 * The static array group is returned, and if it's
1152 * called the first time, the <b>Group DAO</b> is used
1153 * to get all the groups.
1155 * Note: any database errors will be trapped by the DAO.
1160 * @return array - array reference of all groups.
1163 public static function &staticGroup($onlyPublic = FALSE, $groupType = NULL, $excludeHidden = TRUE) {
1164 if (!self
::$staticGroup) {
1165 $condition = 'saved_search_id = 0 OR saved_search_id IS NULL';
1167 $condition .= " AND visibility != 'User and User Admin Only'";
1171 $condition .= ' AND ' . CRM_Contact_BAO_Group
::groupTypeCondition($groupType);
1174 if ($excludeHidden) {
1175 $condition .= ' AND is_hidden != 1 ';
1178 self
::populate(self
::$staticGroup, 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition, 'title');
1181 return self
::$staticGroup;
1185 * Get all the custom groups
1189 * @return array - array reference of all groups.
1192 public static function &customGroup($reset = FALSE) {
1193 if (!self
::$customGroup ||
$reset) {
1194 self
::populate(self
::$customGroup, 'CRM_Core_DAO_CustomGroup', FALSE, 'title', 'is_active', NULL, 'title');
1196 return self
::$customGroup;
1200 * Get all the user framework groups
1204 * @return array - array reference of all groups.
1207 public static function &ufGroup() {
1208 if (!self
::$ufGroup) {
1209 self
::populate(self
::$ufGroup, 'CRM_Core_DAO_UFGroup', FALSE, 'title', 'is_active', NULL, 'title');
1211 return self
::$ufGroup;
1215 * Get all the project tasks
1219 * @return array - array reference of all tasks
1222 public static function &tasks() {
1223 if (!self
::$tasks) {
1224 self
::populate(self
::$tasks, 'CRM_Project_DAO_Task', FALSE, 'title', 'is_active', NULL, 'title');
1226 return self
::$tasks;
1230 * Get all Relationship Types from database.
1232 * The static array group is returned, and if it's
1233 * called the first time, the <b>RelationshipType DAO</b> is used
1234 * to get all the relationship types.
1236 * Note: any database errors will be trapped by the DAO.
1238 * @param string $valueColumnName db column name/label.
1239 * @param boolean $reset reset relationship types if true
1244 * @return array - array reference of all relationship types.
1246 public static function &relationshipType($valueColumnName = 'label', $reset = FALSE) {
1247 if (!CRM_Utils_Array
::value($valueColumnName, self
::$relationshipType) ||
$reset) {
1248 self
::$relationshipType[$valueColumnName] = array();
1250 //now we have name/label columns CRM-3336
1251 $column_a_b = "{$valueColumnName}_a_b";
1252 $column_b_a = "{$valueColumnName}_b_a";
1254 $relationshipTypeDAO = new CRM_Contact_DAO_RelationshipType();
1255 $relationshipTypeDAO->selectAdd();
1256 $relationshipTypeDAO->selectAdd("id, {$column_a_b}, {$column_b_a}, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b");
1257 $relationshipTypeDAO->is_active
= 1;
1258 $relationshipTypeDAO->find();
1259 while ($relationshipTypeDAO->fetch()) {
1261 self
::$relationshipType[$valueColumnName][$relationshipTypeDAO->id
] = array(
1262 $column_a_b => $relationshipTypeDAO->$column_a_b,
1263 $column_b_a => $relationshipTypeDAO->$column_b_a,
1264 'contact_type_a' => "$relationshipTypeDAO->contact_type_a",
1265 'contact_type_b' => "$relationshipTypeDAO->contact_type_b",
1266 'contact_sub_type_a' => "$relationshipTypeDAO->contact_sub_type_a",
1267 'contact_sub_type_b' => "$relationshipTypeDAO->contact_sub_type_b",
1272 return self
::$relationshipType[$valueColumnName];
1276 * Get all the Currency Symbols from Database
1280 * @return array - array reference of all Currency Symbols
1283 public static function ¤cySymbols($name = 'symbol', $key = 'id') {
1284 $cacheKey = "{$name}_{$key}";
1285 if (!isset(self
::$currencySymbols[$cacheKey])) {
1286 self
::populate(self
::$currencySymbols[$cacheKey], 'CRM_Financial_DAO_Currency', TRUE, $name, NULL, NULL, 'name', $key);
1289 return self
::$currencySymbols[$cacheKey];
1293 * get all the ISO 4217 currency codes
1295 * so far, we use this for validation only, so there's no point of putting this into the database
1299 * @return array - array reference of all currency codes
1302 public static function ¤cyCode() {
1303 if (!self
::$currencyCode) {
1304 self
::$currencyCode = array(
1574 return self
::$currencyCode;
1578 * Get all the County from database.
1580 * The static array county is returned, and if it's
1581 * called the first time, the <b>County DAO</b> is used
1582 * to get all the Counties.
1584 * Note: any database errors will be trapped by the DAO.
1589 * @param int $id - Optional id to return
1591 * @return array - array reference of all Counties
1594 public static function &county($id = FALSE) {
1595 if (!self
::$county) {
1597 $config = CRM_Core_Config
::singleton();
1598 // order by id so users who populate civicrm_county can have more control over sort by the order they load the counties
1599 self
::populate(self
::$county, 'CRM_Core_DAO_County', TRUE, 'name', NULL, NULL, 'id');
1602 if (array_key_exists($id, self
::$county)) {
1603 return self
::$county[$id];
1609 return self
::$county;
1613 * Get all the Preferred Communication Methods from database.
1618 * @return array self::pcm - array reference of all preferred communication methods.
1621 public static function &pcm($localize = FALSE) {
1623 self
::$pcm = CRM_Core_OptionGroup
::values('preferred_communication_method', FALSE, FALSE, $localize);
1631 public static function preferredCommunicationMethod($localize = FALSE) {
1632 return self
::pcm($localize);
1636 * Get all active payment processors
1638 * The static array paymentProcessor is returned
1643 * @param boolean $all - get payment processors - default is to get only active ones.
1644 * @param boolean $test - get test payment processors
1646 * @return array - array of all payment processors
1649 public static function &paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
1650 $condition = "is_test = ";
1651 $condition .= ($test) ?
'1' : '0';
1653 if ($additionalCond) {
1654 $condition .= " AND ( $additionalCond ) ";
1657 // CRM-7178. Make sure we only include payment processors valid in ths
1659 $condition .= " AND domain_id = " . CRM_Core_Config
::domainID();
1661 $cacheKey = $condition . '_' . (int) $all;
1662 if (!isset(self
::$paymentProcessor[$cacheKey])) {
1663 self
::populate(self
::$paymentProcessor[$cacheKey], 'CRM_Financial_DAO_PaymentProcessor', $all, 'name', 'is_active', $condition, 'is_default desc, name');
1666 return self
::$paymentProcessor[$cacheKey];
1670 * Get all active payment processors
1672 * The static array paymentProcessorType is returned
1677 * @param boolean $all - get payment processors - default is to get only active ones.
1679 * @return array - array of all payment processor types
1682 public static function &paymentProcessorType($all = FALSE, $id = NULL, $return = 'title') {
1683 $cacheKey = $id . '_' .$return;
1684 if (empty(self
::$paymentProcessorType[$cacheKey])) {
1685 self
::populate(self
::$paymentProcessorType[$cacheKey], 'CRM_Financial_DAO_PaymentProcessorType', $all, $return, 'is_active', NULL, "is_default, $return", 'id');
1687 if ($id && CRM_Utils_Array
::value($id, self
::$paymentProcessorType[$cacheKey])) {
1688 return self
::$paymentProcessorType[$cacheKey][$id];
1690 return self
::$paymentProcessorType[$cacheKey];
1694 * Get all the World Regions from Database
1698 * @return array - array reference of all World Regions
1701 public static function &worldRegion($id = FALSE) {
1702 if (!self
::$worldRegions) {
1703 self
::populate(self
::$worldRegions, 'CRM_Core_DAO_Worldregion', TRUE, 'name', NULL, NULL, 'id');
1707 if (array_key_exists($id, self
::$worldRegions)) {
1708 return self
::$worldRegions[$id];
1715 return self
::$worldRegions;
1719 * Get all Honor Type.
1721 * The static array honorType is returned
1726 * @param boolean $all - get All Honor Type.
1728 * @return array - array reference of all Honor Types.
1731 public static function &honor() {
1732 if (!self
::$honorType) {
1733 self
::$honorType = CRM_Core_OptionGroup
::values('honor_type');
1735 return self
::$honorType;
1739 * Get all Activity Statuses.
1741 * The static array activityStatus is returned
1746 * @return array - array reference of all activity statuses
1748 public static function &activityStatus($column = 'label') {
1749 if (NULL === self
::$activityStatus) {
1750 self
::$activityStatus = array();
1752 if (!array_key_exists($column, self
::$activityStatus)) {
1753 self
::$activityStatus[$column] = array();
1755 self
::$activityStatus[$column] = CRM_Core_OptionGroup
::values('activity_status', FALSE, FALSE, FALSE, NULL, $column);
1758 return self
::$activityStatus[$column];
1762 * Get all Priorities
1764 * The static array Priority is returned
1769 * @return array - array reference of all Priority
1771 public static function &priority() {
1772 if (!self
::$priority) {
1773 self
::$priority = CRM_Core_OptionGroup
::values('priority');
1776 return self
::$priority;
1780 * Get all WYSIWYG Editors.
1782 * The static array wysiwygEditor is returned
1787 * @return array - array reference of all wysiwygEditors
1789 public static function &wysiwygEditor() {
1790 if (!self
::$wysiwygEditor) {
1791 self
::$wysiwygEditor = CRM_Core_OptionGroup
::values('wysiwyg_editor');
1793 return self
::$wysiwygEditor;
1797 * Get all Visibility levels.
1799 * The static array visibility is returned
1804 * @return array - array reference of all Visibility levels.
1807 public static function &visibility($column = 'label') {
1808 if (!isset(self
::$visibility)) {
1809 self
::$visibility = array( );
1812 if (!isset(self
::$visibility[$column])) {
1813 self
::$visibility[$column] = CRM_Core_OptionGroup
::values('visibility', FALSE, FALSE, FALSE, NULL, $column);
1816 return self
::$visibility[$column];
1820 * Get all mapping types
1822 * @return array - array reference of all mapping types
1826 public static function &mappingTypes() {
1827 if (!self
::$mappingType) {
1828 self
::$mappingType = CRM_Core_OptionGroup
::values('mapping_type');
1830 return self
::$mappingType;
1833 public static function &stateProvinceForCountry($countryID, $field = 'name') {
1834 static $_cache = NULL;
1836 $cacheKey = "{$countryID}_{$field}";
1841 if (!empty($_cache[$cacheKey])) {
1842 return $_cache[$cacheKey];
1846 SELECT civicrm_state_province.{$field} name, civicrm_state_province.id id
1847 FROM civicrm_state_province
1848 WHERE country_id = %1
1857 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1860 while ($dao->fetch()) {
1861 $result[$dao->id
] = $dao->name
;
1864 // localise the stateProvince names if in an non-en_US locale
1865 $config = CRM_Core_Config
::singleton();
1867 if ($tsLocale != '' and $tsLocale != 'en_US') {
1868 $i18n = CRM_Core_I18n
::singleton();
1869 $i18n->localizeArray($result, array(
1870 'context' => 'province',
1872 $result = CRM_Utils_Array
::asort($result);
1875 $_cache[$cacheKey] = $result;
1877 CRM_Utils_Hook
::buildStateProvinceForCountry($countryID, $result);
1882 public static function &countyForState($stateID) {
1883 if (is_array($stateID)) {
1884 $states = implode(", ", $stateID);
1886 SELECT civicrm_county.name name, civicrm_county.id id, civicrm_state_province.abbreviation abbreviation
1888 LEFT JOIN civicrm_state_province ON civicrm_county.state_province_id = civicrm_state_province.id
1889 WHERE civicrm_county.state_province_id in ( $states )
1890 ORDER BY civicrm_state_province.abbreviation, civicrm_county.name";
1892 $dao = CRM_Core_DAO
::executeQuery($query);
1895 while ($dao->fetch()) {
1896 $result[$dao->id
] = $dao->abbreviation
. ': ' . $dao->name
;
1901 static $_cache = NULL;
1903 $cacheKey = "{$stateID}_name";
1908 if (!empty($_cache[$cacheKey])) {
1909 return $_cache[$cacheKey];
1913 SELECT civicrm_county.name name, civicrm_county.id id
1915 WHERE state_province_id = %1
1924 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1927 while ($dao->fetch()) {
1928 $result[$dao->id
] = $dao->name
;
1936 * Given a state ID return the country ID, this allows
1937 * us to populate forms and values for downstream code
1939 * @param $stateID int
1941 * @return int the country id that the state belongs to
1945 static function countryIDForStateID($stateID) {
1946 if (empty($stateID)) {
1952 FROM civicrm_state_province
1955 $params = array(1 => array($stateID, 'Integer'));
1957 return CRM_Core_DAO
::singleValueQuery($query, $params);
1961 * Get all types of Greetings.
1963 * The static array of greeting is returned
1968 * @param $filter - get All Email Greetings - default is to get only active ones.
1970 * @return array - array reference of all greetings.
1973 public static function greeting($filter, $columnName = 'label') {
1974 $index = $filter['greeting_type'] . '_' . $columnName;
1976 // also add contactType to the array
1977 $contactType = CRM_Utils_Array
::value('contact_type', $filter);
1979 $index .= '_' . $contactType;
1982 if (NULL === self
::$greeting) {
1983 self
::$greeting = array();
1986 if (!CRM_Utils_Array
::value($index, self
::$greeting)) {
1987 $filterCondition = NULL;
1989 $filterVal = 'v.filter =';
1990 switch ($contactType) {
1999 case 'Organization':
2003 $filterCondition .= "AND (v.filter = 0 OR {$filterVal}) ";
2006 self
::$greeting[$index] = CRM_Core_OptionGroup
::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName);
2009 return self
::$greeting[$index];
2013 * Construct array of default greeting values for contact type
2018 * @return array - array reference of default greetings.
2021 public static function &greetingDefaults() {
2022 if (!self
::$greetingDefaults) {
2023 $defaultGreetings = array();
2024 $contactTypes = array(
2027 'Organization' => 3,
2030 foreach ($contactTypes as $contactType => $filter) {
2031 $filterCondition = " AND (v.filter = 0 OR v.filter = $filter) AND v.is_default = 1 ";
2033 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
2034 $tokenVal = CRM_Core_OptionGroup
::values($greeting, NULL, NULL, NULL, $filterCondition, 'label');
2035 $defaultGreetings[$contactType][$greeting] = $tokenVal;
2039 self
::$greetingDefaults = $defaultGreetings;
2042 return self
::$greetingDefaults;
2046 * Get all the Languages from database.
2051 * @return array self::languages - array reference of all languages
2054 public static function &languages() {
2055 return CRM_Core_I18n_PseudoConstant
::languages();
2061 public static function &preferredLanguage() {
2062 return CRM_Core_I18n_PseudoConstant
::languages();
2066 * Get all extensions
2068 * The static array extensions
2070 * FIXME: This is called by civix but not by any core code. We
2071 * should provide an API call which civix can use instead.
2076 * @return array - array($fullyQualifiedName => $label) list of extensions
2078 public static function &getExtensions() {
2079 if (!self
::$extensions) {
2080 self
::$extensions = array();
2082 SELECT full_name, label
2083 FROM civicrm_extension
2086 $dao = CRM_Core_DAO
::executeQuery($sql);
2087 while ($dao->fetch()) {
2088 self
::$extensions[$dao->full_name
] = $dao->label
;
2092 return self
::$extensions;
2096 * Fetch the list of active extensions of type 'module'
2098 * @param $fresh bool whether to forcibly reload extensions list from canonical store
2102 * @return array - array(array('prefix' => $, 'file' => $))
2104 public static function getModuleExtensions($fresh = FALSE) {
2105 return CRM_Extension_System
::singleton()->getMapper()->getActiveModuleFiles($fresh);
2109 * Get all Activity Contacts
2111 * The static array activityContacts is returned
2116 * @param string $column db column name/label.
2118 * @return array - array reference of all activity Contacts
2121 public static function &activityContacts($column = 'label') {
2122 if (!self
::$activityContacts) {
2123 self
::$activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, $column);
2125 return self
::$activityContacts;
2129 * Get all Event Contacts
2131 * The static array eventContacts is returned
2136 * @param string $column db column name/label.
2138 * @return array - array reference of all event Contacts
2141 public static function &eventContacts($column = 'label') {
2142 if (!self
::$eventContacts) {
2143 self
::$eventContacts = CRM_Core_OptionGroup
::values('event_contacts', FALSE, FALSE, FALSE, NULL, $column);
2145 return self
::$eventContacts;
2149 * Get all options values
2151 * The static array option values is returned
2156 * @param boolean $optionGroupName - get All Option Group values- default is to get only active ones.
2158 * @return array - array reference of all Option Group Name
2161 public static function accountOptionValues($optionGroupName, $id = null, $condition = null) {
2162 $cacheKey = $optionGroupName . '_' . $condition;
2163 if (empty(self
::$accountOptionValues[$cacheKey])) {
2164 self
::$accountOptionValues[$cacheKey] = CRM_Core_OptionGroup
::values($optionGroupName, false, false, false, $condition);
2167 return CRM_Utils_Array
::value($id, self
::$accountOptionValues[$cacheKey]);
2170 return self
::$accountOptionValues[$cacheKey];
2174 * Get all batch modes
2176 * The static array batchModes
2181 * @return array - array reference of all batch modes
2183 public static function &getBatchMode($columnName = 'label') {
2184 if (!self
::$batchModes) {
2185 self
::$batchModes = CRM_Core_OptionGroup
::values('batch_mode', false, false, false, null, $columnName);
2188 return self
::$batchModes;
2192 * Get all batch types
2194 * The static array batchTypes
2199 * @return array - array reference of all batch types
2201 public static function &getBatchType() {
2202 if (!self
::$batchTypes) {
2203 self
::$batchTypes = CRM_Core_OptionGroup
::values('batch_type');
2206 return self
::$batchTypes;
2210 * Get all batch statuses
2212 * The static array batchStatues
2217 * @return array - array reference of all batch statuses
2219 public static function &getBatchStatus() {
2220 if (!self
::$batchStatues) {
2221 self
::$batchStatues = CRM_Core_OptionGroup
::values('batch_status');
2224 return self
::$batchStatues;
2228 * The static array contactType is returned
2232 * @param string $column db column name/label.
2234 * @return array - array reference of all Types
2238 public static function &contactType($column = 'label') {
2239 if (!self
::$contactType) {
2240 self
::$contactType = CRM_Contact_BAO_ContactType
::basicTypePairs(TRUE);
2242 return self
::$contactType;
2246 * Get all the auto renew options
2251 * @return array self::autoRenew - array reference of all autoRenew
2254 public static function &autoRenew() {
2255 if (!self
::$autoRenew) {
2256 self
::$autoRenew = CRM_Core_OptionGroup
::values('auto_renew_options', FALSE, FALSE);
2258 return self
::$autoRenew;