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) {
479 if (isset(self
::$
$name)) {
485 * Get all location types.
487 * The static array locationType is returned
492 * @param boolean $all - get All location types - default is to get only active ones.
494 * @return array - array reference of all location types.
497 public static function &locationType($all = FALSE) {
498 if (!self
::$locationType) {
499 self
::populate(self
::$locationType, 'CRM_Core_DAO_LocationType', $all);
501 return self
::$locationType;
505 * Get all location vCard names.
507 * The static array locationVcardName is returned
512 * @param boolean $all - get All location vCard names - default is to get only active ones.
514 * @return array - array reference of all location vCard names.
517 public static function &locationVcardName($all = FALSE) {
518 if (!self
::$locationVcardName) {
519 self
::populate(self
::$locationVcardName, 'CRM_Core_DAO_LocationType', $all, 'vcard_name');
521 return self
::$locationVcardName;
525 * Get all location Display names.
527 * The static array locationDisplayName is returned
532 * @param boolean $all - get All location display names - default is to get only active ones.
534 * @return array - array reference of all location display names.
537 public static function &locationDisplayName($all = FALSE) {
538 if (!self
::$locationDisplayName) {
539 self
::populate(self
::$locationDisplayName, 'CRM_Core_DAO_LocationType', $all, 'display_name');
541 return self
::$locationDisplayName;
545 * Get all Activty types.
547 * The static array activityType is returned
549 * @param boolean $all - get All Activity types - default is to get only active ones.
554 * @return array - array reference of all activity types.
556 public static function &activityType() {
557 $args = func_get_args();
558 $all = CRM_Utils_Array
::value(0, $args, TRUE);
559 $includeCaseActivities = CRM_Utils_Array
::value(1, $args, FALSE);
560 $reset = CRM_Utils_Array
::value(2, $args, FALSE);
561 $returnColumn = CRM_Utils_Array
::value(3, $args, 'label');
562 $includeCampaignActivities = CRM_Utils_Array
::value(4, $args, FALSE);
563 $onlyComponentActivities = CRM_Utils_Array
::value(5, $args, FALSE);
564 $index = (int) $all . '_' . $returnColumn . '_' . (int) $includeCaseActivities;
565 $index .= '_' . (int) $includeCampaignActivities;
566 $index .= '_' . (int) $onlyComponentActivities;
568 if (NULL === self
::$activityType) {
569 self
::$activityType = array();
572 if (!isset(self
::$activityType[$index]) ||
$reset) {
575 $condition = 'AND filter = 0';
577 $componentClause = " v.component_id IS NULL";
578 if ($onlyComponentActivities) {
579 $componentClause = " v.component_id IS NOT NULL";
582 $componentIds = array();
583 $compInfo = CRM_Core_Component
::getEnabledComponents();
585 // build filter for listing activity types only if their
586 // respective components are enabled
587 foreach ($compInfo as $compName => $compObj) {
588 if ($compName == 'CiviCase') {
589 if ($includeCaseActivities) {
590 $componentIds[] = $compObj->componentID
;
593 elseif ($compName == 'CiviCampaign') {
594 if ($includeCampaignActivities) {
595 $componentIds[] = $compObj->componentID
;
599 $componentIds[] = $compObj->componentID
;
603 if (count($componentIds)) {
604 $componentIds = implode(',', $componentIds);
605 $componentClause = " ($componentClause OR v.component_id IN ($componentIds))";
606 if ($onlyComponentActivities) {
607 $componentClause = " ( v.component_id IN ($componentIds ) )";
610 $condition = $condition . ' AND ' . $componentClause;
612 self
::$activityType[$index] = CRM_Core_OptionGroup
::values('activity_type', FALSE, FALSE, FALSE, $condition, $returnColumn);
614 return self
::$activityType[$index];
618 * Get all payment-processor billing modes
623 * @return array ($id => $name)
625 public static function billingMode() {
626 if (!self
::$billingMode) {
627 self
::$billingMode = array(
628 CRM_Core_Payment
::BILLING_MODE_FORM
=> 'form',
629 CRM_Core_Payment
::BILLING_MODE_BUTTON
=> 'button',
630 CRM_Core_Payment
::BILLING_MODE_NOTIFY
=> 'notify',
633 return self
::$billingMode;
637 * Get all component names
642 * @return array - array reference of all location display names.
645 public static function &component() {
646 if (!self
::$component) {
647 self
::populate(self
::$component, 'CRM_Core_DAO_Component', TRUE, 'name');
649 return self
::$component;
654 * Get all Individual Prefix.
656 * The static array individualPrefix is returned
661 * @param boolean $all - get All Individual Prefix - default is to get only active ones.
663 * @return array - array reference of all individual prefix.
666 public static function &individualPrefix() {
667 if (!self
::$individualPrefix) {
668 self
::$individualPrefix = CRM_Core_OptionGroup
::values('individual_prefix');
670 return self
::$individualPrefix;
675 * The static array phoneType is returned
680 * @param boolean $all - get All phone type - default is to get
683 * @return array - array reference of all phone types.
686 public static function &phoneType() {
687 if (!self
::$phoneType) {
688 self
::$phoneType = CRM_Core_OptionGroup
::values('phone_type');
690 return self
::$phoneType;
694 * Get all Individual Suffix.
696 * The static array individualSuffix is returned
701 * @param boolean $all - get All Individual Suffix - default is to get only active ones.
703 * @return array - array reference of all individual suffix.
706 public static function &individualSuffix() {
707 if (!self
::$individualSuffix) {
708 self
::$individualSuffix = CRM_Core_OptionGroup
::values('individual_suffix');
710 return self
::$individualSuffix;
716 * The static array gender is returned
721 * @param boolean $all - get All Gender - default is to get only active ones.
723 * @return array - array reference of all gender.
726 public static function &gender($localize = FALSE) {
727 if (!self
::$gender) {
728 self
::$gender = CRM_Core_OptionGroup
::values('gender', FALSE, FALSE, $localize);
730 return self
::$gender;
734 * Get all the IM Providers from database.
736 * The static array imProvider is returned, and if it's
737 * called the first time, the <b>IM DAO</b> is used
738 * to get all the IM Providers.
740 * Note: any database errors will be trapped by the DAO.
745 * @return array - array reference of all IM providers.
748 public static function &IMProvider($localize = FALSE) {
749 if (!self
::$imProvider) {
750 self
::$imProvider = CRM_Core_OptionGroup
::values('instant_messenger_service', FALSE, FALSE, $localize);
752 return self
::$imProvider;
756 * Get all the website types from database.
758 * The static array websiteType is returned, and if it's
759 * called the first time, the <b>Website DAO</b> is used
760 * to get all the Website Types.
762 * Note: any database errors will be trapped by the DAO.
767 * @return array - array reference of all Website types.
770 public static function &websiteType() {
771 if (!self
::$websiteType) {
772 self
::$websiteType = CRM_Core_OptionGroup
::values('website_type');
774 return self
::$websiteType;
778 * Get the all From Email Address from database.
780 * The static array $fromEmailAddress is returned, and if it's
781 * called the first time, DAO is used
782 * to get all the From Email Address
784 * Note: any database errors will be trapped by the DAO.
789 * @return array - array reference of all From Email Address.
791 public static function &fromEmailAddress() {
792 if (!self
::$fromEmailAddress) {
793 self
::$fromEmailAddress = CRM_Core_OptionGroup
::values('from_email_address');
795 return self
::$fromEmailAddress;
799 * Get the all Mail Protocols from database.
801 * The static array mailProtocol is returned, and if it's
802 * called the first time, the DAO is used
803 * to get all the Mail Protocol.
805 * Note: any database errors will be trapped by the DAO.
810 * @return array - array reference of all Mail Protocols.
812 public static function &mailProtocol() {
813 if (!self
::$mailProtocol) {
814 self
::$mailProtocol = CRM_Core_OptionGroup
::values('mail_protocol');
816 return self
::$mailProtocol;
820 * Get all the State/Province from database.
822 * The static array stateProvince is returned, and if it's
823 * called the first time, the <b>State Province DAO</b> is used
824 * to get all the States.
826 * Note: any database errors will be trapped by the DAO.
831 * @param int $id - Optional id to return
833 * @return array - array reference of all State/Provinces.
836 public static function &stateProvince($id = FALSE, $limit = TRUE) {
837 if (($id && !CRM_Utils_Array
::value($id, self
::$stateProvince)) ||
!self
::$stateProvince ||
!$id) {
838 $whereClause = FALSE;
839 $config = CRM_Core_Config
::singleton();
841 $countryIsoCodes = self
::countryIsoCode();
842 $limitCodes = $config->provinceLimit();
844 foreach ($limitCodes as $code) {
845 $limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
847 if (!empty($limitIds)) {
848 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
851 $whereClause = FALSE;
854 self
::populate(self
::$stateProvince, 'CRM_Core_DAO_StateProvince', TRUE, 'name', 'is_active', $whereClause);
856 // localise the province names if in an non-en_US locale
858 if ($tsLocale != '' and $tsLocale != 'en_US') {
859 $i18n = CRM_Core_I18n
::singleton();
860 $i18n->localizeArray(self
::$stateProvince, array(
861 'context' => 'province',
863 self
::$stateProvince = CRM_Utils_Array
::asort(self
::$stateProvince);
867 if (array_key_exists($id, self
::$stateProvince)) {
868 return self
::$stateProvince[$id];
875 return self
::$stateProvince;
879 * Get all the State/Province abbreviations from the database.
881 * Same as above, except gets the abbreviations instead of the names.
886 * @param int $id - Optional id to return
888 * @return array - array reference of all State/Province abbreviations.
890 public static function &stateProvinceAbbreviation($id = FALSE, $limit = TRUE) {
894 FROM civicrm_state_province
902 return CRM_Core_DAO
::singleValueQuery($query, $params);
905 if (!self
::$stateProvinceAbbreviation ||
!$id) {
907 $whereClause = FALSE;
910 $config = CRM_Core_Config
::singleton();
911 $countryIsoCodes = self
::countryIsoCode();
912 $limitCodes = $config->provinceLimit();
914 foreach ($limitCodes as $code) {
915 $tmpArray = array_keys($countryIsoCodes, $code);
917 if (!empty($tmpArray)) {
918 $limitIds[] = array_shift($tmpArray);
921 if (!empty($limitIds)) {
922 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
925 self
::populate(self
::$stateProvinceAbbreviation, 'CRM_Core_DAO_StateProvince', TRUE, 'abbreviation', 'is_active', $whereClause);
929 if (array_key_exists($id, self
::$stateProvinceAbbreviation)) {
930 return self
::$stateProvinceAbbreviation[$id];
937 return self
::$stateProvinceAbbreviation;
941 * Get all the countries from database.
943 * The static array country is returned, and if it's
944 * called the first time, the <b>Country DAO</b> is used
945 * to get all the countries.
947 * Note: any database errors will be trapped by the DAO.
952 * @param int $id - Optional id to return
954 * @return array - array reference of all countries.
957 public static function country($id = FALSE, $applyLimit = TRUE) {
958 if (($id && !CRM_Utils_Array
::value($id, self
::$country)) ||
!self
::$country ||
!$id) {
960 $config = CRM_Core_Config
::singleton();
961 $limitCodes = array();
964 // limit the country list to the countries specified in CIVICRM_COUNTRY_LIMIT
965 // (ensuring it's a subset of the legal values)
966 // K/P: We need to fix this, i dont think it works with new setting files
967 $limitCodes = $config->countryLimit();
968 if (!is_array($limitCodes)) {
970 $config->countryLimit
=> 1,
974 $limitCodes = array_intersect(self
::countryIsoCode(), $limitCodes);
977 if (count($limitCodes)) {
978 $whereClause = "iso_code IN ('" . implode("', '", $limitCodes) . "')";
984 self
::populate(self
::$country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active', $whereClause);
986 // if default country is set, percolate it to the top
987 if ($config->defaultContactCountry()) {
988 $countryIsoCodes = self
::countryIsoCode();
989 $defaultID = array_search($config->defaultContactCountry(), $countryIsoCodes);
990 if ($defaultID !== FALSE) {
991 $default[$defaultID] = CRM_Utils_Array
::value($defaultID, self
::$country);
992 self
::$country = $default + self
::$country;
996 // localise the country names if in an non-en_US locale
998 if ($tsLocale != '' and $tsLocale != 'en_US') {
999 $i18n = CRM_Core_I18n
::singleton();
1000 $i18n->localizeArray(self
::$country, array(
1001 'context' => 'country',
1003 self
::$country = CRM_Utils_Array
::asort(self
::$country);
1007 if (array_key_exists($id, self
::$country)) {
1008 return self
::$country[$id];
1011 return CRM_Core_DAO
::$_nullObject;
1014 return self
::$country;
1018 * Get all the country ISO Code abbreviations from the database.
1020 * The static array countryIsoCode is returned, and if it's
1021 * called the first time, the <b>Country DAO</b> is used
1022 * to get all the countries' ISO codes.
1024 * Note: any database errors will be trapped by the DAO.
1029 * @return array - array reference of all country ISO codes.
1032 public static function &countryIsoCode($id = FALSE) {
1033 if (!self
::$countryIsoCode) {
1034 self
::populate(self
::$countryIsoCode, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
1037 if (array_key_exists($id, self
::$countryIsoCode)) {
1038 return self
::$countryIsoCode[$id];
1041 return CRM_Core_DAO
::$_nullObject;
1044 return self
::$countryIsoCode;
1048 * Get all the categories from database.
1050 * The static array tag is returned, and if it's
1051 * called the first time, the <b>Tag DAO</b> is used
1052 * to get all the categories.
1054 * Note: any database errors will be trapped by the DAO.
1059 * @return array - array reference of all categories.
1062 public static function &tag() {
1064 self
::populate(self
::$tag, 'CRM_Core_DAO_Tag', TRUE);
1070 * Get all groups from database
1072 * The static array group is returned, and if it's
1073 * called the first time, the <b>Group DAO</b> is used
1074 * to get all the groups.
1076 * Note: any database errors will be trapped by the DAO.
1078 * @param string $groupType type of group(Access/Mailing)
1079 * @param boolen $excludeHidden exclude hidden groups.
1084 * @return array - array reference of all groups.
1087 public static function &allGroup($groupType = NULL, $excludeHidden = TRUE) {
1088 $condition = CRM_Contact_BAO_Group
::groupTypeCondition($groupType, $excludeHidden);
1090 if (!self
::$group) {
1091 self
::$group = array();
1094 $groupKey = $groupType ?
$groupType : 'null';
1096 if (!isset(self
::$group[$groupKey])) {
1097 self
::$group[$groupKey] = NULL;
1098 self
::populate(self
::$group[$groupKey], 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition);
1100 return self
::$group[$groupKey];
1104 * Create or get groups iterator (iterates over nested groups in a
1107 * The GroupNesting instance is returned; it's created if this is being
1108 * called for the first time
1114 * @return mixed - instance of CRM_Contact_BAO_GroupNesting
1117 public static function &groupIterator($styledLabels = FALSE) {
1118 if (!self
::$groupIterator) {
1120 When used as an object, GroupNesting implements Iterator
1121 and iterates nested groups in a logical manner for us
1123 self
::$groupIterator = new CRM_Contact_BAO_GroupNesting($styledLabels);
1125 return self
::$groupIterator;
1129 * Get all permissioned groups from database
1131 * The static array group is returned, and if it's
1132 * called the first time, the <b>Group DAO</b> is used
1133 * to get all the groups.
1135 * Note: any database errors will be trapped by the DAO.
1137 * @param string $groupType type of group(Access/Mailing)
1138 * @param boolen $excludeHidden exclude hidden groups.
1143 * @return array - array reference of all groups.
1146 public static function group($groupType = NULL, $excludeHidden = TRUE) {
1147 return CRM_Core_Permission
::group($groupType, $excludeHidden);
1151 * Get all permissioned groups from database
1153 * The static array group is returned, and if it's
1154 * called the first time, the <b>Group DAO</b> is used
1155 * to get all the groups.
1157 * Note: any database errors will be trapped by the DAO.
1162 * @return array - array reference of all groups.
1165 public static function &staticGroup($onlyPublic = FALSE, $groupType = NULL, $excludeHidden = TRUE) {
1166 if (!self
::$staticGroup) {
1167 $condition = 'saved_search_id = 0 OR saved_search_id IS NULL';
1169 $condition .= " AND visibility != 'User and User Admin Only'";
1173 $condition .= ' AND ' . CRM_Contact_BAO_Group
::groupTypeCondition($groupType);
1176 if ($excludeHidden) {
1177 $condition .= ' AND is_hidden != 1 ';
1180 self
::populate(self
::$staticGroup, 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition, 'title');
1183 return self
::$staticGroup;
1187 * Get all the custom groups
1191 * @return array - array reference of all groups.
1194 public static function &customGroup($reset = FALSE) {
1195 if (!self
::$customGroup ||
$reset) {
1196 self
::populate(self
::$customGroup, 'CRM_Core_DAO_CustomGroup', FALSE, 'title', 'is_active', NULL, 'title');
1198 return self
::$customGroup;
1202 * Get all the user framework groups
1206 * @return array - array reference of all groups.
1209 public static function &ufGroup() {
1210 if (!self
::$ufGroup) {
1211 self
::populate(self
::$ufGroup, 'CRM_Core_DAO_UFGroup', FALSE, 'title', 'is_active', NULL, 'title');
1213 return self
::$ufGroup;
1217 * Get all the project tasks
1221 * @return array - array reference of all tasks
1224 public static function &tasks() {
1225 if (!self
::$tasks) {
1226 self
::populate(self
::$tasks, 'CRM_Project_DAO_Task', FALSE, 'title', 'is_active', NULL, 'title');
1228 return self
::$tasks;
1232 * Get all Relationship Types from database.
1234 * The static array group is returned, and if it's
1235 * called the first time, the <b>RelationshipType DAO</b> is used
1236 * to get all the relationship types.
1238 * Note: any database errors will be trapped by the DAO.
1240 * @param string $valueColumnName db column name/label.
1241 * @param boolean $reset reset relationship types if true
1246 * @return array - array reference of all relationship types.
1248 public static function &relationshipType($valueColumnName = 'label', $reset = FALSE) {
1249 if (!CRM_Utils_Array
::value($valueColumnName, self
::$relationshipType) ||
$reset) {
1250 self
::$relationshipType[$valueColumnName] = array();
1252 //now we have name/label columns CRM-3336
1253 $column_a_b = "{$valueColumnName}_a_b";
1254 $column_b_a = "{$valueColumnName}_b_a";
1256 $relationshipTypeDAO = new CRM_Contact_DAO_RelationshipType();
1257 $relationshipTypeDAO->selectAdd();
1258 $relationshipTypeDAO->selectAdd("id, {$column_a_b}, {$column_b_a}, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b");
1259 $relationshipTypeDAO->is_active
= 1;
1260 $relationshipTypeDAO->find();
1261 while ($relationshipTypeDAO->fetch()) {
1263 self
::$relationshipType[$valueColumnName][$relationshipTypeDAO->id
] = array(
1264 'id' => $relationshipTypeDAO->id
,
1265 $column_a_b => $relationshipTypeDAO->$column_a_b,
1266 $column_b_a => $relationshipTypeDAO->$column_b_a,
1267 'contact_type_a' => "$relationshipTypeDAO->contact_type_a",
1268 'contact_type_b' => "$relationshipTypeDAO->contact_type_b",
1269 'contact_sub_type_a' => "$relationshipTypeDAO->contact_sub_type_a",
1270 'contact_sub_type_b' => "$relationshipTypeDAO->contact_sub_type_b",
1275 return self
::$relationshipType[$valueColumnName];
1279 * Get all the Currency Symbols from Database
1283 * @return array - array reference of all Currency Symbols
1286 public static function ¤cySymbols($name = 'symbol', $key = 'id') {
1287 $cacheKey = "{$name}_{$key}";
1288 if (!isset(self
::$currencySymbols[$cacheKey])) {
1289 self
::populate(self
::$currencySymbols[$cacheKey], 'CRM_Financial_DAO_Currency', TRUE, $name, NULL, NULL, 'name', $key);
1292 return self
::$currencySymbols[$cacheKey];
1296 * get all the ISO 4217 currency codes
1298 * so far, we use this for validation only, so there's no point of putting this into the database
1302 * @return array - array reference of all currency codes
1305 public static function ¤cyCode() {
1306 if (!self
::$currencyCode) {
1307 self
::$currencyCode = array(
1577 return self
::$currencyCode;
1581 * Get all the County from database.
1583 * The static array county is returned, and if it's
1584 * called the first time, the <b>County DAO</b> is used
1585 * to get all the Counties.
1587 * Note: any database errors will be trapped by the DAO.
1592 * @param int $id - Optional id to return
1594 * @return array - array reference of all Counties
1597 public static function &county($id = FALSE) {
1598 if (!self
::$county) {
1600 $config = CRM_Core_Config
::singleton();
1601 // order by id so users who populate civicrm_county can have more control over sort by the order they load the counties
1602 self
::populate(self
::$county, 'CRM_Core_DAO_County', TRUE, 'name', NULL, NULL, 'id');
1605 if (array_key_exists($id, self
::$county)) {
1606 return self
::$county[$id];
1609 return CRM_Core_DAO
::$_nullObject;
1612 return self
::$county;
1616 * Get all the Preferred Communication Methods from database.
1621 * @return array self::pcm - array reference of all preferred communication methods.
1624 public static function &pcm($localize = FALSE) {
1626 self
::$pcm = CRM_Core_OptionGroup
::values('preferred_communication_method', FALSE, FALSE, $localize);
1634 public static function preferredCommunicationMethod($localize = FALSE) {
1635 return self
::pcm($localize);
1639 * Get all active payment processors
1641 * The static array paymentProcessor is returned
1646 * @param boolean $all - get payment processors - default is to get only active ones.
1647 * @param boolean $test - get test payment processors
1649 * @return array - array of all payment processors
1652 public static function &paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
1653 $condition = "is_test = ";
1654 $condition .= ($test) ?
'1' : '0';
1656 if ($additionalCond) {
1657 $condition .= " AND ( $additionalCond ) ";
1660 // CRM-7178. Make sure we only include payment processors valid in ths
1662 $condition .= " AND domain_id = " . CRM_Core_Config
::domainID();
1664 $cacheKey = $condition . '_' . (int) $all;
1665 if (!isset(self
::$paymentProcessor[$cacheKey])) {
1666 self
::populate(self
::$paymentProcessor[$cacheKey], 'CRM_Financial_DAO_PaymentProcessor', $all, 'name', 'is_active', $condition, 'is_default desc, name');
1669 return self
::$paymentProcessor[$cacheKey];
1673 * Get all active payment processors
1675 * The static array paymentProcessorType is returned
1680 * @param boolean $all - get payment processors - default is to get only active ones.
1682 * @return array - array of all payment processor types
1685 public static function &paymentProcessorType($all = FALSE, $id = NULL, $return = 'title') {
1686 $cacheKey = $id . '_' .$return;
1687 if (empty(self
::$paymentProcessorType[$cacheKey])) {
1688 self
::populate(self
::$paymentProcessorType[$cacheKey], 'CRM_Financial_DAO_PaymentProcessorType', $all, $return, 'is_active', NULL, "is_default, $return", 'id');
1690 if ($id && CRM_Utils_Array
::value($id, self
::$paymentProcessorType[$cacheKey])) {
1691 return self
::$paymentProcessorType[$cacheKey][$id];
1693 return self
::$paymentProcessorType[$cacheKey];
1697 * Get all the World Regions from Database
1701 * @return array - array reference of all World Regions
1704 public static function &worldRegion($id = FALSE) {
1705 if (!self
::$worldRegions) {
1706 self
::populate(self
::$worldRegions, 'CRM_Core_DAO_Worldregion', TRUE, 'name', NULL, NULL, 'id');
1710 if (array_key_exists($id, self
::$worldRegions)) {
1711 return self
::$worldRegions[$id];
1714 return CRM_Core_DAO
::$_nullObject;
1718 return self
::$worldRegions;
1722 * Get all Honor Type.
1724 * The static array honorType is returned
1729 * @param boolean $all - get All Honor Type.
1731 * @return array - array reference of all Honor Types.
1734 public static function &honor() {
1735 if (!self
::$honorType) {
1736 self
::$honorType = CRM_Core_OptionGroup
::values('honor_type');
1738 return self
::$honorType;
1742 * Get all Activity Statuses.
1744 * The static array activityStatus is returned
1749 * @return array - array reference of all activity statuses
1751 public static function &activityStatus($column = 'label') {
1752 if (NULL === self
::$activityStatus) {
1753 self
::$activityStatus = array();
1755 if (!array_key_exists($column, self
::$activityStatus)) {
1756 self
::$activityStatus[$column] = array();
1758 self
::$activityStatus[$column] = CRM_Core_OptionGroup
::values('activity_status', FALSE, FALSE, FALSE, NULL, $column);
1761 return self
::$activityStatus[$column];
1765 * Get all Priorities
1767 * The static array Priority is returned
1772 * @return array - array reference of all Priority
1774 public static function &priority() {
1775 if (!self
::$priority) {
1776 self
::$priority = CRM_Core_OptionGroup
::values('priority');
1779 return self
::$priority;
1783 * Get all WYSIWYG Editors.
1785 * The static array wysiwygEditor is returned
1790 * @return array - array reference of all wysiwygEditors
1792 public static function &wysiwygEditor() {
1793 if (!self
::$wysiwygEditor) {
1794 self
::$wysiwygEditor = CRM_Core_OptionGroup
::values('wysiwyg_editor');
1796 return self
::$wysiwygEditor;
1800 * Get all Visibility levels.
1802 * The static array visibility is returned
1807 * @return array - array reference of all Visibility levels.
1810 public static function &visibility($column = 'label') {
1811 if (!isset(self
::$visibility)) {
1812 self
::$visibility = array( );
1815 if (!isset(self
::$visibility[$column])) {
1816 self
::$visibility[$column] = CRM_Core_OptionGroup
::values('visibility', FALSE, FALSE, FALSE, NULL, $column);
1819 return self
::$visibility[$column];
1823 * Get all mapping types
1825 * @return array - array reference of all mapping types
1829 public static function &mappingTypes() {
1830 if (!self
::$mappingType) {
1831 self
::$mappingType = CRM_Core_OptionGroup
::values('mapping_type');
1833 return self
::$mappingType;
1836 public static function &stateProvinceForCountry($countryID, $field = 'name') {
1837 static $_cache = NULL;
1839 $cacheKey = "{$countryID}_{$field}";
1844 if (!empty($_cache[$cacheKey])) {
1845 return $_cache[$cacheKey];
1849 SELECT civicrm_state_province.{$field} name, civicrm_state_province.id id
1850 FROM civicrm_state_province
1851 WHERE country_id = %1
1860 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1863 while ($dao->fetch()) {
1864 $result[$dao->id
] = $dao->name
;
1867 // localise the stateProvince names if in an non-en_US locale
1868 $config = CRM_Core_Config
::singleton();
1870 if ($tsLocale != '' and $tsLocale != 'en_US') {
1871 $i18n = CRM_Core_I18n
::singleton();
1872 $i18n->localizeArray($result, array(
1873 'context' => 'province',
1875 $result = CRM_Utils_Array
::asort($result);
1878 $_cache[$cacheKey] = $result;
1880 CRM_Utils_Hook
::buildStateProvinceForCountry($countryID, $result);
1885 public static function &countyForState($stateID) {
1886 if (is_array($stateID)) {
1887 $states = implode(", ", $stateID);
1889 SELECT civicrm_county.name name, civicrm_county.id id, civicrm_state_province.abbreviation abbreviation
1891 LEFT JOIN civicrm_state_province ON civicrm_county.state_province_id = civicrm_state_province.id
1892 WHERE civicrm_county.state_province_id in ( $states )
1893 ORDER BY civicrm_state_province.abbreviation, civicrm_county.name";
1895 $dao = CRM_Core_DAO
::executeQuery($query);
1898 while ($dao->fetch()) {
1899 $result[$dao->id
] = $dao->abbreviation
. ': ' . $dao->name
;
1904 static $_cache = NULL;
1906 $cacheKey = "{$stateID}_name";
1911 if (!empty($_cache[$cacheKey])) {
1912 return $_cache[$cacheKey];
1916 SELECT civicrm_county.name name, civicrm_county.id id
1918 WHERE state_province_id = %1
1927 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1930 while ($dao->fetch()) {
1931 $result[$dao->id
] = $dao->name
;
1939 * Given a state ID return the country ID, this allows
1940 * us to populate forms and values for downstream code
1942 * @param $stateID int
1944 * @return int the country id that the state belongs to
1948 static function countryIDForStateID($stateID) {
1949 if (empty($stateID)) {
1950 return CRM_Core_DAO
::$_nullObject;
1955 FROM civicrm_state_province
1958 $params = array(1 => array($stateID, 'Integer'));
1960 return CRM_Core_DAO
::singleValueQuery($query, $params);
1964 * Get all types of Greetings.
1966 * The static array of greeting is returned
1971 * @param $filter - get All Email Greetings - default is to get only active ones.
1973 * @return array - array reference of all greetings.
1976 public static function greeting($filter, $columnName = 'label') {
1977 $index = $filter['greeting_type'] . '_' . $columnName;
1979 // also add contactType to the array
1980 $contactType = CRM_Utils_Array
::value('contact_type', $filter);
1982 $index .= '_' . $contactType;
1985 if (NULL === self
::$greeting) {
1986 self
::$greeting = array();
1989 if (!CRM_Utils_Array
::value($index, self
::$greeting)) {
1990 $filterCondition = NULL;
1992 $filterVal = 'v.filter =';
1993 switch ($contactType) {
2002 case 'Organization':
2006 $filterCondition .= "AND (v.filter = 0 OR {$filterVal}) ";
2009 self
::$greeting[$index] = CRM_Core_OptionGroup
::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName);
2012 return self
::$greeting[$index];
2016 * Construct array of default greeting values for contact type
2021 * @return array - array reference of default greetings.
2024 public static function &greetingDefaults() {
2025 if (!self
::$greetingDefaults) {
2026 $defaultGreetings = array();
2027 $contactTypes = array(
2030 'Organization' => 3,
2033 foreach ($contactTypes as $contactType => $filter) {
2034 $filterCondition = " AND (v.filter = 0 OR v.filter = $filter) AND v.is_default = 1 ";
2036 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
2037 $tokenVal = CRM_Core_OptionGroup
::values($greeting, NULL, NULL, NULL, $filterCondition, 'label');
2038 $defaultGreetings[$contactType][$greeting] = $tokenVal;
2042 self
::$greetingDefaults = $defaultGreetings;
2045 return self
::$greetingDefaults;
2049 * Get all the Languages from database.
2054 * @return array self::languages - array reference of all languages
2057 public static function &languages() {
2058 return CRM_Core_I18n_PseudoConstant
::languages();
2064 public static function &preferredLanguage() {
2065 return CRM_Core_I18n_PseudoConstant
::languages();
2069 * Get all extensions
2071 * The static array extensions
2073 * FIXME: This is called by civix but not by any core code. We
2074 * should provide an API call which civix can use instead.
2079 * @return array - array($fullyQualifiedName => $label) list of extensions
2081 public static function &getExtensions() {
2082 if (!self
::$extensions) {
2083 self
::$extensions = array();
2085 SELECT full_name, label
2086 FROM civicrm_extension
2089 $dao = CRM_Core_DAO
::executeQuery($sql);
2090 while ($dao->fetch()) {
2091 self
::$extensions[$dao->full_name
] = $dao->label
;
2095 return self
::$extensions;
2099 * Fetch the list of active extensions of type 'module'
2101 * @param $fresh bool whether to forcibly reload extensions list from canonical store
2105 * @return array - array(array('prefix' => $, 'file' => $))
2107 public static function getModuleExtensions($fresh = FALSE) {
2108 return CRM_Extension_System
::singleton()->getMapper()->getActiveModuleFiles($fresh);
2112 * Get all Activity Contacts
2114 * The static array activityContacts is returned
2119 * @param string $column db column name/label.
2121 * @return array - array reference of all activity Contacts
2124 public static function &activityContacts($column = 'label') {
2125 if (!self
::$activityContacts) {
2126 self
::$activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, $column);
2128 return self
::$activityContacts;
2132 * Get all Event Contacts
2134 * The static array eventContacts is returned
2139 * @param string $column db column name/label.
2141 * @return array - array reference of all event Contacts
2144 public static function &eventContacts($column = 'label') {
2145 if (!self
::$eventContacts) {
2146 self
::$eventContacts = CRM_Core_OptionGroup
::values('event_contacts', FALSE, FALSE, FALSE, NULL, $column);
2148 return self
::$eventContacts;
2152 * Get all options values
2154 * The static array option values is returned
2159 * @param boolean $optionGroupName - get All Option Group values- default is to get only active ones.
2161 * @return array - array reference of all Option Group Name
2164 public static function accountOptionValues($optionGroupName, $id = null, $condition = null) {
2165 $cacheKey = $optionGroupName . '_' . $condition;
2166 if (empty(self
::$accountOptionValues[$cacheKey])) {
2167 self
::$accountOptionValues[$cacheKey] = CRM_Core_OptionGroup
::values($optionGroupName, false, false, false, $condition);
2170 return CRM_Utils_Array
::value($id, self
::$accountOptionValues[$cacheKey]);
2173 return self
::$accountOptionValues[$cacheKey];
2177 * Get all batch modes
2179 * The static array batchModes
2184 * @return array - array reference of all batch modes
2186 public static function &getBatchMode($columnName = 'label') {
2187 if (!self
::$batchModes) {
2188 self
::$batchModes = CRM_Core_OptionGroup
::values('batch_mode', false, false, false, null, $columnName);
2191 return self
::$batchModes;
2195 * Get all batch types
2197 * The static array batchTypes
2202 * @return array - array reference of all batch types
2204 public static function &getBatchType() {
2205 if (!self
::$batchTypes) {
2206 self
::$batchTypes = CRM_Core_OptionGroup
::values('batch_type');
2209 return self
::$batchTypes;
2213 * Get all batch statuses
2215 * The static array batchStatues
2220 * @return array - array reference of all batch statuses
2222 public static function &getBatchStatus() {
2223 if (!self
::$batchStatues) {
2224 self
::$batchStatues = CRM_Core_OptionGroup
::values('batch_status');
2227 return self
::$batchStatues;
2231 * The static array contactType is returned
2235 * @param string $column db column name/label.
2237 * @return array - array reference of all Types
2241 public static function &contactType($column = 'label') {
2242 if (!self
::$contactType) {
2243 self
::$contactType = CRM_Contact_BAO_ContactType
::basicTypePairs(TRUE);
2245 return self
::$contactType;
2249 * Get all the auto renew options
2254 * @return array self::autoRenew - array reference of all autoRenew
2257 public static function &autoRenew() {
2258 if (!self
::$autoRenew) {
2259 self
::$autoRenew = CRM_Core_OptionGroup
::values('auto_renew_options', FALSE, FALSE);
2261 return self
::$autoRenew;