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(&$var, $name, $all = FALSE, $retrieve = 'name', $filter = 'is_active', $condition = NULL, $orderby = NULL, $key = 'id', $force = NULL) {
423 $cacheKey = "CRM_PC_{$name}_{$all}_{$key}_{$retrieve}_{$filter}_{$condition}_{$orderby}";
424 $cache = CRM_Utils_Cache
::singleton();
425 $var = $cache->get($cacheKey);
426 if ($var && empty($force)) {
430 $object = new $name ( );
432 $object->selectAdd();
433 $object->selectAdd("$key, $retrieve");
435 $object->whereAdd($condition);
439 $object->orderBy($retrieve);
442 $object->orderBy($orderby);
446 $object->$filter = 1;
451 while ($object->fetch()) {
452 $var[$object->$key] = $object->$retrieve;
455 $cache->set($cacheKey, $var);
459 * Flush given pseudoconstant so it can be reread from db
460 * nex time it's requested.
465 * @param boolean $name pseudoconstant to be flushed
468 public static function flush($name) {
473 * Get all location types.
475 * The static array locationType is returned
480 * @param boolean $all - get All location types - default is to get only active ones.
482 * @return array - array reference of all location types.
485 public static function &locationType($all = FALSE) {
486 if (!self
::$locationType) {
487 self
::populate(self
::$locationType, 'CRM_Core_DAO_LocationType', $all);
489 return self
::$locationType;
493 * Get all location vCard names.
495 * The static array locationVcardName is returned
500 * @param boolean $all - get All location vCard names - default is to get only active ones.
502 * @return array - array reference of all location vCard names.
505 public static function &locationVcardName($all = FALSE) {
506 if (!self
::$locationVcardName) {
507 self
::populate(self
::$locationVcardName, 'CRM_Core_DAO_LocationType', $all, 'vcard_name');
509 return self
::$locationVcardName;
513 * Get all location Display names.
515 * The static array locationDisplayName is returned
520 * @param boolean $all - get All location display names - default is to get only active ones.
522 * @return array - array reference of all location display names.
525 public static function &locationDisplayName($all = FALSE) {
526 if (!self
::$locationDisplayName) {
527 self
::populate(self
::$locationDisplayName, 'CRM_Core_DAO_LocationType', $all, 'display_name');
529 return self
::$locationDisplayName;
533 * Get all Activty types.
535 * The static array activityType is returned
537 * @param boolean $all - get All Activity types - default is to get only active ones.
542 * @return array - array reference of all activity types.
544 public static function &activityType() {
545 $args = func_get_args();
546 $all = CRM_Utils_Array
::value(0, $args, TRUE);
547 $includeCaseActivities = CRM_Utils_Array
::value(1, $args, FALSE);
548 $reset = CRM_Utils_Array
::value(2, $args, FALSE);
549 $returnColumn = CRM_Utils_Array
::value(3, $args, 'label');
550 $includeCampaignActivities = CRM_Utils_Array
::value(4, $args, FALSE);
551 $onlyComponentActivities = CRM_Utils_Array
::value(5, $args, FALSE);
552 $index = (int) $all . '_' . $returnColumn . '_' . (int) $includeCaseActivities;
553 $index .= '_' . (int) $includeCampaignActivities;
554 $index .= '_' . (int) $onlyComponentActivities;
556 if (NULL === self
::$activityType) {
557 self
::$activityType = array();
560 if (!isset(self
::$activityType[$index]) ||
$reset) {
563 $condition = 'AND filter = 0';
565 $componentClause = " v.component_id IS NULL";
566 if ($onlyComponentActivities) {
567 $componentClause = " v.component_id IS NOT NULL";
570 $componentIds = array();
571 $compInfo = CRM_Core_Component
::getEnabledComponents();
573 // build filter for listing activity types only if their
574 // respective components are enabled
575 foreach ($compInfo as $compName => $compObj) {
576 if ($compName == 'CiviCase') {
577 if ($includeCaseActivities) {
578 $componentIds[] = $compObj->componentID
;
581 elseif ($compName == 'CiviCampaign') {
582 if ($includeCampaignActivities) {
583 $componentIds[] = $compObj->componentID
;
587 $componentIds[] = $compObj->componentID
;
591 if (count($componentIds)) {
592 $componentIds = implode(',', $componentIds);
593 $componentClause = " ($componentClause OR v.component_id IN ($componentIds))";
594 if ($onlyComponentActivities) {
595 $componentClause = " ( v.component_id IN ($componentIds ) )";
598 $condition = $condition . ' AND ' . $componentClause;
600 self
::$activityType[$index] = CRM_Core_OptionGroup
::values('activity_type', FALSE, FALSE, FALSE, $condition, $returnColumn);
602 return self
::$activityType[$index];
606 * Get all payment-processor billing modes
611 * @return array ($id => $name)
613 public static function billingMode() {
614 if (!self
::$billingMode) {
615 self
::$billingMode = array(
616 CRM_Core_Payment
::BILLING_MODE_FORM
=> 'form',
617 CRM_Core_Payment
::BILLING_MODE_BUTTON
=> 'button',
618 CRM_Core_Payment
::BILLING_MODE_NOTIFY
=> 'notify',
621 return self
::$billingMode;
625 * Get all component names
630 * @return array - array reference of all location display names.
633 public static function &component() {
634 if (!self
::$component) {
635 self
::populate(self
::$component, 'CRM_Core_DAO_Component', TRUE, 'name');
637 return self
::$component;
642 * Get all Individual Prefix.
644 * The static array individualPrefix is returned
649 * @param boolean $all - get All Individual Prefix - default is to get only active ones.
651 * @return array - array reference of all individual prefix.
654 public static function &individualPrefix() {
655 if (!self
::$individualPrefix) {
656 self
::$individualPrefix = CRM_Core_OptionGroup
::values('individual_prefix');
658 return self
::$individualPrefix;
663 * The static array phoneType is returned
668 * @param boolean $all - get All phone type - default is to get
671 * @return array - array reference of all phone types.
674 public static function &phoneType() {
675 if (!self
::$phoneType) {
676 self
::$phoneType = CRM_Core_OptionGroup
::values('phone_type');
678 return self
::$phoneType;
682 * Get all Individual Suffix.
684 * The static array individualSuffix is returned
689 * @param boolean $all - get All Individual Suffix - default is to get only active ones.
691 * @return array - array reference of all individual suffix.
694 public static function &individualSuffix() {
695 if (!self
::$individualSuffix) {
696 self
::$individualSuffix = CRM_Core_OptionGroup
::values('individual_suffix');
698 return self
::$individualSuffix;
704 * The static array gender is returned
709 * @param boolean $all - get All Gender - default is to get only active ones.
711 * @return array - array reference of all gender.
714 public static function &gender($localize = FALSE) {
715 if (!self
::$gender) {
716 self
::$gender = CRM_Core_OptionGroup
::values('gender', FALSE, FALSE, $localize);
718 return self
::$gender;
722 * Get all the IM Providers from database.
724 * The static array imProvider is returned, and if it's
725 * called the first time, the <b>IM DAO</b> is used
726 * to get all the IM Providers.
728 * Note: any database errors will be trapped by the DAO.
733 * @return array - array reference of all IM providers.
736 public static function &IMProvider($localize = FALSE) {
737 if (!self
::$imProvider) {
738 self
::$imProvider = CRM_Core_OptionGroup
::values('instant_messenger_service', FALSE, FALSE, $localize);
740 return self
::$imProvider;
744 * Get all the website types from database.
746 * The static array websiteType is returned, and if it's
747 * called the first time, the <b>Website DAO</b> is used
748 * to get all the Website Types.
750 * Note: any database errors will be trapped by the DAO.
755 * @return array - array reference of all Website types.
758 public static function &websiteType() {
759 if (!self
::$websiteType) {
760 self
::$websiteType = CRM_Core_OptionGroup
::values('website_type');
762 return self
::$websiteType;
766 * Get the all From Email Address from database.
768 * The static array $fromEmailAddress is returned, and if it's
769 * called the first time, DAO is used
770 * to get all the From Email Address
772 * Note: any database errors will be trapped by the DAO.
777 * @return array - array reference of all From Email Address.
779 public static function &fromEmailAddress() {
780 if (!self
::$fromEmailAddress) {
781 self
::$fromEmailAddress = CRM_Core_OptionGroup
::values('from_email_address');
783 return self
::$fromEmailAddress;
787 * Get the all Mail Protocols from database.
789 * The static array mailProtocol is returned, and if it's
790 * called the first time, the DAO is used
791 * to get all the Mail Protocol.
793 * Note: any database errors will be trapped by the DAO.
798 * @return array - array reference of all Mail Protocols.
800 public static function &mailProtocol() {
801 if (!self
::$mailProtocol) {
802 self
::$mailProtocol = CRM_Core_OptionGroup
::values('mail_protocol');
804 return self
::$mailProtocol;
808 * Get all the State/Province from database.
810 * The static array stateProvince is returned, and if it's
811 * called the first time, the <b>State Province DAO</b> is used
812 * to get all the States.
814 * Note: any database errors will be trapped by the DAO.
819 * @param int $id - Optional id to return
821 * @return array - array reference of all State/Provinces.
824 public static function &stateProvince($id = FALSE, $limit = TRUE) {
825 if (($id && !CRM_Utils_Array
::value($id, self
::$stateProvince)) ||
!self
::$stateProvince ||
!$id) {
826 $whereClause = FALSE;
827 $config = CRM_Core_Config
::singleton();
829 $countryIsoCodes = self
::countryIsoCode();
830 $limitCodes = $config->provinceLimit();
832 foreach ($limitCodes as $code) {
833 $limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
835 if (!empty($limitIds)) {
836 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
839 $whereClause = FALSE;
842 self
::populate(self
::$stateProvince, 'CRM_Core_DAO_StateProvince', TRUE, 'name', 'is_active', $whereClause);
844 // localise the province names if in an non-en_US locale
846 if ($tsLocale != '' and $tsLocale != 'en_US') {
847 $i18n = CRM_Core_I18n
::singleton();
848 $i18n->localizeArray(self
::$stateProvince, array(
849 'context' => 'province',
851 self
::$stateProvince = CRM_Utils_Array
::asort(self
::$stateProvince);
855 if (array_key_exists($id, self
::$stateProvince)) {
856 return self
::$stateProvince[$id];
863 return self
::$stateProvince;
867 * Get all the State/Province abbreviations from the database.
869 * Same as above, except gets the abbreviations instead of the names.
874 * @param int $id - Optional id to return
876 * @return array - array reference of all State/Province abbreviations.
878 public static function &stateProvinceAbbreviation($id = FALSE, $limit = TRUE) {
882 FROM civicrm_state_province
890 return CRM_Core_DAO
::singleValueQuery($query, $params);
893 if (!self
::$stateProvinceAbbreviation ||
!$id) {
895 $whereClause = FALSE;
898 $config = CRM_Core_Config
::singleton();
899 $countryIsoCodes = self
::countryIsoCode();
900 $limitCodes = $config->provinceLimit();
902 foreach ($limitCodes as $code) {
903 $tmpArray = array_keys($countryIsoCodes, $code);
905 if (!empty($tmpArray)) {
906 $limitIds[] = array_shift($tmpArray);
909 if (!empty($limitIds)) {
910 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
913 self
::populate(self
::$stateProvinceAbbreviation, 'CRM_Core_DAO_StateProvince', TRUE, 'abbreviation', 'is_active', $whereClause);
917 if (array_key_exists($id, self
::$stateProvinceAbbreviation)) {
918 return self
::$stateProvinceAbbreviation[$id];
925 return self
::$stateProvinceAbbreviation;
929 * Get all the countries from database.
931 * The static array country is returned, and if it's
932 * called the first time, the <b>Country DAO</b> is used
933 * to get all the countries.
935 * Note: any database errors will be trapped by the DAO.
940 * @param int $id - Optional id to return
942 * @return array - array reference of all countries.
945 public static function country($id = FALSE, $applyLimit = TRUE) {
946 if (($id && !CRM_Utils_Array
::value($id, self
::$country)) ||
!self
::$country ||
!$id) {
948 $config = CRM_Core_Config
::singleton();
949 $limitCodes = array();
952 // limit the country list to the countries specified in CIVICRM_COUNTRY_LIMIT
953 // (ensuring it's a subset of the legal values)
954 // K/P: We need to fix this, i dont think it works with new setting files
955 $limitCodes = $config->countryLimit();
956 if (!is_array($limitCodes)) {
958 $config->countryLimit
=> 1,
962 $limitCodes = array_intersect(self
::countryIsoCode(), $limitCodes);
965 if (count($limitCodes)) {
966 $whereClause = "iso_code IN ('" . implode("', '", $limitCodes) . "')";
972 self
::populate(self
::$country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active', $whereClause);
974 // if default country is set, percolate it to the top
975 if ($config->defaultContactCountry()) {
976 $countryIsoCodes = self
::countryIsoCode();
977 $defaultID = array_search($config->defaultContactCountry(), $countryIsoCodes);
978 if ($defaultID !== FALSE) {
979 $default[$defaultID] = CRM_Utils_Array
::value($defaultID, self
::$country);
980 self
::$country = $default + self
::$country;
984 // localise the country names if in an non-en_US locale
986 if ($tsLocale != '' and $tsLocale != 'en_US') {
987 $i18n = CRM_Core_I18n
::singleton();
988 $i18n->localizeArray(self
::$country, array(
989 'context' => 'country',
991 self
::$country = CRM_Utils_Array
::asort(self
::$country);
995 if (array_key_exists($id, self
::$country)) {
996 return self
::$country[$id];
1002 return self
::$country;
1006 * Get all the country ISO Code abbreviations from the database.
1008 * The static array countryIsoCode is returned, and if it's
1009 * called the first time, the <b>Country DAO</b> is used
1010 * to get all the countries' ISO codes.
1012 * Note: any database errors will be trapped by the DAO.
1017 * @return array - array reference of all country ISO codes.
1020 public static function &countryIsoCode($id = FALSE) {
1021 if (!self
::$countryIsoCode) {
1022 self
::populate(self
::$countryIsoCode, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
1025 if (array_key_exists($id, self
::$countryIsoCode)) {
1026 return self
::$countryIsoCode[$id];
1032 return self
::$countryIsoCode;
1036 * Get all the categories from database.
1038 * The static array tag is returned, and if it's
1039 * called the first time, the <b>Tag DAO</b> is used
1040 * to get all the categories.
1042 * Note: any database errors will be trapped by the DAO.
1047 * @return array - array reference of all categories.
1050 public static function &tag() {
1052 self
::populate(self
::$tag, 'CRM_Core_DAO_Tag', TRUE);
1058 * Get all groups from database
1060 * The static array group is returned, and if it's
1061 * called the first time, the <b>Group DAO</b> is used
1062 * to get all the groups.
1064 * Note: any database errors will be trapped by the DAO.
1066 * @param string $groupType type of group(Access/Mailing)
1067 * @param boolen $excludeHidden exclude hidden groups.
1072 * @return array - array reference of all groups.
1075 public static function &allGroup($groupType = NULL, $excludeHidden = TRUE) {
1076 $condition = CRM_Contact_BAO_Group
::groupTypeCondition($groupType, $excludeHidden);
1078 if (!self
::$group) {
1079 self
::$group = array();
1082 $groupKey = $groupType ?
$groupType : 'null';
1084 if (!isset(self
::$group[$groupKey])) {
1085 self
::$group[$groupKey] = NULL;
1086 self
::populate(self
::$group[$groupKey], 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition);
1088 return self
::$group[$groupKey];
1092 * Create or get groups iterator (iterates over nested groups in a
1095 * The GroupNesting instance is returned; it's created if this is being
1096 * called for the first time
1102 * @return mixed - instance of CRM_Contact_BAO_GroupNesting
1105 public static function &groupIterator($styledLabels = FALSE) {
1106 if (!self
::$groupIterator) {
1108 When used as an object, GroupNesting implements Iterator
1109 and iterates nested groups in a logical manner for us
1112 self
::$groupIterator = new CRM_Contact_BAO_GroupNesting($styledLabels);
1114 return self
::$groupIterator;
1118 * Get all permissioned groups from database
1120 * The static array group is returned, and if it's
1121 * called the first time, the <b>Group DAO</b> is used
1122 * to get all the groups.
1124 * Note: any database errors will be trapped by the DAO.
1126 * @param string $groupType type of group(Access/Mailing)
1127 * @param boolen $excludeHidden exclude hidden groups.
1132 * @return array - array reference of all groups.
1135 public static function group($groupType = NULL, $excludeHidden = TRUE) {
1136 return CRM_Core_Permission
::group($groupType, $excludeHidden);
1140 * Get all permissioned groups from database
1142 * The static array group is returned, and if it's
1143 * called the first time, the <b>Group DAO</b> is used
1144 * to get all the groups.
1146 * Note: any database errors will be trapped by the DAO.
1151 * @return array - array reference of all groups.
1154 public static function &staticGroup($onlyPublic = FALSE, $groupType = NULL, $excludeHidden = TRUE) {
1155 if (!self
::$staticGroup) {
1156 $condition = 'saved_search_id = 0 OR saved_search_id IS NULL';
1158 $condition .= " AND visibility != 'User and User Admin Only'";
1162 $condition .= ' AND ' . CRM_Contact_BAO_Group
::groupTypeCondition($groupType);
1165 if ($excludeHidden) {
1166 $condition .= ' AND is_hidden != 1 ';
1169 self
::populate(self
::$staticGroup, 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition, 'title');
1172 return self
::$staticGroup;
1176 * Get all the custom groups
1180 * @return array - array reference of all groups.
1183 public static function &customGroup($reset = FALSE) {
1184 if (!self
::$customGroup ||
$reset) {
1185 self
::populate(self
::$customGroup, 'CRM_Core_DAO_CustomGroup', FALSE, 'title', 'is_active', NULL, 'title');
1187 return self
::$customGroup;
1191 * Get all the user framework groups
1195 * @return array - array reference of all groups.
1198 public static function &ufGroup() {
1199 if (!self
::$ufGroup) {
1200 self
::populate(self
::$ufGroup, 'CRM_Core_DAO_UFGroup', FALSE, 'title', 'is_active', NULL, 'title');
1202 return self
::$ufGroup;
1206 * Get all the project tasks
1210 * @return array - array reference of all tasks
1213 public static function &tasks() {
1214 if (!self
::$tasks) {
1215 self
::populate(self
::$tasks, 'CRM_Project_DAO_Task', FALSE, 'title', 'is_active', NULL, 'title');
1217 return self
::$tasks;
1221 * Get all Relationship Types from database.
1223 * The static array group is returned, and if it's
1224 * called the first time, the <b>RelationshipType DAO</b> is used
1225 * to get all the relationship types.
1227 * Note: any database errors will be trapped by the DAO.
1229 * @param string $valueColumnName db column name/label.
1230 * @param boolean $reset reset relationship types if true
1235 * @return array - array reference of all relationship types.
1237 public static function &relationshipType($valueColumnName = 'label', $reset = FALSE) {
1238 if (!CRM_Utils_Array
::value($valueColumnName, self
::$relationshipType) ||
$reset) {
1239 self
::$relationshipType[$valueColumnName] = array();
1241 //now we have name/label columns CRM-3336
1242 $column_a_b = "{$valueColumnName}_a_b";
1243 $column_b_a = "{$valueColumnName}_b_a";
1245 $relationshipTypeDAO = new CRM_Contact_DAO_RelationshipType();
1246 $relationshipTypeDAO->selectAdd();
1247 $relationshipTypeDAO->selectAdd("id, {$column_a_b}, {$column_b_a}, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b");
1248 $relationshipTypeDAO->is_active
= 1;
1249 $relationshipTypeDAO->find();
1250 while ($relationshipTypeDAO->fetch()) {
1252 self
::$relationshipType[$valueColumnName][$relationshipTypeDAO->id
] = array(
1253 $column_a_b => $relationshipTypeDAO->$column_a_b,
1254 $column_b_a => $relationshipTypeDAO->$column_b_a,
1255 'contact_type_a' => "$relationshipTypeDAO->contact_type_a",
1256 'contact_type_b' => "$relationshipTypeDAO->contact_type_b",
1257 'contact_sub_type_a' => "$relationshipTypeDAO->contact_sub_type_a",
1258 'contact_sub_type_b' => "$relationshipTypeDAO->contact_sub_type_b",
1263 return self
::$relationshipType[$valueColumnName];
1267 * Get all the Currency Symbols from Database
1271 * @return array - array reference of all Currency Symbols
1274 public static function ¤cySymbols($name = 'symbol', $key = 'id') {
1275 $cacheKey = "{$name}_{$key}";
1276 if (!isset(self
::$currencySymbols[$cacheKey])) {
1277 self
::populate(self
::$currencySymbols[$cacheKey], 'CRM_Financial_DAO_Currency', TRUE, $name, NULL, NULL, 'name', $key);
1280 return self
::$currencySymbols[$cacheKey];
1284 * get all the ISO 4217 currency codes
1286 * so far, we use this for validation only, so there's no point of putting this into the database
1290 * @return array - array reference of all currency codes
1293 public static function ¤cyCode() {
1294 if (!self
::$currencyCode) {
1295 self
::$currencyCode = array(
1565 return self
::$currencyCode;
1569 * Get all the County from database.
1571 * The static array county is returned, and if it's
1572 * called the first time, the <b>County DAO</b> is used
1573 * to get all the Counties.
1575 * Note: any database errors will be trapped by the DAO.
1580 * @param int $id - Optional id to return
1582 * @return array - array reference of all Counties
1585 public static function &county($id = FALSE) {
1586 if (!self
::$county) {
1588 $config = CRM_Core_Config
::singleton();
1589 // order by id so users who populate civicrm_county can have more control over sort by the order they load the counties
1590 self
::populate(self
::$county, 'CRM_Core_DAO_County', TRUE, 'name', NULL, NULL, 'id');
1593 if (array_key_exists($id, self
::$county)) {
1594 return self
::$county[$id];
1600 return self
::$county;
1604 * Get all the Preferred Communication Methods from database.
1609 * @return array self::pcm - array reference of all preferred communication methods.
1612 public static function &pcm($localize = FALSE) {
1614 self
::$pcm = CRM_Core_OptionGroup
::values('preferred_communication_method', FALSE, FALSE, $localize);
1622 public static function preferredCommunicationMethod($localize = FALSE) {
1623 return self
::pcm($localize);
1627 * Get all active payment processors
1629 * The static array paymentProcessor is returned
1634 * @param boolean $all - get payment processors - default is to get only active ones.
1635 * @param boolean $test - get test payment processors
1637 * @return array - array of all payment processors
1640 public static function &paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
1641 $condition = "is_test = ";
1642 $condition .= ($test) ?
'1' : '0';
1644 if ($additionalCond) {
1645 $condition .= " AND ( $additionalCond ) ";
1648 // CRM-7178. Make sure we only include payment processors valid in ths
1650 $condition .= " AND domain_id = " . CRM_Core_Config
::domainID();
1652 $cacheKey = $condition . '_' . (int) $all;
1653 if (!isset(self
::$paymentProcessor[$cacheKey])) {
1654 self
::populate(self
::$paymentProcessor[$cacheKey], 'CRM_Financial_DAO_PaymentProcessor', $all, 'name', 'is_active', $condition, 'is_default desc, name');
1657 return self
::$paymentProcessor[$cacheKey];
1661 * Get all active payment processors
1663 * The static array paymentProcessorType is returned
1668 * @param boolean $all - get payment processors - default is to get only active ones.
1670 * @return array - array of all payment processor types
1673 public static function &paymentProcessorType($all = FALSE, $id = NULL, $return = 'title') {
1674 $cacheKey = $id . '_' .$return;
1675 if (empty(self
::$paymentProcessorType[$cacheKey])) {
1676 self
::populate(self
::$paymentProcessorType[$cacheKey], 'CRM_Financial_DAO_PaymentProcessorType', $all, $return, 'is_active', NULL, "is_default, $return", 'id');
1678 if ($id && CRM_Utils_Array
::value($id, self
::$paymentProcessorType[$cacheKey])) {
1679 return self
::$paymentProcessorType[$cacheKey][$id];
1681 return self
::$paymentProcessorType[$cacheKey];
1685 * Get all the World Regions from Database
1689 * @return array - array reference of all World Regions
1692 public static function &worldRegion($id = FALSE) {
1693 if (!self
::$worldRegions) {
1694 self
::populate(self
::$worldRegions, 'CRM_Core_DAO_Worldregion', TRUE, 'name', NULL, NULL, 'id');
1698 if (array_key_exists($id, self
::$worldRegions)) {
1699 return self
::$worldRegions[$id];
1706 return self
::$worldRegions;
1710 * Get all Honor Type.
1712 * The static array honorType is returned
1717 * @param boolean $all - get All Honor Type.
1719 * @return array - array reference of all Honor Types.
1722 public static function &honor() {
1723 if (!self
::$honorType) {
1724 self
::$honorType = CRM_Core_OptionGroup
::values('honor_type');
1726 return self
::$honorType;
1730 * Get all Activity Statuses.
1732 * The static array activityStatus is returned
1737 * @return array - array reference of all activity statuses
1739 public static function &activityStatus($column = 'label') {
1740 if (NULL === self
::$activityStatus) {
1741 self
::$activityStatus = array();
1743 if (!array_key_exists($column, self
::$activityStatus)) {
1744 self
::$activityStatus[$column] = array();
1746 self
::$activityStatus[$column] = CRM_Core_OptionGroup
::values('activity_status', FALSE, FALSE, FALSE, NULL, $column);
1749 return self
::$activityStatus[$column];
1753 * Get all Priorities
1755 * The static array Priority is returned
1760 * @return array - array reference of all Priority
1762 public static function &priority() {
1763 if (!self
::$priority) {
1764 self
::$priority = CRM_Core_OptionGroup
::values('priority');
1767 return self
::$priority;
1771 * Get all WYSIWYG Editors.
1773 * The static array wysiwygEditor is returned
1778 * @return array - array reference of all wysiwygEditors
1780 public static function &wysiwygEditor() {
1781 if (!self
::$wysiwygEditor) {
1782 self
::$wysiwygEditor = CRM_Core_OptionGroup
::values('wysiwyg_editor');
1784 return self
::$wysiwygEditor;
1788 * Get all Visibility levels.
1790 * The static array visibility is returned
1795 * @return array - array reference of all Visibility levels.
1798 public static function &visibility($column = 'label') {
1799 if (!isset(self
::$visibility)) {
1800 self
::$visibility = array( );
1803 if (!isset(self
::$visibility[$column])) {
1804 self
::$visibility[$column] = CRM_Core_OptionGroup
::values('visibility', FALSE, FALSE, FALSE, NULL, $column);
1807 return self
::$visibility[$column];
1811 * Get all mapping types
1813 * @return array - array reference of all mapping types
1817 public static function &mappingTypes() {
1818 if (!self
::$mappingType) {
1819 self
::$mappingType = CRM_Core_OptionGroup
::values('mapping_type');
1821 return self
::$mappingType;
1824 public static function &stateProvinceForCountry($countryID, $field = 'name') {
1825 static $_cache = NULL;
1827 $cacheKey = "{$countryID}_{$field}";
1832 if (!empty($_cache[$cacheKey])) {
1833 return $_cache[$cacheKey];
1837 SELECT civicrm_state_province.{$field} name, civicrm_state_province.id id
1838 FROM civicrm_state_province
1839 WHERE country_id = %1
1848 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1851 while ($dao->fetch()) {
1852 $result[$dao->id
] = $dao->name
;
1855 // localise the stateProvince names if in an non-en_US locale
1856 $config = CRM_Core_Config
::singleton();
1858 if ($tsLocale != '' and $tsLocale != 'en_US') {
1859 $i18n = CRM_Core_I18n
::singleton();
1860 $i18n->localizeArray($result, array(
1861 'context' => 'province',
1863 $result = CRM_Utils_Array
::asort($result);
1866 $_cache[$cacheKey] = $result;
1868 CRM_Utils_Hook
::buildStateProvinceForCountry($countryID, $result);
1873 public static function &countyForState($stateID) {
1874 if (is_array($stateID)) {
1875 $states = implode(", ", $stateID);
1877 SELECT civicrm_county.name name, civicrm_county.id id, civicrm_state_province.abbreviation abbreviation
1879 LEFT JOIN civicrm_state_province ON civicrm_county.state_province_id = civicrm_state_province.id
1880 WHERE civicrm_county.state_province_id in ( $states )
1881 ORDER BY civicrm_state_province.abbreviation, civicrm_county.name";
1883 $dao = CRM_Core_DAO
::executeQuery($query);
1886 while ($dao->fetch()) {
1887 $result[$dao->id
] = $dao->abbreviation
. ': ' . $dao->name
;
1892 static $_cache = NULL;
1894 $cacheKey = "{$stateID}_name";
1899 if (!empty($_cache[$cacheKey])) {
1900 return $_cache[$cacheKey];
1904 SELECT civicrm_county.name name, civicrm_county.id id
1906 WHERE state_province_id = %1
1915 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1918 while ($dao->fetch()) {
1919 $result[$dao->id
] = $dao->name
;
1927 * Get all types of Greetings.
1929 * The static array of greeting is returned
1934 * @param $filter - get All Email Greetings - default is to get only active ones.
1936 * @return array - array reference of all greetings.
1939 public static function greeting($filter, $columnName = 'label') {
1940 $index = $filter['greeting_type'] . '_' . $columnName;
1942 // also add contactType to the array
1943 $contactType = CRM_Utils_Array
::value('contact_type', $filter);
1945 $index .= '_' . $contactType;
1948 if (NULL === self
::$greeting) {
1949 self
::$greeting = array();
1952 if (!CRM_Utils_Array
::value($index, self
::$greeting)) {
1953 $filterCondition = NULL;
1955 $filterVal = 'v.filter =';
1956 switch ($contactType) {
1965 case 'Organization':
1969 $filterCondition .= "AND (v.filter = 0 OR {$filterVal}) ";
1972 self
::$greeting[$index] = CRM_Core_OptionGroup
::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName);
1975 return self
::$greeting[$index];
1979 * Construct array of default greeting values for contact type
1984 * @return array - array reference of default greetings.
1987 public static function &greetingDefaults() {
1988 if (!self
::$greetingDefaults) {
1989 $defaultGreetings = array();
1990 $contactTypes = array(
1993 'Organization' => 3,
1996 foreach ($contactTypes as $contactType => $filter) {
1997 $filterCondition = " AND (v.filter = 0 OR v.filter = $filter) AND v.is_default = 1 ";
1999 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
2000 $tokenVal = CRM_Core_OptionGroup
::values($greeting, NULL, NULL, NULL, $filterCondition, 'label');
2001 $defaultGreetings[$contactType][$greeting] = $tokenVal;
2005 self
::$greetingDefaults = $defaultGreetings;
2008 return self
::$greetingDefaults;
2012 * Get all the Languages from database.
2017 * @return array self::languages - array reference of all languages
2020 public static function &languages() {
2021 return CRM_Core_I18n_PseudoConstant
::languages();
2027 public static function &preferredLanguage() {
2028 return CRM_Core_I18n_PseudoConstant
::languages();
2032 * Get all extensions
2034 * The static array extensions
2036 * FIXME: This is called by civix but not by any core code. We
2037 * should provide an API call which civix can use instead.
2042 * @return array - array($fullyQualifiedName => $label) list of extensions
2044 public static function &getExtensions() {
2045 if (!self
::$extensions) {
2046 self
::$extensions = array();
2048 SELECT full_name, label
2049 FROM civicrm_extension
2052 $dao = CRM_Core_DAO
::executeQuery($sql);
2053 while ($dao->fetch()) {
2054 self
::$extensions[$dao->full_name
] = $dao->label
;
2058 return self
::$extensions;
2062 * Fetch the list of active extensions of type 'module'
2064 * @param $fresh bool whether to forcibly reload extensions list from canonical store
2068 * @return array - array(array('prefix' => $, 'file' => $))
2070 public static function getModuleExtensions($fresh = FALSE) {
2071 return CRM_Extension_System
::singleton()->getMapper()->getActiveModuleFiles($fresh);
2075 * Get all Activity Contacts
2077 * The static array activityContacts is returned
2082 * @param string $column db column name/label.
2084 * @return array - array reference of all activity Contacts
2087 public static function &activityContacts($column = 'label') {
2088 if (!self
::$activityContacts) {
2089 self
::$activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, $column);
2091 return self
::$activityContacts;
2095 * Get all Event Contacts
2097 * The static array eventContacts is returned
2102 * @param string $column db column name/label.
2104 * @return array - array reference of all event Contacts
2107 public static function &eventContacts($column = 'label') {
2108 if (!self
::$eventContacts) {
2109 self
::$eventContacts = CRM_Core_OptionGroup
::values('event_contacts', FALSE, FALSE, FALSE, NULL, $column);
2111 return self
::$eventContacts;
2115 * Get all options values
2117 * The static array option values is returned
2122 * @param boolean $optionGroupName - get All Option Group values- default is to get only active ones.
2124 * @return array - array reference of all Option Group Name
2127 public static function accountOptionValues($optionGroupName, $id = null, $condition = null) {
2128 $cacheKey = $optionGroupName . '_' . $condition;
2129 if (empty(self
::$accountOptionValues[$cacheKey])) {
2130 self
::$accountOptionValues[$cacheKey] = CRM_Core_OptionGroup
::values($optionGroupName, false, false, false, $condition);
2133 return CRM_Utils_Array
::value($id, self
::$accountOptionValues[$cacheKey]);
2136 return self
::$accountOptionValues[$cacheKey];
2140 * Get all batch modes
2142 * The static array batchModes
2147 * @return array - array reference of all batch modes
2149 public static function &getBatchMode($columnName = 'label') {
2150 if (!self
::$batchModes) {
2151 self
::$batchModes = CRM_Core_OptionGroup
::values('batch_mode', false, false, false, null, $columnName);
2154 return self
::$batchModes;
2158 * Get all batch types
2160 * The static array batchTypes
2165 * @return array - array reference of all batch types
2167 public static function &getBatchType() {
2168 if (!self
::$batchTypes) {
2169 self
::$batchTypes = CRM_Core_OptionGroup
::values('batch_type');
2172 return self
::$batchTypes;
2176 * Get all batch statuses
2178 * The static array batchStatues
2183 * @return array - array reference of all batch statuses
2185 public static function &getBatchStatus() {
2186 if (!self
::$batchStatues) {
2187 self
::$batchStatues = CRM_Core_OptionGroup
::values('batch_status');
2190 return self
::$batchStatues;
2194 * The static array contactType is returned
2198 * @param string $column db column name/label.
2200 * @return array - array reference of all Types
2204 public static function &contactType($column = 'label') {
2205 if (!self
::$contactType) {
2206 self
::$contactType = CRM_Contact_BAO_ContactType
::basicTypePairs(TRUE);
2208 return self
::$contactType;
2212 * Get all the auto renew options
2217 * @return array self::autoRenew - array reference of all autoRenew
2220 public static function &autoRenew() {
2221 if (!self
::$autoRenew) {
2222 self
::$autoRenew = CRM_Core_OptionGroup
::values('auto_renew_options', FALSE, FALSE);
2224 return self
::$autoRenew;