Load country-specific calendar i18n if available
[civicrm-core.git] / CRM / Core / PseudoConstant.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * Stores all constants and pseudo constants for CRM application.
31 *
32 * examples of constants are "Contact Type" which will always be either
33 * 'Individual', 'Household', 'Organization'.
34 *
35 * pseudo constants are entities from the database whose values rarely
36 * change. examples are list of countries, states, location types,
37 * relationship types.
38 *
39 * currently we're getting the data from the underlying database. this
40 * will be reworked to use caching.
41 *
42 * Note: All pseudoconstants should be uninitialized or default to NULL.
43 * This provides greater consistency/predictability after flushing.
44 *
45 * @package CRM
46 * @copyright CiviCRM LLC (c) 2004-2013
47 * $Id$
48 *
49 */
50 class CRM_Core_PseudoConstant {
51
52 /**
53 * location type
54 * @var array
55 * @static
56 */
57 private static $locationType;
58
59 /**
60 * location vCard name
61 * @var array
62 * @static
63 */
64 private static $locationVcardName;
65
66 /**
67 * location display name
68 * @var array
69 * @static
70 */
71 private static $locationDisplayName;
72
73 /**
74 * activity type
75 * @var array
76 * @static
77 */
78 private static $activityType;
79
80 /**
81 * payment processor billing modes
82 * @var array
83 * @static
84 */
85 private static $billingMode;
86
87 /**
88 * component
89 * @var array
90 * @static
91 */
92 private static $component;
93
94 /**
95 * individual prefix
96 * @var array
97 * @static
98 */
99 private static $individualPrefix;
100
101 /**
102 * individual suffix
103 * @var array
104 * @static
105 */
106 private static $individualSuffix;
107
108 /**
109 * gender
110 * @var array
111 * @static
112 */
113 private static $gender;
114
115 /**
116 * im protocols
117 * @var array
118 * @static
119 */
120 private static $imProvider;
121
122 /**
123 * website protocols
124 * @var array
125 * @static
126 */
127 private static $websiteType;
128
129 /**
130 * im protocols
131 * @var array
132 * @static
133 */
134 private static $fromEmailAddress;
135
136 /**
137 * states, provinces
138 * @var array
139 * @static
140 */
141 private static $stateProvince;
142
143 /**
144 * counties
145 * @var array
146 * @static
147 */
148 private static $county;
149
150 /**
151 * states/provinces abbreviations
152 * @var array
153 * @static
154 */
155 private static $stateProvinceAbbreviation;
156
157 /**
158 * country
159 * @var array
160 * @static
161 */
162 private static $country;
163
164 /**
165 * countryIsoCode
166 * @var array
167 * @static
168 */
169 private static $countryIsoCode;
170
171 /**
172 * tag
173 * @var array
174 * @static
175 */
176 private static $tag;
177
178 /**
179 * group
180 * @var array
181 * @static
182 */
183 private static $group;
184
185 /**
186 * groupIterator
187 * @var mixed
188 * @static
189 */
190 private static $groupIterator;
191
192 /**
193 * relationshipType
194 * @var array
195 * @static
196 */
197 private static $relationshipType;
198
199 /**
200 * civicrm groups that are not smart groups
201 * @var array
202 * @static
203 */
204 private static $staticGroup;
205
206 /**
207 * user framework groups
208 * @var array
209 * @static
210 */
211 private static $ufGroup;
212
213 /**
214 * custom groups
215 * @var array
216 * @static
217 */
218 private static $customGroup;
219
220 /**
221 * currency codes
222 * @var array
223 * @static
224 */
225 private static $currencyCode;
226
227 /**
228 * currency Symbols
229 * @var array
230 * @static
231 */
232 private static $currencySymbols;
233
234 /**
235 * project tasks
236 * @var array
237 * @static
238 */
239 private static $tasks;
240
241 /**
242 * preferred communication methods
243 * @var array
244 * @static
245 */
246 private static $pcm;
247
248 /**
249 * payment processor
250 * @var array
251 * @static
252 */
253 private static $paymentProcessor;
254
255 /**
256 * payment processor types
257 * @var array
258 * @static
259 */
260 private static $paymentProcessorType;
261
262 /**
263 * World Region
264 * @var array
265 * @static
266 */
267 private static $worldRegions;
268
269 /**
270 * honorType
271 * @var array
272 * @static
273 */
274 private static $honorType;
275
276 /**
277 * activity status
278 * @var array
279 * @static
280 */
281 private static $activityStatus;
282
283 /**
284 * priority
285 * @var array
286 * @static
287 */
288 private static $priority;
289
290 /**
291 * wysiwyg Editor
292 * @var array
293 * @static
294 */
295 private static $wysiwygEditor;
296
297 /**
298 * Mapping Types
299 * @var array
300 * @static
301 */
302 private static $mappingType;
303
304 /**
305 * Phone Types
306 * @var array
307 * @static
308 */
309 private static $phoneType;
310
311 /**
312 * Visibility
313 * @var array
314 * @static
315 */
316 private static $visibility;
317
318 /**
319 * Mail Protocols
320 * @var array
321 * @static
322 */
323 private static $mailProtocol;
324
325 /**
326 * Greetings
327 * @var array
328 * @static
329 */
330 private static $greeting;
331
332 /**
333 * Default Greetings
334 * @var array
335 * @static
336 */
337 private static $greetingDefaults;
338
339 /**
340 * Extensions of type module
341 * @var array
342 * @static
343 */
344 private static $extensions;
345
346 /**
347 * activity contacts
348 * @var array
349 * @static
350 */
351 private static $activityContacts;
352
353 /**
354 * event contacts
355 * @var array
356 * @static
357 */
358 private static $eventContacts;
359
360 /**
361 * auto renew options
362 * @var array
363 * @static
364 */
365 private static $autoRenew;
366
367 /**
368 * batch mode options
369 * @var array
370 * @static
371 */
372 private static $batchModes;
373
374 /**
375 * batch type options
376 * @var array
377 * @static
378 */
379 private static $batchTypes;
380
381 /**
382 * batch status options
383 * @var array
384 * @static
385 */
386 private static $batchStatues;
387
388 /**
389 * contact Type
390 * @var array
391 * @static
392 */
393 private static $contactType;
394
395 /**
396 * Financial Account Type
397 * @var array
398 * @static
399 */
400 private static $accountOptionValues;
401
402 /**
403 * populate the object from the database. generic populate
404 * method
405 *
406 * The static array $var is populated from the db
407 * using the <b>$name DAO</b>.
408 *
409 * Note: any database errors will be trapped by the DAO.
410 *
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
417 *
418 * @return void
419 * @access public
420 * @static
421 */
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)) {
427 return $var;
428 }
429
430 $object = new $name ( );
431
432 $object->selectAdd();
433 $object->selectAdd("$key, $retrieve");
434 if ($condition) {
435 $object->whereAdd($condition);
436 }
437
438 if (!$orderby) {
439 $object->orderBy($retrieve);
440 }
441 else {
442 $object->orderBy($orderby);
443 }
444
445 if (!$all) {
446 $object->$filter = 1;
447 }
448
449 $object->find();
450 $var = array();
451 while ($object->fetch()) {
452 $var[$object->$key] = $object->$retrieve;
453 }
454
455 $cache->set($cacheKey, $var);
456 }
457
458 /**
459 * Flush given pseudoconstant so it can be reread from db
460 * nex time it's requested.
461 *
462 * @access public
463 * @static
464 *
465 * @param boolean $name pseudoconstant to be flushed
466 *
467 */
468 public static function flush($name) {
469 self::$$name = NULL;
470 }
471
472 /**
473 * Get all location types.
474 *
475 * The static array locationType is returned
476 *
477 * @access public
478 * @static
479 *
480 * @param boolean $all - get All location types - default is to get only active ones.
481 *
482 * @return array - array reference of all location types.
483 *
484 */
485 public static function &locationType($all = FALSE) {
486 if (!self::$locationType) {
487 self::populate(self::$locationType, 'CRM_Core_DAO_LocationType', $all);
488 }
489 return self::$locationType;
490 }
491
492 /**
493 * Get all location vCard names.
494 *
495 * The static array locationVcardName is returned
496 *
497 * @access public
498 * @static
499 *
500 * @param boolean $all - get All location vCard names - default is to get only active ones.
501 *
502 * @return array - array reference of all location vCard names.
503 *
504 */
505 public static function &locationVcardName($all = FALSE) {
506 if (!self::$locationVcardName) {
507 self::populate(self::$locationVcardName, 'CRM_Core_DAO_LocationType', $all, 'vcard_name');
508 }
509 return self::$locationVcardName;
510 }
511
512 /**
513 * Get all location Display names.
514 *
515 * The static array locationDisplayName is returned
516 *
517 * @access public
518 * @static
519 *
520 * @param boolean $all - get All location display names - default is to get only active ones.
521 *
522 * @return array - array reference of all location display names.
523 *
524 */
525 public static function &locationDisplayName($all = FALSE) {
526 if (!self::$locationDisplayName) {
527 self::populate(self::$locationDisplayName, 'CRM_Core_DAO_LocationType', $all, 'display_name');
528 }
529 return self::$locationDisplayName;
530 }
531
532 /**
533 * Get all Activty types.
534 *
535 * The static array activityType is returned
536 *
537 * @param boolean $all - get All Activity types - default is to get only active ones.
538 *
539 * @access public
540 * @static
541 *
542 * @return array - array reference of all activity types.
543 */
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;
555
556 if (NULL === self::$activityType) {
557 self::$activityType = array();
558 }
559
560 if (!isset(self::$activityType[$index]) || $reset) {
561 $condition = NULL;
562 if (!$all) {
563 $condition = 'AND filter = 0';
564 }
565 $componentClause = " v.component_id IS NULL";
566 if ($onlyComponentActivities) {
567 $componentClause = " v.component_id IS NOT NULL";
568 }
569
570 $componentIds = array();
571 $compInfo = CRM_Core_Component::getEnabledComponents();
572
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;
579 }
580 }
581 elseif ($compName == 'CiviCampaign') {
582 if ($includeCampaignActivities) {
583 $componentIds[] = $compObj->componentID;
584 }
585 }
586 else {
587 $componentIds[] = $compObj->componentID;
588 }
589 }
590
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 ) )";
596 }
597 }
598 $condition = $condition . ' AND ' . $componentClause;
599
600 self::$activityType[$index] = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, $condition, $returnColumn);
601 }
602 return self::$activityType[$index];
603 }
604
605 /**
606 * Get all payment-processor billing modes
607 *
608 * @access public
609 * @static
610 *
611 * @return array ($id => $name)
612 */
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',
619 );
620 }
621 return self::$billingMode;
622 }
623
624 /**
625 * Get all component names
626 *
627 * @access public
628 * @static
629 *
630 * @return array - array reference of all location display names.
631 *
632 */
633 public static function &component() {
634 if (!self::$component) {
635 self::populate(self::$component, 'CRM_Core_DAO_Component', TRUE, 'name');
636 }
637 return self::$component;
638 }
639
640
641 /**
642 * Get all Individual Prefix.
643 *
644 * The static array individualPrefix is returned
645 *
646 * @access public
647 * @static
648 *
649 * @param boolean $all - get All Individual Prefix - default is to get only active ones.
650 *
651 * @return array - array reference of all individual prefix.
652 *
653 */
654 public static function &individualPrefix() {
655 if (!self::$individualPrefix) {
656 self::$individualPrefix = CRM_Core_OptionGroup::values('individual_prefix');
657 }
658 return self::$individualPrefix;
659 }
660
661 /**
662 * Get all phone type
663 * The static array phoneType is returned
664 *
665 * @access public
666 * @static
667 *
668 * @param boolean $all - get All phone type - default is to get
669 * only active ones.
670 *
671 * @return array - array reference of all phone types.
672 *
673 */
674 public static function &phoneType() {
675 if (!self::$phoneType) {
676 self::$phoneType = CRM_Core_OptionGroup::values('phone_type');
677 }
678 return self::$phoneType;
679 }
680
681 /**
682 * Get all Individual Suffix.
683 *
684 * The static array individualSuffix is returned
685 *
686 * @access public
687 * @static
688 *
689 * @param boolean $all - get All Individual Suffix - default is to get only active ones.
690 *
691 * @return array - array reference of all individual suffix.
692 *
693 */
694 public static function &individualSuffix() {
695 if (!self::$individualSuffix) {
696 self::$individualSuffix = CRM_Core_OptionGroup::values('individual_suffix');
697 }
698 return self::$individualSuffix;
699 }
700
701 /**
702 * Get all Gender.
703 *
704 * The static array gender is returned
705 *
706 * @access public
707 * @static
708 *
709 * @param boolean $all - get All Gender - default is to get only active ones.
710 *
711 * @return array - array reference of all gender.
712 *
713 */
714 public static function &gender($localize = FALSE) {
715 if (!self::$gender) {
716 self::$gender = CRM_Core_OptionGroup::values('gender', FALSE, FALSE, $localize);
717 }
718 return self::$gender;
719 }
720
721 /**
722 * Get all the IM Providers from database.
723 *
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.
727 *
728 * Note: any database errors will be trapped by the DAO.
729 *
730 * @access public
731 * @static
732 *
733 * @return array - array reference of all IM providers.
734 *
735 */
736 public static function &IMProvider($localize = FALSE) {
737 if (!self::$imProvider) {
738 self::$imProvider = CRM_Core_OptionGroup::values('instant_messenger_service', FALSE, FALSE, $localize);
739 }
740 return self::$imProvider;
741 }
742
743 /**
744 * Get all the website types from database.
745 *
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.
749 *
750 * Note: any database errors will be trapped by the DAO.
751 *
752 * @access public
753 * @static
754 *
755 * @return array - array reference of all Website types.
756 *
757 */
758 public static function &websiteType() {
759 if (!self::$websiteType) {
760 self::$websiteType = CRM_Core_OptionGroup::values('website_type');
761 }
762 return self::$websiteType;
763 }
764
765 /**
766 * Get the all From Email Address from database.
767 *
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
771 *
772 * Note: any database errors will be trapped by the DAO.
773 *
774 * @access public
775 * @static
776 *
777 * @return array - array reference of all From Email Address.
778 */
779 public static function &fromEmailAddress() {
780 if (!self::$fromEmailAddress) {
781 self::$fromEmailAddress = CRM_Core_OptionGroup::values('from_email_address');
782 }
783 return self::$fromEmailAddress;
784 }
785
786 /**
787 * Get the all Mail Protocols from database.
788 *
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.
792 *
793 * Note: any database errors will be trapped by the DAO.
794 *
795 * @access public
796 * @static
797 *
798 * @return array - array reference of all Mail Protocols.
799 */
800 public static function &mailProtocol() {
801 if (!self::$mailProtocol) {
802 self::$mailProtocol = CRM_Core_OptionGroup::values('mail_protocol');
803 }
804 return self::$mailProtocol;
805 }
806
807 /**
808 * Get all the State/Province from database.
809 *
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.
813 *
814 * Note: any database errors will be trapped by the DAO.
815 *
816 * @access public
817 * @static
818 *
819 * @param int $id - Optional id to return
820 *
821 * @return array - array reference of all State/Provinces.
822 *
823 */
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();
828 if ($limit) {
829 $countryIsoCodes = self::countryIsoCode();
830 $limitCodes = $config->provinceLimit();
831 $limitIds = array();
832 foreach ($limitCodes as $code) {
833 $limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
834 }
835 if (!empty($limitIds)) {
836 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
837 }
838 else {
839 $whereClause = FALSE;
840 }
841 }
842 self::populate(self::$stateProvince, 'CRM_Core_DAO_StateProvince', TRUE, 'name', 'is_active', $whereClause);
843
844 // localise the province names if in an non-en_US locale
845 global $tsLocale;
846 if ($tsLocale != '' and $tsLocale != 'en_US') {
847 $i18n = CRM_Core_I18n::singleton();
848 $i18n->localizeArray(self::$stateProvince, array(
849 'context' => 'province',
850 ));
851 self::$stateProvince = CRM_Utils_Array::asort(self::$stateProvince);
852 }
853 }
854 if ($id) {
855 if (array_key_exists($id, self::$stateProvince)) {
856 return self::$stateProvince[$id];
857 }
858 else {
859 $result = NULL;
860 return $result;
861 }
862 }
863 return self::$stateProvince;
864 }
865
866 /**
867 * Get all the State/Province abbreviations from the database.
868 *
869 * Same as above, except gets the abbreviations instead of the names.
870 *
871 * @access public
872 * @static
873 *
874 * @param int $id - Optional id to return
875 *
876 * @return array - array reference of all State/Province abbreviations.
877 */
878 public static function &stateProvinceAbbreviation($id = FALSE, $limit = TRUE) {
879 if ($id > 1) {
880 $query = "
881 SELECT abbreviation
882 FROM civicrm_state_province
883 WHERE id = %1";
884 $params = array(
885 1 => array(
886 $id,
887 'Integer',
888 ),
889 );
890 return CRM_Core_DAO::singleValueQuery($query, $params);
891 }
892
893 if (!self::$stateProvinceAbbreviation || !$id) {
894
895 $whereClause = FALSE;
896
897 if ($limit) {
898 $config = CRM_Core_Config::singleton();
899 $countryIsoCodes = self::countryIsoCode();
900 $limitCodes = $config->provinceLimit();
901 $limitIds = array();
902 foreach ($limitCodes as $code) {
903 $tmpArray = array_keys($countryIsoCodes, $code);
904
905 if (!empty($tmpArray)) {
906 $limitIds[] = array_shift($tmpArray);
907 }
908 }
909 if (!empty($limitIds)) {
910 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
911 }
912 }
913 self::populate(self::$stateProvinceAbbreviation, 'CRM_Core_DAO_StateProvince', TRUE, 'abbreviation', 'is_active', $whereClause);
914 }
915
916 if ($id) {
917 if (array_key_exists($id, self::$stateProvinceAbbreviation)) {
918 return self::$stateProvinceAbbreviation[$id];
919 }
920 else {
921 $result = NULL;
922 return $result;
923 }
924 }
925 return self::$stateProvinceAbbreviation;
926 }
927
928 /**
929 * Get all the countries from database.
930 *
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.
934 *
935 * Note: any database errors will be trapped by the DAO.
936 *
937 * @access public
938 * @static
939 *
940 * @param int $id - Optional id to return
941 *
942 * @return array - array reference of all countries.
943 *
944 */
945 public static function country($id = FALSE, $applyLimit = TRUE) {
946 if (($id && !CRM_Utils_Array::value($id, self::$country)) || !self::$country || !$id) {
947
948 $config = CRM_Core_Config::singleton();
949 $limitCodes = array();
950
951 if ($applyLimit) {
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)) {
957 $limitCodes = array(
958 $config->countryLimit => 1,
959 );
960 }
961
962 $limitCodes = array_intersect(self::countryIsoCode(), $limitCodes);
963 }
964
965 if (count($limitCodes)) {
966 $whereClause = "iso_code IN ('" . implode("', '", $limitCodes) . "')";
967 }
968 else {
969 $whereClause = NULL;
970 }
971
972 self::populate(self::$country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active', $whereClause);
973
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;
981 }
982 }
983
984 // localise the country names if in an non-en_US locale
985 global $tsLocale;
986 if ($tsLocale != '' and $tsLocale != 'en_US') {
987 $i18n = CRM_Core_I18n::singleton();
988 $i18n->localizeArray(self::$country, array(
989 'context' => 'country',
990 ));
991 self::$country = CRM_Utils_Array::asort(self::$country);
992 }
993 }
994 if ($id) {
995 if (array_key_exists($id, self::$country)) {
996 return self::$country[$id];
997 }
998 else {
999 return NULL;
1000 }
1001 }
1002 return self::$country;
1003 }
1004
1005 /**
1006 * Get all the country ISO Code abbreviations from the database.
1007 *
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.
1011 *
1012 * Note: any database errors will be trapped by the DAO.
1013 *
1014 * @access public
1015 * @static
1016 *
1017 * @return array - array reference of all country ISO codes.
1018 *
1019 */
1020 public static function &countryIsoCode($id = FALSE) {
1021 if (!self::$countryIsoCode) {
1022 self::populate(self::$countryIsoCode, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
1023 }
1024 if ($id) {
1025 if (array_key_exists($id, self::$countryIsoCode)) {
1026 return self::$countryIsoCode[$id];
1027 }
1028 else {
1029 return NULL;
1030 }
1031 }
1032 return self::$countryIsoCode;
1033 }
1034
1035 /**
1036 * Get all the categories from database.
1037 *
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.
1041 *
1042 * Note: any database errors will be trapped by the DAO.
1043 *
1044 * @access public
1045 * @static
1046 *
1047 * @return array - array reference of all categories.
1048 *
1049 */
1050 public static function &tag() {
1051 if (!self::$tag) {
1052 self::populate(self::$tag, 'CRM_Core_DAO_Tag', TRUE);
1053 }
1054 return self::$tag;
1055 }
1056
1057 /**
1058 * Get all groups from database
1059 *
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.
1063 *
1064 * Note: any database errors will be trapped by the DAO.
1065 *
1066 * @param string $groupType type of group(Access/Mailing)
1067 * @param boolen $excludeHidden exclude hidden groups.
1068 *
1069 * @access public
1070 * @static
1071 *
1072 * @return array - array reference of all groups.
1073 *
1074 */
1075 public static function &allGroup($groupType = NULL, $excludeHidden = TRUE) {
1076 $condition = CRM_Contact_BAO_Group::groupTypeCondition($groupType, $excludeHidden);
1077
1078 if (!self::$group) {
1079 self::$group = array();
1080 }
1081
1082 $groupKey = $groupType ? $groupType : 'null';
1083
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);
1087 }
1088 return self::$group[$groupKey];
1089 }
1090
1091 /**
1092 * Create or get groups iterator (iterates over nested groups in a
1093 * logical fashion)
1094 *
1095 * The GroupNesting instance is returned; it's created if this is being
1096 * called for the first time
1097 *
1098 *
1099 * @access public
1100 * @static
1101 *
1102 * @return mixed - instance of CRM_Contact_BAO_GroupNesting
1103 *
1104 */
1105 public static function &groupIterator($styledLabels = FALSE) {
1106 if (!self::$groupIterator) {
1107 /*
1108 When used as an object, GroupNesting implements Iterator
1109 and iterates nested groups in a logical manner for us
1110 */
1111
1112 self::$groupIterator = new CRM_Contact_BAO_GroupNesting($styledLabels);
1113 }
1114 return self::$groupIterator;
1115 }
1116
1117 /**
1118 * Get all permissioned groups from database
1119 *
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.
1123 *
1124 * Note: any database errors will be trapped by the DAO.
1125 *
1126 * @param string $groupType type of group(Access/Mailing)
1127 * @param boolen $excludeHidden exclude hidden groups.
1128
1129 * @access public
1130 * @static
1131 *
1132 * @return array - array reference of all groups.
1133 *
1134 */
1135 public static function group($groupType = NULL, $excludeHidden = TRUE) {
1136 return CRM_Core_Permission::group($groupType, $excludeHidden);
1137 }
1138
1139 /**
1140 * Get all permissioned groups from database
1141 *
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.
1145 *
1146 * Note: any database errors will be trapped by the DAO.
1147 *
1148 * @access public
1149 * @static
1150 *
1151 * @return array - array reference of all groups.
1152 *
1153 */
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';
1157 if ($onlyPublic) {
1158 $condition .= " AND visibility != 'User and User Admin Only'";
1159 }
1160
1161 if ($groupType) {
1162 $condition .= ' AND ' . CRM_Contact_BAO_Group::groupTypeCondition($groupType);
1163 }
1164
1165 if ($excludeHidden) {
1166 $condition .= ' AND is_hidden != 1 ';
1167 }
1168
1169 self::populate(self::$staticGroup, 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition, 'title');
1170 }
1171
1172 return self::$staticGroup;
1173 }
1174
1175 /**
1176 * Get all the custom groups
1177 *
1178 * @access public
1179 *
1180 * @return array - array reference of all groups.
1181 * @static
1182 */
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');
1186 }
1187 return self::$customGroup;
1188 }
1189
1190 /**
1191 * Get all the user framework groups
1192 *
1193 * @access public
1194 *
1195 * @return array - array reference of all groups.
1196 * @static
1197 */
1198 public static function &ufGroup() {
1199 if (!self::$ufGroup) {
1200 self::populate(self::$ufGroup, 'CRM_Core_DAO_UFGroup', FALSE, 'title', 'is_active', NULL, 'title');
1201 }
1202 return self::$ufGroup;
1203 }
1204
1205 /**
1206 * Get all the project tasks
1207 *
1208 * @access public
1209 *
1210 * @return array - array reference of all tasks
1211 * @static
1212 */
1213 public static function &tasks() {
1214 if (!self::$tasks) {
1215 self::populate(self::$tasks, 'CRM_Project_DAO_Task', FALSE, 'title', 'is_active', NULL, 'title');
1216 }
1217 return self::$tasks;
1218 }
1219
1220 /**
1221 * Get all Relationship Types from database.
1222 *
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.
1226 *
1227 * Note: any database errors will be trapped by the DAO.
1228 *
1229 * @param string $valueColumnName db column name/label.
1230 * @param boolean $reset reset relationship types if true
1231 *
1232 * @access public
1233 * @static
1234 *
1235 * @return array - array reference of all relationship types.
1236 */
1237 public static function &relationshipType($valueColumnName = 'label', $reset = FALSE) {
1238 if (!CRM_Utils_Array::value($valueColumnName, self::$relationshipType) || $reset) {
1239 self::$relationshipType[$valueColumnName] = array();
1240
1241 //now we have name/label columns CRM-3336
1242 $column_a_b = "{$valueColumnName}_a_b";
1243 $column_b_a = "{$valueColumnName}_b_a";
1244
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()) {
1251
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",
1259 );
1260 }
1261 }
1262
1263 return self::$relationshipType[$valueColumnName];
1264 }
1265
1266 /**
1267 * Get all the Currency Symbols from Database
1268 *
1269 * @access public
1270 *
1271 * @return array - array reference of all Currency Symbols
1272 * @static
1273 */
1274 public static function &currencySymbols($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);
1278 }
1279
1280 return self::$currencySymbols[$cacheKey];
1281 }
1282
1283 /**
1284 * get all the ISO 4217 currency codes
1285 *
1286 * so far, we use this for validation only, so there's no point of putting this into the database
1287 *
1288 * @access public
1289 *
1290 * @return array - array reference of all currency codes
1291 * @static
1292 */
1293 public static function &currencyCode() {
1294 if (!self::$currencyCode) {
1295 self::$currencyCode = array(
1296 'AFN',
1297 'ALL',
1298 'DZD',
1299 'USD',
1300 'EUR',
1301 'AOA',
1302 'XCD',
1303 'XCD',
1304 'ARS',
1305 'AMD',
1306 'AWG',
1307 'AUD',
1308 'EUR',
1309 'AZM',
1310 'BSD',
1311 'BHD',
1312 'BDT',
1313 'BBD',
1314 'BYR',
1315 'EUR',
1316 'BZD',
1317 'XOF',
1318 'BMD',
1319 'INR',
1320 'BTN',
1321 'BOB',
1322 'BOV',
1323 'BAM',
1324 'BWP',
1325 'NOK',
1326 'BRL',
1327 'USD',
1328 'BND',
1329 'BGN',
1330 'XOF',
1331 'BIF',
1332 'KHR',
1333 'XAF',
1334 'CAD',
1335 'CVE',
1336 'KYD',
1337 'XAF',
1338 'XAF',
1339 'CLP',
1340 'CLF',
1341 'CNY',
1342 'AUD',
1343 'AUD',
1344 'COP',
1345 'COU',
1346 'KMF',
1347 'XAF',
1348 'CDF',
1349 'NZD',
1350 'CRC',
1351 'XOF',
1352 'HRK',
1353 'CUP',
1354 'CYP',
1355 'CZK',
1356 'DKK',
1357 'DJF',
1358 'XCD',
1359 'DOP',
1360 'USD',
1361 'EGP',
1362 'SVC',
1363 'USD',
1364 'XAF',
1365 'ERN',
1366 'EEK',
1367 'ETB',
1368 'FKP',
1369 'DKK',
1370 'FJD',
1371 'EUR',
1372 'EUR',
1373 'EUR',
1374 'XPF',
1375 'EUR',
1376 'XAF',
1377 'GMD',
1378 'GEL',
1379 'EUR',
1380 'GHC',
1381 'GIP',
1382 'EUR',
1383 'DKK',
1384 'XCD',
1385 'EUR',
1386 'USD',
1387 'GTQ',
1388 'GNF',
1389 'GWP',
1390 'XOF',
1391 'GYD',
1392 'HTG',
1393 'USD',
1394 'AUD',
1395 'EUR',
1396 'HNL',
1397 'HKD',
1398 'HUF',
1399 'ISK',
1400 'INR',
1401 'IDR',
1402 'XDR',
1403 'IRR',
1404 'IQD',
1405 'EUR',
1406 'ILS',
1407 'EUR',
1408 'JMD',
1409 'JPY',
1410 'JOD',
1411 'KZT',
1412 'KES',
1413 'AUD',
1414 'KPW',
1415 'KRW',
1416 'KWD',
1417 'KGS',
1418 'LAK',
1419 'LVL',
1420 'LBP',
1421 'ZAR',
1422 'LSL',
1423 'LRD',
1424 'LYD',
1425 'CHF',
1426 'LTL',
1427 'EUR',
1428 'MOP',
1429 'MKD',
1430 'MGA',
1431 'MWK',
1432 'MYR',
1433 'MVR',
1434 'XOF',
1435 'MTL',
1436 'USD',
1437 'EUR',
1438 'MRO',
1439 'MUR',
1440 'EUR',
1441 'MXN',
1442 'MXV',
1443 'USD',
1444 'MDL',
1445 'EUR',
1446 'MNT',
1447 'XCD',
1448 'MAD',
1449 'MZM',
1450 'MMK',
1451 'ZAR',
1452 'NAD',
1453 'AUD',
1454 'NPR',
1455 'EUR',
1456 'ANG',
1457 'XPF',
1458 'NZD',
1459 'NIO',
1460 'XOF',
1461 'NGN',
1462 'NZD',
1463 'AUD',
1464 'USD',
1465 'NOK',
1466 'OMR',
1467 'PKR',
1468 'USD',
1469 'PAB',
1470 'USD',
1471 'PGK',
1472 'PYG',
1473 'PEN',
1474 'PHP',
1475 'NZD',
1476 'PLN',
1477 'EUR',
1478 'USD',
1479 'QAR',
1480 'EUR',
1481 'ROL',
1482 'RON',
1483 'RUB',
1484 'RWF',
1485 'SHP',
1486 'XCD',
1487 'XCD',
1488 'EUR',
1489 'XCD',
1490 'WST',
1491 'EUR',
1492 'STD',
1493 'SAR',
1494 'XOF',
1495 'CSD',
1496 'EUR',
1497 'SCR',
1498 'SLL',
1499 'SGD',
1500 'SKK',
1501 'SIT',
1502 'SBD',
1503 'SOS',
1504 'ZAR',
1505 'EUR',
1506 'LKR',
1507 'SDD',
1508 'SRD',
1509 'NOK',
1510 'SZL',
1511 'SEK',
1512 'CHF',
1513 'CHW',
1514 'CHE',
1515 'SYP',
1516 'TWD',
1517 'TJS',
1518 'TZS',
1519 'THB',
1520 'USD',
1521 'XOF',
1522 'NZD',
1523 'TOP',
1524 'TTD',
1525 'TND',
1526 'TRY',
1527 'TRL',
1528 'TMM',
1529 'USD',
1530 'AUD',
1531 'UGX',
1532 'UAH',
1533 'AED',
1534 'GBP',
1535 'USD',
1536 'USS',
1537 'USN',
1538 'USD',
1539 'UYU',
1540 'UZS',
1541 'VUV',
1542 'VEB',
1543 'VND',
1544 'USD',
1545 'USD',
1546 'XPF',
1547 'MAD',
1548 'YER',
1549 'ZMK',
1550 'ZWD',
1551 'XAU',
1552 'XBA',
1553 'XBB',
1554 'XBC',
1555 'XBD',
1556 'XPD',
1557 'XPT',
1558 'XAG',
1559 'XFU',
1560 'XFO',
1561 'XTS',
1562 'XXX',
1563 );
1564 }
1565 return self::$currencyCode;
1566 }
1567
1568 /**
1569 * Get all the County from database.
1570 *
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.
1574 *
1575 * Note: any database errors will be trapped by the DAO.
1576 *
1577 * @access public
1578 * @static
1579 *
1580 * @param int $id - Optional id to return
1581 *
1582 * @return array - array reference of all Counties
1583 *
1584 */
1585 public static function &county($id = FALSE) {
1586 if (!self::$county) {
1587
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');
1591 }
1592 if ($id) {
1593 if (array_key_exists($id, self::$county)) {
1594 return self::$county[$id];
1595 }
1596 else {
1597 return NULL;
1598 }
1599 }
1600 return self::$county;
1601 }
1602
1603 /**
1604 * Get all the Preferred Communication Methods from database.
1605 *
1606 * @access public
1607 * @static
1608 *
1609 * @return array self::pcm - array reference of all preferred communication methods.
1610 *
1611 */
1612 public static function &pcm($localize = FALSE) {
1613 if (!self::$pcm) {
1614 self::$pcm = CRM_Core_OptionGroup::values('preferred_communication_method', FALSE, FALSE, $localize);
1615 }
1616 return self::$pcm;
1617 }
1618
1619 /**
1620 * Alias of pcm
1621 */
1622 public static function preferredCommunicationMethod($localize = FALSE) {
1623 return self::pcm($localize);
1624 }
1625
1626 /**
1627 * Get all active payment processors
1628 *
1629 * The static array paymentProcessor is returned
1630 *
1631 * @access public
1632 * @static
1633 *
1634 * @param boolean $all - get payment processors - default is to get only active ones.
1635 * @param boolean $test - get test payment processors
1636 *
1637 * @return array - array of all payment processors
1638 *
1639 */
1640 public static function &paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
1641 $condition = "is_test = ";
1642 $condition .= ($test) ? '1' : '0';
1643
1644 if ($additionalCond) {
1645 $condition .= " AND ( $additionalCond ) ";
1646 }
1647
1648 // CRM-7178. Make sure we only include payment processors valid in ths
1649 // domain
1650 $condition .= " AND domain_id = " . CRM_Core_Config::domainID();
1651
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');
1655 }
1656
1657 return self::$paymentProcessor[$cacheKey];
1658 }
1659
1660 /**
1661 * Get all active payment processors
1662 *
1663 * The static array paymentProcessorType is returned
1664 *
1665 * @access public
1666 * @static
1667 *
1668 * @param boolean $all - get payment processors - default is to get only active ones.
1669 *
1670 * @return array - array of all payment processor types
1671 *
1672 */
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');
1677 }
1678 if ($id && CRM_Utils_Array::value($id, self::$paymentProcessorType[$cacheKey])) {
1679 return self::$paymentProcessorType[$cacheKey][$id];
1680 }
1681 return self::$paymentProcessorType[$cacheKey];
1682 }
1683
1684 /**
1685 * Get all the World Regions from Database
1686 *
1687 * @access public
1688 *
1689 * @return array - array reference of all World Regions
1690 * @static
1691 */
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');
1695 }
1696
1697 if ($id) {
1698 if (array_key_exists($id, self::$worldRegions)) {
1699 return self::$worldRegions[$id];
1700 }
1701 else {
1702 return NULL;
1703 }
1704 }
1705
1706 return self::$worldRegions;
1707 }
1708
1709 /**
1710 * Get all Honor Type.
1711 *
1712 * The static array honorType is returned
1713 *
1714 * @access public
1715 * @static
1716 *
1717 * @param boolean $all - get All Honor Type.
1718 *
1719 * @return array - array reference of all Honor Types.
1720 *
1721 */
1722 public static function &honor() {
1723 if (!self::$honorType) {
1724 self::$honorType = CRM_Core_OptionGroup::values('honor_type');
1725 }
1726 return self::$honorType;
1727 }
1728
1729 /**
1730 * Get all Activity Statuses.
1731 *
1732 * The static array activityStatus is returned
1733 *
1734 * @access public
1735 * @static
1736 *
1737 * @return array - array reference of all activity statuses
1738 */
1739 public static function &activityStatus($column = 'label') {
1740 if (NULL === self::$activityStatus) {
1741 self::$activityStatus = array();
1742 }
1743 if (!array_key_exists($column, self::$activityStatus)) {
1744 self::$activityStatus[$column] = array();
1745
1746 self::$activityStatus[$column] = CRM_Core_OptionGroup::values('activity_status', FALSE, FALSE, FALSE, NULL, $column);
1747 }
1748
1749 return self::$activityStatus[$column];
1750 }
1751
1752 /**
1753 * Get all Priorities
1754 *
1755 * The static array Priority is returned
1756 *
1757 * @access public
1758 * @static
1759 *
1760 * @return array - array reference of all Priority
1761 */
1762 public static function &priority() {
1763 if (!self::$priority) {
1764 self::$priority = CRM_Core_OptionGroup::values('priority');
1765 }
1766
1767 return self::$priority;
1768 }
1769
1770 /**
1771 * Get all WYSIWYG Editors.
1772 *
1773 * The static array wysiwygEditor is returned
1774 *
1775 * @access public
1776 * @static
1777 *
1778 * @return array - array reference of all wysiwygEditors
1779 */
1780 public static function &wysiwygEditor() {
1781 if (!self::$wysiwygEditor) {
1782 self::$wysiwygEditor = CRM_Core_OptionGroup::values('wysiwyg_editor');
1783 }
1784 return self::$wysiwygEditor;
1785 }
1786
1787 /**
1788 * Get all Visibility levels.
1789 *
1790 * The static array visibility is returned
1791 *
1792 * @access public
1793 * @static
1794 *
1795 * @return array - array reference of all Visibility levels.
1796 *
1797 */
1798 public static function &visibility($column = 'label') {
1799 if (!isset(self::$visibility)) {
1800 self::$visibility = array( );
1801 }
1802
1803 if (!isset(self::$visibility[$column])) {
1804 self::$visibility[$column] = CRM_Core_OptionGroup::values('visibility', FALSE, FALSE, FALSE, NULL, $column);
1805 }
1806
1807 return self::$visibility[$column];
1808 }
1809
1810 /**
1811 * Get all mapping types
1812 *
1813 * @return array - array reference of all mapping types
1814 * @access public
1815 * @static
1816 */
1817 public static function &mappingTypes() {
1818 if (!self::$mappingType) {
1819 self::$mappingType = CRM_Core_OptionGroup::values('mapping_type');
1820 }
1821 return self::$mappingType;
1822 }
1823
1824 public static function &stateProvinceForCountry($countryID, $field = 'name') {
1825 static $_cache = NULL;
1826
1827 $cacheKey = "{$countryID}_{$field}";
1828 if (!$_cache) {
1829 $_cache = array();
1830 }
1831
1832 if (!empty($_cache[$cacheKey])) {
1833 return $_cache[$cacheKey];
1834 }
1835
1836 $query = "
1837 SELECT civicrm_state_province.{$field} name, civicrm_state_province.id id
1838 FROM civicrm_state_province
1839 WHERE country_id = %1
1840 ORDER BY name";
1841 $params = array(
1842 1 => array(
1843 $countryID,
1844 'Integer',
1845 ),
1846 );
1847
1848 $dao = CRM_Core_DAO::executeQuery($query, $params);
1849
1850 $result = array();
1851 while ($dao->fetch()) {
1852 $result[$dao->id] = $dao->name;
1853 }
1854
1855 // localise the stateProvince names if in an non-en_US locale
1856 $config = CRM_Core_Config::singleton();
1857 global $tsLocale;
1858 if ($tsLocale != '' and $tsLocale != 'en_US') {
1859 $i18n = CRM_Core_I18n::singleton();
1860 $i18n->localizeArray($result, array(
1861 'context' => 'province',
1862 ));
1863 $result = CRM_Utils_Array::asort($result);
1864 }
1865
1866 $_cache[$cacheKey] = $result;
1867
1868 CRM_Utils_Hook::buildStateProvinceForCountry($countryID, $result);
1869
1870 return $result;
1871 }
1872
1873 public static function &countyForState($stateID) {
1874 if (is_array($stateID)) {
1875 $states = implode(", ", $stateID);
1876 $query = "
1877 SELECT civicrm_county.name name, civicrm_county.id id, civicrm_state_province.abbreviation abbreviation
1878 FROM civicrm_county
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";
1882
1883 $dao = CRM_Core_DAO::executeQuery($query);
1884
1885 $result = array();
1886 while ($dao->fetch()) {
1887 $result[$dao->id] = $dao->abbreviation . ': ' . $dao->name;
1888 }
1889 }
1890 else {
1891
1892 static $_cache = NULL;
1893
1894 $cacheKey = "{$stateID}_name";
1895 if (!$_cache) {
1896 $_cache = array();
1897 }
1898
1899 if (!empty($_cache[$cacheKey])) {
1900 return $_cache[$cacheKey];
1901 }
1902
1903 $query = "
1904 SELECT civicrm_county.name name, civicrm_county.id id
1905 FROM civicrm_county
1906 WHERE state_province_id = %1
1907 ORDER BY name";
1908 $params = array(
1909 1 => array(
1910 $stateID,
1911 'Integer',
1912 ),
1913 );
1914
1915 $dao = CRM_Core_DAO::executeQuery($query, $params);
1916
1917 $result = array();
1918 while ($dao->fetch()) {
1919 $result[$dao->id] = $dao->name;
1920 }
1921 }
1922
1923 return $result;
1924 }
1925
1926 /**
1927 * Get all types of Greetings.
1928 *
1929 * The static array of greeting is returned
1930 *
1931 * @access public
1932 * @static
1933 *
1934 * @param $filter - get All Email Greetings - default is to get only active ones.
1935 *
1936 * @return array - array reference of all greetings.
1937 *
1938 */
1939 public static function greeting($filter, $columnName = 'label') {
1940 $index = $filter['greeting_type'] . '_' . $columnName;
1941
1942 // also add contactType to the array
1943 $contactType = CRM_Utils_Array::value('contact_type', $filter);
1944 if ($contactType) {
1945 $index .= '_' . $contactType;
1946 }
1947
1948 if (NULL === self::$greeting) {
1949 self::$greeting = array();
1950 }
1951
1952 if (!CRM_Utils_Array::value($index, self::$greeting)) {
1953 $filterCondition = NULL;
1954 if ($contactType) {
1955 $filterVal = 'v.filter =';
1956 switch ($contactType) {
1957 case 'Individual':
1958 $filterVal .= "1";
1959 break;
1960
1961 case 'Household':
1962 $filterVal .= "2";
1963 break;
1964
1965 case 'Organization':
1966 $filterVal .= "3";
1967 break;
1968 }
1969 $filterCondition .= "AND (v.filter = 0 OR {$filterVal}) ";
1970 }
1971
1972 self::$greeting[$index] = CRM_Core_OptionGroup::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName);
1973 }
1974
1975 return self::$greeting[$index];
1976 }
1977
1978 /**
1979 * Construct array of default greeting values for contact type
1980 *
1981 * @access public
1982 * @static
1983 *
1984 * @return array - array reference of default greetings.
1985 *
1986 */
1987 public static function &greetingDefaults() {
1988 if (!self::$greetingDefaults) {
1989 $defaultGreetings = array();
1990 $contactTypes = array(
1991 'Individual' => 1,
1992 'Household' => 2,
1993 'Organization' => 3,
1994 );
1995
1996 foreach ($contactTypes as $contactType => $filter) {
1997 $filterCondition = " AND (v.filter = 0 OR v.filter = $filter) AND v.is_default = 1 ";
1998
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;
2002 }
2003 }
2004
2005 self::$greetingDefaults = $defaultGreetings;
2006 }
2007
2008 return self::$greetingDefaults;
2009 }
2010
2011 /**
2012 * Get all the Languages from database.
2013 *
2014 * @access public
2015 * @static
2016 *
2017 * @return array self::languages - array reference of all languages
2018 *
2019 */
2020 public static function &languages() {
2021 return CRM_Core_I18n_PseudoConstant::languages();
2022 }
2023
2024 /**
2025 * Alias of above
2026 */
2027 public static function &preferredLanguage() {
2028 return CRM_Core_I18n_PseudoConstant::languages();
2029 }
2030
2031 /**
2032 * Get all extensions
2033 *
2034 * The static array extensions
2035 *
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.
2038 *
2039 * @access public
2040 * @static
2041 *
2042 * @return array - array($fullyQualifiedName => $label) list of extensions
2043 */
2044 public static function &getExtensions() {
2045 if (!self::$extensions) {
2046 self::$extensions = array();
2047 $sql = '
2048 SELECT full_name, label
2049 FROM civicrm_extension
2050 WHERE is_active = 1
2051 ';
2052 $dao = CRM_Core_DAO::executeQuery($sql);
2053 while ($dao->fetch()) {
2054 self::$extensions[$dao->full_name] = $dao->label;
2055 }
2056 }
2057
2058 return self::$extensions;
2059 }
2060
2061 /**
2062 * Fetch the list of active extensions of type 'module'
2063 *
2064 * @param $fresh bool whether to forcibly reload extensions list from canonical store
2065 * @access public
2066 * @static
2067 *
2068 * @return array - array(array('prefix' => $, 'file' => $))
2069 */
2070 public static function getModuleExtensions($fresh = FALSE) {
2071 return CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles($fresh);
2072 }
2073
2074 /**
2075 * Get all Activity Contacts
2076 *
2077 * The static array activityContacts is returned
2078 *
2079 * @access public
2080 * @static
2081 *
2082 * @param string $column db column name/label.
2083 *
2084 * @return array - array reference of all activity Contacts
2085 *
2086 */
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);
2090 }
2091 return self::$activityContacts;
2092 }
2093
2094 /**
2095 * Get all Event Contacts
2096 *
2097 * The static array eventContacts is returned
2098 *
2099 * @access public
2100 * @static
2101 *
2102 * @param string $column db column name/label.
2103 *
2104 * @return array - array reference of all event Contacts
2105 *
2106 */
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);
2110 }
2111 return self::$eventContacts;
2112 }
2113
2114 /**
2115 * Get all options values
2116 *
2117 * The static array option values is returned
2118 *
2119 * @access public
2120 * @static
2121 *
2122 * @param boolean $optionGroupName - get All Option Group values- default is to get only active ones.
2123 *
2124 * @return array - array reference of all Option Group Name
2125 *
2126 */
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);
2131 }
2132 if ($id) {
2133 return CRM_Utils_Array::value($id, self::$accountOptionValues[$cacheKey]);
2134 }
2135
2136 return self::$accountOptionValues[$cacheKey];
2137 }
2138
2139 /**
2140 * Get all batch modes
2141 *
2142 * The static array batchModes
2143 *
2144 * @access public
2145 * @static
2146 *
2147 * @return array - array reference of all batch modes
2148 */
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);
2152 }
2153
2154 return self::$batchModes;
2155 }
2156
2157 /**
2158 * Get all batch types
2159 *
2160 * The static array batchTypes
2161 *
2162 * @access public
2163 * @static
2164 *
2165 * @return array - array reference of all batch types
2166 */
2167 public static function &getBatchType() {
2168 if (!self::$batchTypes) {
2169 self::$batchTypes = CRM_Core_OptionGroup::values('batch_type');
2170 }
2171
2172 return self::$batchTypes;
2173 }
2174
2175 /**
2176 * Get all batch statuses
2177 *
2178 * The static array batchStatues
2179 *
2180 * @access public
2181 * @static
2182 *
2183 * @return array - array reference of all batch statuses
2184 */
2185 public static function &getBatchStatus() {
2186 if (!self::$batchStatues) {
2187 self::$batchStatues = CRM_Core_OptionGroup::values('batch_status');
2188 }
2189
2190 return self::$batchStatues;
2191 }
2192
2193 /*
2194 * The static array contactType is returned
2195 *
2196 * @access public
2197 * @static
2198 * @param string $column db column name/label.
2199 *
2200 * @return array - array reference of all Types
2201 *
2202 */
2203
2204 public static function &contactType($column = 'label') {
2205 if (!self::$contactType) {
2206 self::$contactType = CRM_Contact_BAO_ContactType::basicTypePairs(TRUE);
2207 }
2208 return self::$contactType;
2209 }
2210
2211 /**
2212 * Get all the auto renew options
2213 *
2214 * @access public
2215 * @static
2216 *
2217 * @return array self::autoRenew - array reference of all autoRenew
2218 *
2219 */
2220 public static function &autoRenew() {
2221 if (!self::$autoRenew) {
2222 self::$autoRenew = CRM_Core_OptionGroup::values('auto_renew_options', FALSE, FALSE);
2223 }
2224 return self::$autoRenew;
2225 }
2226 }
2227