fix formatting
[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(
423 &$var,
424 $name,
425 $all = FALSE,
426 $retrieve = 'name',
427 $filter = 'is_active',
428 $condition = NULL,
429 $orderby = NULL,
430 $key = 'id',
431 $force = NULL
432 ) {
433 $cacheKey = "CRM_PC_{$name}_{$all}_{$key}_{$retrieve}_{$filter}_{$condition}_{$orderby}";
434 $cache = CRM_Utils_Cache::singleton();
435 $var = $cache->get($cacheKey);
436 if ($var && empty($force)) {
437 return $var;
438 }
439
440 $object = new $name ( );
441
442 $object->selectAdd();
443 $object->selectAdd("$key, $retrieve");
444 if ($condition) {
445 $object->whereAdd($condition);
446 }
447
448 if (!$orderby) {
449 $object->orderBy($retrieve);
450 }
451 else {
452 $object->orderBy($orderby);
453 }
454
455 if (!$all) {
456 $object->$filter = 1;
457 }
458
459 $object->find();
460 $var = array();
461 while ($object->fetch()) {
462 $var[$object->$key] = $object->$retrieve;
463 }
464
465 $cache->set($cacheKey, $var);
466 }
467
468 /**
469 * Flush given pseudoconstant so it can be reread from db
470 * nex time it's requested.
471 *
472 * @access public
473 * @static
474 *
475 * @param boolean $name pseudoconstant to be flushed
476 *
477 */
478 public static function flush($name) {
479 self::$$name = NULL;
480 }
481
482 /**
483 * Get all location types.
484 *
485 * The static array locationType is returned
486 *
487 * @access public
488 * @static
489 *
490 * @param boolean $all - get All location types - default is to get only active ones.
491 *
492 * @return array - array reference of all location types.
493 *
494 */
495 public static function &locationType($all = FALSE) {
496 if (!self::$locationType) {
497 self::populate(self::$locationType, 'CRM_Core_DAO_LocationType', $all);
498 }
499 return self::$locationType;
500 }
501
502 /**
503 * Get all location vCard names.
504 *
505 * The static array locationVcardName is returned
506 *
507 * @access public
508 * @static
509 *
510 * @param boolean $all - get All location vCard names - default is to get only active ones.
511 *
512 * @return array - array reference of all location vCard names.
513 *
514 */
515 public static function &locationVcardName($all = FALSE) {
516 if (!self::$locationVcardName) {
517 self::populate(self::$locationVcardName, 'CRM_Core_DAO_LocationType', $all, 'vcard_name');
518 }
519 return self::$locationVcardName;
520 }
521
522 /**
523 * Get all location Display names.
524 *
525 * The static array locationDisplayName is returned
526 *
527 * @access public
528 * @static
529 *
530 * @param boolean $all - get All location display names - default is to get only active ones.
531 *
532 * @return array - array reference of all location display names.
533 *
534 */
535 public static function &locationDisplayName($all = FALSE) {
536 if (!self::$locationDisplayName) {
537 self::populate(self::$locationDisplayName, 'CRM_Core_DAO_LocationType', $all, 'display_name');
538 }
539 return self::$locationDisplayName;
540 }
541
542 /**
543 * Get all Activty types.
544 *
545 * The static array activityType is returned
546 *
547 * @param boolean $all - get All Activity types - default is to get only active ones.
548 *
549 * @access public
550 * @static
551 *
552 * @return array - array reference of all activity types.
553 */
554 public static function &activityType() {
555 $args = func_get_args();
556 $all = CRM_Utils_Array::value(0, $args, TRUE);
557 $includeCaseActivities = CRM_Utils_Array::value(1, $args, FALSE);
558 $reset = CRM_Utils_Array::value(2, $args, FALSE);
559 $returnColumn = CRM_Utils_Array::value(3, $args, 'label');
560 $includeCampaignActivities = CRM_Utils_Array::value(4, $args, FALSE);
561 $onlyComponentActivities = CRM_Utils_Array::value(5, $args, FALSE);
562 $index = (int) $all . '_' . $returnColumn . '_' . (int) $includeCaseActivities;
563 $index .= '_' . (int) $includeCampaignActivities;
564 $index .= '_' . (int) $onlyComponentActivities;
565
566 if (NULL === self::$activityType) {
567 self::$activityType = array();
568 }
569
570 if (!isset(self::$activityType[$index]) || $reset) {
571 $condition = NULL;
572 if (!$all) {
573 $condition = 'AND filter = 0';
574 }
575 $componentClause = " v.component_id IS NULL";
576 if ($onlyComponentActivities) {
577 $componentClause = " v.component_id IS NOT NULL";
578 }
579
580 $componentIds = array();
581 $compInfo = CRM_Core_Component::getEnabledComponents();
582
583 // build filter for listing activity types only if their
584 // respective components are enabled
585 foreach ($compInfo as $compName => $compObj) {
586 if ($compName == 'CiviCase') {
587 if ($includeCaseActivities) {
588 $componentIds[] = $compObj->componentID;
589 }
590 }
591 elseif ($compName == 'CiviCampaign') {
592 if ($includeCampaignActivities) {
593 $componentIds[] = $compObj->componentID;
594 }
595 }
596 else {
597 $componentIds[] = $compObj->componentID;
598 }
599 }
600
601 if (count($componentIds)) {
602 $componentIds = implode(',', $componentIds);
603 $componentClause = " ($componentClause OR v.component_id IN ($componentIds))";
604 if ($onlyComponentActivities) {
605 $componentClause = " ( v.component_id IN ($componentIds ) )";
606 }
607 }
608 $condition = $condition . ' AND ' . $componentClause;
609
610 self::$activityType[$index] = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, $condition, $returnColumn);
611 }
612 return self::$activityType[$index];
613 }
614
615 /**
616 * Get all payment-processor billing modes
617 *
618 * @access public
619 * @static
620 *
621 * @return array ($id => $name)
622 */
623 public static function billingMode() {
624 if (!self::$billingMode) {
625 self::$billingMode = array(
626 CRM_Core_Payment::BILLING_MODE_FORM => 'form',
627 CRM_Core_Payment::BILLING_MODE_BUTTON => 'button',
628 CRM_Core_Payment::BILLING_MODE_NOTIFY => 'notify',
629 );
630 }
631 return self::$billingMode;
632 }
633
634 /**
635 * Get all component names
636 *
637 * @access public
638 * @static
639 *
640 * @return array - array reference of all location display names.
641 *
642 */
643 public static function &component() {
644 if (!self::$component) {
645 self::populate(self::$component, 'CRM_Core_DAO_Component', TRUE, 'name');
646 }
647 return self::$component;
648 }
649
650
651 /**
652 * Get all Individual Prefix.
653 *
654 * The static array individualPrefix is returned
655 *
656 * @access public
657 * @static
658 *
659 * @param boolean $all - get All Individual Prefix - default is to get only active ones.
660 *
661 * @return array - array reference of all individual prefix.
662 *
663 */
664 public static function &individualPrefix() {
665 if (!self::$individualPrefix) {
666 self::$individualPrefix = CRM_Core_OptionGroup::values('individual_prefix');
667 }
668 return self::$individualPrefix;
669 }
670
671 /**
672 * Get all phone type
673 * The static array phoneType is returned
674 *
675 * @access public
676 * @static
677 *
678 * @param boolean $all - get All phone type - default is to get
679 * only active ones.
680 *
681 * @return array - array reference of all phone types.
682 *
683 */
684 public static function &phoneType() {
685 if (!self::$phoneType) {
686 self::$phoneType = CRM_Core_OptionGroup::values('phone_type');
687 }
688 return self::$phoneType;
689 }
690
691 /**
692 * Get all Individual Suffix.
693 *
694 * The static array individualSuffix is returned
695 *
696 * @access public
697 * @static
698 *
699 * @param boolean $all - get All Individual Suffix - default is to get only active ones.
700 *
701 * @return array - array reference of all individual suffix.
702 *
703 */
704 public static function &individualSuffix() {
705 if (!self::$individualSuffix) {
706 self::$individualSuffix = CRM_Core_OptionGroup::values('individual_suffix');
707 }
708 return self::$individualSuffix;
709 }
710
711 /**
712 * Get all Gender.
713 *
714 * The static array gender is returned
715 *
716 * @access public
717 * @static
718 *
719 * @param boolean $all - get All Gender - default is to get only active ones.
720 *
721 * @return array - array reference of all gender.
722 *
723 */
724 public static function &gender($localize = FALSE) {
725 if (!self::$gender) {
726 self::$gender = CRM_Core_OptionGroup::values('gender', FALSE, FALSE, $localize);
727 }
728 return self::$gender;
729 }
730
731 /**
732 * Get all the IM Providers from database.
733 *
734 * The static array imProvider is returned, and if it's
735 * called the first time, the <b>IM DAO</b> is used
736 * to get all the IM Providers.
737 *
738 * Note: any database errors will be trapped by the DAO.
739 *
740 * @access public
741 * @static
742 *
743 * @return array - array reference of all IM providers.
744 *
745 */
746 public static function &IMProvider($localize = FALSE) {
747 if (!self::$imProvider) {
748 self::$imProvider = CRM_Core_OptionGroup::values('instant_messenger_service', FALSE, FALSE, $localize);
749 }
750 return self::$imProvider;
751 }
752
753 /**
754 * Get all the website types from database.
755 *
756 * The static array websiteType is returned, and if it's
757 * called the first time, the <b>Website DAO</b> is used
758 * to get all the Website Types.
759 *
760 * Note: any database errors will be trapped by the DAO.
761 *
762 * @access public
763 * @static
764 *
765 * @return array - array reference of all Website types.
766 *
767 */
768 public static function &websiteType() {
769 if (!self::$websiteType) {
770 self::$websiteType = CRM_Core_OptionGroup::values('website_type');
771 }
772 return self::$websiteType;
773 }
774
775 /**
776 * Get the all From Email Address from database.
777 *
778 * The static array $fromEmailAddress is returned, and if it's
779 * called the first time, DAO is used
780 * to get all the From Email Address
781 *
782 * Note: any database errors will be trapped by the DAO.
783 *
784 * @access public
785 * @static
786 *
787 * @return array - array reference of all From Email Address.
788 */
789 public static function &fromEmailAddress() {
790 if (!self::$fromEmailAddress) {
791 self::$fromEmailAddress = CRM_Core_OptionGroup::values('from_email_address');
792 }
793 return self::$fromEmailAddress;
794 }
795
796 /**
797 * Get the all Mail Protocols from database.
798 *
799 * The static array mailProtocol is returned, and if it's
800 * called the first time, the DAO is used
801 * to get all the Mail Protocol.
802 *
803 * Note: any database errors will be trapped by the DAO.
804 *
805 * @access public
806 * @static
807 *
808 * @return array - array reference of all Mail Protocols.
809 */
810 public static function &mailProtocol() {
811 if (!self::$mailProtocol) {
812 self::$mailProtocol = CRM_Core_OptionGroup::values('mail_protocol');
813 }
814 return self::$mailProtocol;
815 }
816
817 /**
818 * Get all the State/Province from database.
819 *
820 * The static array stateProvince is returned, and if it's
821 * called the first time, the <b>State Province DAO</b> is used
822 * to get all the States.
823 *
824 * Note: any database errors will be trapped by the DAO.
825 *
826 * @access public
827 * @static
828 *
829 * @param int $id - Optional id to return
830 *
831 * @return array - array reference of all State/Provinces.
832 *
833 */
834 public static function &stateProvince($id = FALSE, $limit = TRUE) {
835 if (($id && !CRM_Utils_Array::value($id, self::$stateProvince)) || !self::$stateProvince || !$id) {
836 $whereClause = FALSE;
837 $config = CRM_Core_Config::singleton();
838 if ($limit) {
839 $countryIsoCodes = self::countryIsoCode();
840 $limitCodes = $config->provinceLimit();
841 $limitIds = array();
842 foreach ($limitCodes as $code) {
843 $limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
844 }
845 if (!empty($limitIds)) {
846 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
847 }
848 else {
849 $whereClause = FALSE;
850 }
851 }
852 self::populate(self::$stateProvince, 'CRM_Core_DAO_StateProvince', TRUE, 'name', 'is_active', $whereClause);
853
854 // localise the province names if in an non-en_US locale
855 global $tsLocale;
856 if ($tsLocale != '' and $tsLocale != 'en_US') {
857 $i18n = CRM_Core_I18n::singleton();
858 $i18n->localizeArray(self::$stateProvince, array(
859 'context' => 'province',
860 ));
861 self::$stateProvince = CRM_Utils_Array::asort(self::$stateProvince);
862 }
863 }
864 if ($id) {
865 if (array_key_exists($id, self::$stateProvince)) {
866 return self::$stateProvince[$id];
867 }
868 else {
869 $result = NULL;
870 return $result;
871 }
872 }
873 return self::$stateProvince;
874 }
875
876 /**
877 * Get all the State/Province abbreviations from the database.
878 *
879 * Same as above, except gets the abbreviations instead of the names.
880 *
881 * @access public
882 * @static
883 *
884 * @param int $id - Optional id to return
885 *
886 * @return array - array reference of all State/Province abbreviations.
887 */
888 public static function &stateProvinceAbbreviation($id = FALSE, $limit = TRUE) {
889 if ($id > 1) {
890 $query = "
891 SELECT abbreviation
892 FROM civicrm_state_province
893 WHERE id = %1";
894 $params = array(
895 1 => array(
896 $id,
897 'Integer',
898 ),
899 );
900 return CRM_Core_DAO::singleValueQuery($query, $params);
901 }
902
903 if (!self::$stateProvinceAbbreviation || !$id) {
904
905 $whereClause = FALSE;
906
907 if ($limit) {
908 $config = CRM_Core_Config::singleton();
909 $countryIsoCodes = self::countryIsoCode();
910 $limitCodes = $config->provinceLimit();
911 $limitIds = array();
912 foreach ($limitCodes as $code) {
913 $tmpArray = array_keys($countryIsoCodes, $code);
914
915 if (!empty($tmpArray)) {
916 $limitIds[] = array_shift($tmpArray);
917 }
918 }
919 if (!empty($limitIds)) {
920 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
921 }
922 }
923 self::populate(self::$stateProvinceAbbreviation, 'CRM_Core_DAO_StateProvince', TRUE, 'abbreviation', 'is_active', $whereClause);
924 }
925
926 if ($id) {
927 if (array_key_exists($id, self::$stateProvinceAbbreviation)) {
928 return self::$stateProvinceAbbreviation[$id];
929 }
930 else {
931 $result = NULL;
932 return $result;
933 }
934 }
935 return self::$stateProvinceAbbreviation;
936 }
937
938 /**
939 * Get all the countries from database.
940 *
941 * The static array country is returned, and if it's
942 * called the first time, the <b>Country DAO</b> is used
943 * to get all the countries.
944 *
945 * Note: any database errors will be trapped by the DAO.
946 *
947 * @access public
948 * @static
949 *
950 * @param int $id - Optional id to return
951 *
952 * @return array - array reference of all countries.
953 *
954 */
955 public static function country($id = FALSE, $applyLimit = TRUE) {
956 if (($id && !CRM_Utils_Array::value($id, self::$country)) || !self::$country || !$id) {
957
958 $config = CRM_Core_Config::singleton();
959 $limitCodes = array();
960
961 if ($applyLimit) {
962 // limit the country list to the countries specified in CIVICRM_COUNTRY_LIMIT
963 // (ensuring it's a subset of the legal values)
964 // K/P: We need to fix this, i dont think it works with new setting files
965 $limitCodes = $config->countryLimit();
966 if (!is_array($limitCodes)) {
967 $limitCodes = array(
968 $config->countryLimit => 1,
969 );
970 }
971
972 $limitCodes = array_intersect(self::countryIsoCode(), $limitCodes);
973 }
974
975 if (count($limitCodes)) {
976 $whereClause = "iso_code IN ('" . implode("', '", $limitCodes) . "')";
977 }
978 else {
979 $whereClause = NULL;
980 }
981
982 self::populate(self::$country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active', $whereClause);
983
984 // if default country is set, percolate it to the top
985 if ($config->defaultContactCountry()) {
986 $countryIsoCodes = self::countryIsoCode();
987 $defaultID = array_search($config->defaultContactCountry(), $countryIsoCodes);
988 if ($defaultID !== FALSE) {
989 $default[$defaultID] = CRM_Utils_Array::value($defaultID, self::$country);
990 self::$country = $default + self::$country;
991 }
992 }
993
994 // localise the country names if in an non-en_US locale
995 global $tsLocale;
996 if ($tsLocale != '' and $tsLocale != 'en_US') {
997 $i18n = CRM_Core_I18n::singleton();
998 $i18n->localizeArray(self::$country, array(
999 'context' => 'country',
1000 ));
1001 self::$country = CRM_Utils_Array::asort(self::$country);
1002 }
1003 }
1004 if ($id) {
1005 if (array_key_exists($id, self::$country)) {
1006 return self::$country[$id];
1007 }
1008 else {
1009 return NULL;
1010 }
1011 }
1012 return self::$country;
1013 }
1014
1015 /**
1016 * Get all the country ISO Code abbreviations from the database.
1017 *
1018 * The static array countryIsoCode is returned, and if it's
1019 * called the first time, the <b>Country DAO</b> is used
1020 * to get all the countries' ISO codes.
1021 *
1022 * Note: any database errors will be trapped by the DAO.
1023 *
1024 * @access public
1025 * @static
1026 *
1027 * @return array - array reference of all country ISO codes.
1028 *
1029 */
1030 public static function &countryIsoCode($id = FALSE) {
1031 if (!self::$countryIsoCode) {
1032 self::populate(self::$countryIsoCode, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
1033 }
1034 if ($id) {
1035 if (array_key_exists($id, self::$countryIsoCode)) {
1036 return self::$countryIsoCode[$id];
1037 }
1038 else {
1039 return NULL;
1040 }
1041 }
1042 return self::$countryIsoCode;
1043 }
1044
1045 /**
1046 * Get all the categories from database.
1047 *
1048 * The static array tag is returned, and if it's
1049 * called the first time, the <b>Tag DAO</b> is used
1050 * to get all the categories.
1051 *
1052 * Note: any database errors will be trapped by the DAO.
1053 *
1054 * @access public
1055 * @static
1056 *
1057 * @return array - array reference of all categories.
1058 *
1059 */
1060 public static function &tag() {
1061 if (!self::$tag) {
1062 self::populate(self::$tag, 'CRM_Core_DAO_Tag', TRUE);
1063 }
1064 return self::$tag;
1065 }
1066
1067 /**
1068 * Get all groups from database
1069 *
1070 * The static array group is returned, and if it's
1071 * called the first time, the <b>Group DAO</b> is used
1072 * to get all the groups.
1073 *
1074 * Note: any database errors will be trapped by the DAO.
1075 *
1076 * @param string $groupType type of group(Access/Mailing)
1077 * @param boolen $excludeHidden exclude hidden groups.
1078 *
1079 * @access public
1080 * @static
1081 *
1082 * @return array - array reference of all groups.
1083 *
1084 */
1085 public static function &allGroup($groupType = NULL, $excludeHidden = TRUE) {
1086 $condition = CRM_Contact_BAO_Group::groupTypeCondition($groupType, $excludeHidden);
1087
1088 if (!self::$group) {
1089 self::$group = array();
1090 }
1091
1092 $groupKey = $groupType ? $groupType : 'null';
1093
1094 if (!isset(self::$group[$groupKey])) {
1095 self::$group[$groupKey] = NULL;
1096 self::populate(self::$group[$groupKey], 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition);
1097 }
1098 return self::$group[$groupKey];
1099 }
1100
1101 /**
1102 * Create or get groups iterator (iterates over nested groups in a
1103 * logical fashion)
1104 *
1105 * The GroupNesting instance is returned; it's created if this is being
1106 * called for the first time
1107 *
1108 *
1109 * @access public
1110 * @static
1111 *
1112 * @return mixed - instance of CRM_Contact_BAO_GroupNesting
1113 *
1114 */
1115 public static function &groupIterator($styledLabels = FALSE) {
1116 if (!self::$groupIterator) {
1117 /*
1118 When used as an object, GroupNesting implements Iterator
1119 and iterates nested groups in a logical manner for us
1120 */
1121 self::$groupIterator = new CRM_Contact_BAO_GroupNesting($styledLabels);
1122 }
1123 return self::$groupIterator;
1124 }
1125
1126 /**
1127 * Get all permissioned groups from database
1128 *
1129 * The static array group is returned, and if it's
1130 * called the first time, the <b>Group DAO</b> is used
1131 * to get all the groups.
1132 *
1133 * Note: any database errors will be trapped by the DAO.
1134 *
1135 * @param string $groupType type of group(Access/Mailing)
1136 * @param boolen $excludeHidden exclude hidden groups.
1137
1138 * @access public
1139 * @static
1140 *
1141 * @return array - array reference of all groups.
1142 *
1143 */
1144 public static function group($groupType = NULL, $excludeHidden = TRUE) {
1145 return CRM_Core_Permission::group($groupType, $excludeHidden);
1146 }
1147
1148 /**
1149 * Get all permissioned groups from database
1150 *
1151 * The static array group is returned, and if it's
1152 * called the first time, the <b>Group DAO</b> is used
1153 * to get all the groups.
1154 *
1155 * Note: any database errors will be trapped by the DAO.
1156 *
1157 * @access public
1158 * @static
1159 *
1160 * @return array - array reference of all groups.
1161 *
1162 */
1163 public static function &staticGroup($onlyPublic = FALSE, $groupType = NULL, $excludeHidden = TRUE) {
1164 if (!self::$staticGroup) {
1165 $condition = 'saved_search_id = 0 OR saved_search_id IS NULL';
1166 if ($onlyPublic) {
1167 $condition .= " AND visibility != 'User and User Admin Only'";
1168 }
1169
1170 if ($groupType) {
1171 $condition .= ' AND ' . CRM_Contact_BAO_Group::groupTypeCondition($groupType);
1172 }
1173
1174 if ($excludeHidden) {
1175 $condition .= ' AND is_hidden != 1 ';
1176 }
1177
1178 self::populate(self::$staticGroup, 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition, 'title');
1179 }
1180
1181 return self::$staticGroup;
1182 }
1183
1184 /**
1185 * Get all the custom groups
1186 *
1187 * @access public
1188 *
1189 * @return array - array reference of all groups.
1190 * @static
1191 */
1192 public static function &customGroup($reset = FALSE) {
1193 if (!self::$customGroup || $reset) {
1194 self::populate(self::$customGroup, 'CRM_Core_DAO_CustomGroup', FALSE, 'title', 'is_active', NULL, 'title');
1195 }
1196 return self::$customGroup;
1197 }
1198
1199 /**
1200 * Get all the user framework groups
1201 *
1202 * @access public
1203 *
1204 * @return array - array reference of all groups.
1205 * @static
1206 */
1207 public static function &ufGroup() {
1208 if (!self::$ufGroup) {
1209 self::populate(self::$ufGroup, 'CRM_Core_DAO_UFGroup', FALSE, 'title', 'is_active', NULL, 'title');
1210 }
1211 return self::$ufGroup;
1212 }
1213
1214 /**
1215 * Get all the project tasks
1216 *
1217 * @access public
1218 *
1219 * @return array - array reference of all tasks
1220 * @static
1221 */
1222 public static function &tasks() {
1223 if (!self::$tasks) {
1224 self::populate(self::$tasks, 'CRM_Project_DAO_Task', FALSE, 'title', 'is_active', NULL, 'title');
1225 }
1226 return self::$tasks;
1227 }
1228
1229 /**
1230 * Get all Relationship Types from database.
1231 *
1232 * The static array group is returned, and if it's
1233 * called the first time, the <b>RelationshipType DAO</b> is used
1234 * to get all the relationship types.
1235 *
1236 * Note: any database errors will be trapped by the DAO.
1237 *
1238 * @param string $valueColumnName db column name/label.
1239 * @param boolean $reset reset relationship types if true
1240 *
1241 * @access public
1242 * @static
1243 *
1244 * @return array - array reference of all relationship types.
1245 */
1246 public static function &relationshipType($valueColumnName = 'label', $reset = FALSE) {
1247 if (!CRM_Utils_Array::value($valueColumnName, self::$relationshipType) || $reset) {
1248 self::$relationshipType[$valueColumnName] = array();
1249
1250 //now we have name/label columns CRM-3336
1251 $column_a_b = "{$valueColumnName}_a_b";
1252 $column_b_a = "{$valueColumnName}_b_a";
1253
1254 $relationshipTypeDAO = new CRM_Contact_DAO_RelationshipType();
1255 $relationshipTypeDAO->selectAdd();
1256 $relationshipTypeDAO->selectAdd("id, {$column_a_b}, {$column_b_a}, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b");
1257 $relationshipTypeDAO->is_active = 1;
1258 $relationshipTypeDAO->find();
1259 while ($relationshipTypeDAO->fetch()) {
1260
1261 self::$relationshipType[$valueColumnName][$relationshipTypeDAO->id] = array(
1262 $column_a_b => $relationshipTypeDAO->$column_a_b,
1263 $column_b_a => $relationshipTypeDAO->$column_b_a,
1264 'contact_type_a' => "$relationshipTypeDAO->contact_type_a",
1265 'contact_type_b' => "$relationshipTypeDAO->contact_type_b",
1266 'contact_sub_type_a' => "$relationshipTypeDAO->contact_sub_type_a",
1267 'contact_sub_type_b' => "$relationshipTypeDAO->contact_sub_type_b",
1268 );
1269 }
1270 }
1271
1272 return self::$relationshipType[$valueColumnName];
1273 }
1274
1275 /**
1276 * Get all the Currency Symbols from Database
1277 *
1278 * @access public
1279 *
1280 * @return array - array reference of all Currency Symbols
1281 * @static
1282 */
1283 public static function &currencySymbols($name = 'symbol', $key = 'id') {
1284 $cacheKey = "{$name}_{$key}";
1285 if (!isset(self::$currencySymbols[$cacheKey])) {
1286 self::populate(self::$currencySymbols[$cacheKey], 'CRM_Financial_DAO_Currency', TRUE, $name, NULL, NULL, 'name', $key);
1287 }
1288
1289 return self::$currencySymbols[$cacheKey];
1290 }
1291
1292 /**
1293 * get all the ISO 4217 currency codes
1294 *
1295 * so far, we use this for validation only, so there's no point of putting this into the database
1296 *
1297 * @access public
1298 *
1299 * @return array - array reference of all currency codes
1300 * @static
1301 */
1302 public static function &currencyCode() {
1303 if (!self::$currencyCode) {
1304 self::$currencyCode = array(
1305 'AFN',
1306 'ALL',
1307 'DZD',
1308 'USD',
1309 'EUR',
1310 'AOA',
1311 'XCD',
1312 'XCD',
1313 'ARS',
1314 'AMD',
1315 'AWG',
1316 'AUD',
1317 'EUR',
1318 'AZM',
1319 'BSD',
1320 'BHD',
1321 'BDT',
1322 'BBD',
1323 'BYR',
1324 'EUR',
1325 'BZD',
1326 'XOF',
1327 'BMD',
1328 'INR',
1329 'BTN',
1330 'BOB',
1331 'BOV',
1332 'BAM',
1333 'BWP',
1334 'NOK',
1335 'BRL',
1336 'USD',
1337 'BND',
1338 'BGN',
1339 'XOF',
1340 'BIF',
1341 'KHR',
1342 'XAF',
1343 'CAD',
1344 'CVE',
1345 'KYD',
1346 'XAF',
1347 'XAF',
1348 'CLP',
1349 'CLF',
1350 'CNY',
1351 'AUD',
1352 'AUD',
1353 'COP',
1354 'COU',
1355 'KMF',
1356 'XAF',
1357 'CDF',
1358 'NZD',
1359 'CRC',
1360 'XOF',
1361 'HRK',
1362 'CUP',
1363 'CYP',
1364 'CZK',
1365 'DKK',
1366 'DJF',
1367 'XCD',
1368 'DOP',
1369 'USD',
1370 'EGP',
1371 'SVC',
1372 'USD',
1373 'XAF',
1374 'ERN',
1375 'EEK',
1376 'ETB',
1377 'FKP',
1378 'DKK',
1379 'FJD',
1380 'EUR',
1381 'EUR',
1382 'EUR',
1383 'XPF',
1384 'EUR',
1385 'XAF',
1386 'GMD',
1387 'GEL',
1388 'EUR',
1389 'GHC',
1390 'GIP',
1391 'EUR',
1392 'DKK',
1393 'XCD',
1394 'EUR',
1395 'USD',
1396 'GTQ',
1397 'GNF',
1398 'GWP',
1399 'XOF',
1400 'GYD',
1401 'HTG',
1402 'USD',
1403 'AUD',
1404 'EUR',
1405 'HNL',
1406 'HKD',
1407 'HUF',
1408 'ISK',
1409 'INR',
1410 'IDR',
1411 'XDR',
1412 'IRR',
1413 'IQD',
1414 'EUR',
1415 'ILS',
1416 'EUR',
1417 'JMD',
1418 'JPY',
1419 'JOD',
1420 'KZT',
1421 'KES',
1422 'AUD',
1423 'KPW',
1424 'KRW',
1425 'KWD',
1426 'KGS',
1427 'LAK',
1428 'LVL',
1429 'LBP',
1430 'ZAR',
1431 'LSL',
1432 'LRD',
1433 'LYD',
1434 'CHF',
1435 'LTL',
1436 'EUR',
1437 'MOP',
1438 'MKD',
1439 'MGA',
1440 'MWK',
1441 'MYR',
1442 'MVR',
1443 'XOF',
1444 'MTL',
1445 'USD',
1446 'EUR',
1447 'MRO',
1448 'MUR',
1449 'EUR',
1450 'MXN',
1451 'MXV',
1452 'USD',
1453 'MDL',
1454 'EUR',
1455 'MNT',
1456 'XCD',
1457 'MAD',
1458 'MZM',
1459 'MMK',
1460 'ZAR',
1461 'NAD',
1462 'AUD',
1463 'NPR',
1464 'EUR',
1465 'ANG',
1466 'XPF',
1467 'NZD',
1468 'NIO',
1469 'XOF',
1470 'NGN',
1471 'NZD',
1472 'AUD',
1473 'USD',
1474 'NOK',
1475 'OMR',
1476 'PKR',
1477 'USD',
1478 'PAB',
1479 'USD',
1480 'PGK',
1481 'PYG',
1482 'PEN',
1483 'PHP',
1484 'NZD',
1485 'PLN',
1486 'EUR',
1487 'USD',
1488 'QAR',
1489 'EUR',
1490 'ROL',
1491 'RON',
1492 'RUB',
1493 'RWF',
1494 'SHP',
1495 'XCD',
1496 'XCD',
1497 'EUR',
1498 'XCD',
1499 'WST',
1500 'EUR',
1501 'STD',
1502 'SAR',
1503 'XOF',
1504 'CSD',
1505 'EUR',
1506 'SCR',
1507 'SLL',
1508 'SGD',
1509 'SKK',
1510 'SIT',
1511 'SBD',
1512 'SOS',
1513 'ZAR',
1514 'EUR',
1515 'LKR',
1516 'SDD',
1517 'SRD',
1518 'NOK',
1519 'SZL',
1520 'SEK',
1521 'CHF',
1522 'CHW',
1523 'CHE',
1524 'SYP',
1525 'TWD',
1526 'TJS',
1527 'TZS',
1528 'THB',
1529 'USD',
1530 'XOF',
1531 'NZD',
1532 'TOP',
1533 'TTD',
1534 'TND',
1535 'TRY',
1536 'TRL',
1537 'TMM',
1538 'USD',
1539 'AUD',
1540 'UGX',
1541 'UAH',
1542 'AED',
1543 'GBP',
1544 'USD',
1545 'USS',
1546 'USN',
1547 'USD',
1548 'UYU',
1549 'UZS',
1550 'VUV',
1551 'VEB',
1552 'VND',
1553 'USD',
1554 'USD',
1555 'XPF',
1556 'MAD',
1557 'YER',
1558 'ZMK',
1559 'ZWD',
1560 'XAU',
1561 'XBA',
1562 'XBB',
1563 'XBC',
1564 'XBD',
1565 'XPD',
1566 'XPT',
1567 'XAG',
1568 'XFU',
1569 'XFO',
1570 'XTS',
1571 'XXX',
1572 );
1573 }
1574 return self::$currencyCode;
1575 }
1576
1577 /**
1578 * Get all the County from database.
1579 *
1580 * The static array county is returned, and if it's
1581 * called the first time, the <b>County DAO</b> is used
1582 * to get all the Counties.
1583 *
1584 * Note: any database errors will be trapped by the DAO.
1585 *
1586 * @access public
1587 * @static
1588 *
1589 * @param int $id - Optional id to return
1590 *
1591 * @return array - array reference of all Counties
1592 *
1593 */
1594 public static function &county($id = FALSE) {
1595 if (!self::$county) {
1596
1597 $config = CRM_Core_Config::singleton();
1598 // order by id so users who populate civicrm_county can have more control over sort by the order they load the counties
1599 self::populate(self::$county, 'CRM_Core_DAO_County', TRUE, 'name', NULL, NULL, 'id');
1600 }
1601 if ($id) {
1602 if (array_key_exists($id, self::$county)) {
1603 return self::$county[$id];
1604 }
1605 else {
1606 return NULL;
1607 }
1608 }
1609 return self::$county;
1610 }
1611
1612 /**
1613 * Get all the Preferred Communication Methods from database.
1614 *
1615 * @access public
1616 * @static
1617 *
1618 * @return array self::pcm - array reference of all preferred communication methods.
1619 *
1620 */
1621 public static function &pcm($localize = FALSE) {
1622 if (!self::$pcm) {
1623 self::$pcm = CRM_Core_OptionGroup::values('preferred_communication_method', FALSE, FALSE, $localize);
1624 }
1625 return self::$pcm;
1626 }
1627
1628 /**
1629 * Alias of pcm
1630 */
1631 public static function preferredCommunicationMethod($localize = FALSE) {
1632 return self::pcm($localize);
1633 }
1634
1635 /**
1636 * Get all active payment processors
1637 *
1638 * The static array paymentProcessor is returned
1639 *
1640 * @access public
1641 * @static
1642 *
1643 * @param boolean $all - get payment processors - default is to get only active ones.
1644 * @param boolean $test - get test payment processors
1645 *
1646 * @return array - array of all payment processors
1647 *
1648 */
1649 public static function &paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
1650 $condition = "is_test = ";
1651 $condition .= ($test) ? '1' : '0';
1652
1653 if ($additionalCond) {
1654 $condition .= " AND ( $additionalCond ) ";
1655 }
1656
1657 // CRM-7178. Make sure we only include payment processors valid in ths
1658 // domain
1659 $condition .= " AND domain_id = " . CRM_Core_Config::domainID();
1660
1661 $cacheKey = $condition . '_' . (int) $all;
1662 if (!isset(self::$paymentProcessor[$cacheKey])) {
1663 self::populate(self::$paymentProcessor[$cacheKey], 'CRM_Financial_DAO_PaymentProcessor', $all, 'name', 'is_active', $condition, 'is_default desc, name');
1664 }
1665
1666 return self::$paymentProcessor[$cacheKey];
1667 }
1668
1669 /**
1670 * Get all active payment processors
1671 *
1672 * The static array paymentProcessorType is returned
1673 *
1674 * @access public
1675 * @static
1676 *
1677 * @param boolean $all - get payment processors - default is to get only active ones.
1678 *
1679 * @return array - array of all payment processor types
1680 *
1681 */
1682 public static function &paymentProcessorType($all = FALSE, $id = NULL, $return = 'title') {
1683 $cacheKey = $id . '_' .$return;
1684 if (empty(self::$paymentProcessorType[$cacheKey])) {
1685 self::populate(self::$paymentProcessorType[$cacheKey], 'CRM_Financial_DAO_PaymentProcessorType', $all, $return, 'is_active', NULL, "is_default, $return", 'id');
1686 }
1687 if ($id && CRM_Utils_Array::value($id, self::$paymentProcessorType[$cacheKey])) {
1688 return self::$paymentProcessorType[$cacheKey][$id];
1689 }
1690 return self::$paymentProcessorType[$cacheKey];
1691 }
1692
1693 /**
1694 * Get all the World Regions from Database
1695 *
1696 * @access public
1697 *
1698 * @return array - array reference of all World Regions
1699 * @static
1700 */
1701 public static function &worldRegion($id = FALSE) {
1702 if (!self::$worldRegions) {
1703 self::populate(self::$worldRegions, 'CRM_Core_DAO_Worldregion', TRUE, 'name', NULL, NULL, 'id');
1704 }
1705
1706 if ($id) {
1707 if (array_key_exists($id, self::$worldRegions)) {
1708 return self::$worldRegions[$id];
1709 }
1710 else {
1711 return NULL;
1712 }
1713 }
1714
1715 return self::$worldRegions;
1716 }
1717
1718 /**
1719 * Get all Honor Type.
1720 *
1721 * The static array honorType is returned
1722 *
1723 * @access public
1724 * @static
1725 *
1726 * @param boolean $all - get All Honor Type.
1727 *
1728 * @return array - array reference of all Honor Types.
1729 *
1730 */
1731 public static function &honor() {
1732 if (!self::$honorType) {
1733 self::$honorType = CRM_Core_OptionGroup::values('honor_type');
1734 }
1735 return self::$honorType;
1736 }
1737
1738 /**
1739 * Get all Activity Statuses.
1740 *
1741 * The static array activityStatus is returned
1742 *
1743 * @access public
1744 * @static
1745 *
1746 * @return array - array reference of all activity statuses
1747 */
1748 public static function &activityStatus($column = 'label') {
1749 if (NULL === self::$activityStatus) {
1750 self::$activityStatus = array();
1751 }
1752 if (!array_key_exists($column, self::$activityStatus)) {
1753 self::$activityStatus[$column] = array();
1754
1755 self::$activityStatus[$column] = CRM_Core_OptionGroup::values('activity_status', FALSE, FALSE, FALSE, NULL, $column);
1756 }
1757
1758 return self::$activityStatus[$column];
1759 }
1760
1761 /**
1762 * Get all Priorities
1763 *
1764 * The static array Priority is returned
1765 *
1766 * @access public
1767 * @static
1768 *
1769 * @return array - array reference of all Priority
1770 */
1771 public static function &priority() {
1772 if (!self::$priority) {
1773 self::$priority = CRM_Core_OptionGroup::values('priority');
1774 }
1775
1776 return self::$priority;
1777 }
1778
1779 /**
1780 * Get all WYSIWYG Editors.
1781 *
1782 * The static array wysiwygEditor is returned
1783 *
1784 * @access public
1785 * @static
1786 *
1787 * @return array - array reference of all wysiwygEditors
1788 */
1789 public static function &wysiwygEditor() {
1790 if (!self::$wysiwygEditor) {
1791 self::$wysiwygEditor = CRM_Core_OptionGroup::values('wysiwyg_editor');
1792 }
1793 return self::$wysiwygEditor;
1794 }
1795
1796 /**
1797 * Get all Visibility levels.
1798 *
1799 * The static array visibility is returned
1800 *
1801 * @access public
1802 * @static
1803 *
1804 * @return array - array reference of all Visibility levels.
1805 *
1806 */
1807 public static function &visibility($column = 'label') {
1808 if (!isset(self::$visibility)) {
1809 self::$visibility = array( );
1810 }
1811
1812 if (!isset(self::$visibility[$column])) {
1813 self::$visibility[$column] = CRM_Core_OptionGroup::values('visibility', FALSE, FALSE, FALSE, NULL, $column);
1814 }
1815
1816 return self::$visibility[$column];
1817 }
1818
1819 /**
1820 * Get all mapping types
1821 *
1822 * @return array - array reference of all mapping types
1823 * @access public
1824 * @static
1825 */
1826 public static function &mappingTypes() {
1827 if (!self::$mappingType) {
1828 self::$mappingType = CRM_Core_OptionGroup::values('mapping_type');
1829 }
1830 return self::$mappingType;
1831 }
1832
1833 public static function &stateProvinceForCountry($countryID, $field = 'name') {
1834 static $_cache = NULL;
1835
1836 $cacheKey = "{$countryID}_{$field}";
1837 if (!$_cache) {
1838 $_cache = array();
1839 }
1840
1841 if (!empty($_cache[$cacheKey])) {
1842 return $_cache[$cacheKey];
1843 }
1844
1845 $query = "
1846 SELECT civicrm_state_province.{$field} name, civicrm_state_province.id id
1847 FROM civicrm_state_province
1848 WHERE country_id = %1
1849 ORDER BY name";
1850 $params = array(
1851 1 => array(
1852 $countryID,
1853 'Integer',
1854 ),
1855 );
1856
1857 $dao = CRM_Core_DAO::executeQuery($query, $params);
1858
1859 $result = array();
1860 while ($dao->fetch()) {
1861 $result[$dao->id] = $dao->name;
1862 }
1863
1864 // localise the stateProvince names if in an non-en_US locale
1865 $config = CRM_Core_Config::singleton();
1866 global $tsLocale;
1867 if ($tsLocale != '' and $tsLocale != 'en_US') {
1868 $i18n = CRM_Core_I18n::singleton();
1869 $i18n->localizeArray($result, array(
1870 'context' => 'province',
1871 ));
1872 $result = CRM_Utils_Array::asort($result);
1873 }
1874
1875 $_cache[$cacheKey] = $result;
1876
1877 CRM_Utils_Hook::buildStateProvinceForCountry($countryID, $result);
1878
1879 return $result;
1880 }
1881
1882 public static function &countyForState($stateID) {
1883 if (is_array($stateID)) {
1884 $states = implode(", ", $stateID);
1885 $query = "
1886 SELECT civicrm_county.name name, civicrm_county.id id, civicrm_state_province.abbreviation abbreviation
1887 FROM civicrm_county
1888 LEFT JOIN civicrm_state_province ON civicrm_county.state_province_id = civicrm_state_province.id
1889 WHERE civicrm_county.state_province_id in ( $states )
1890 ORDER BY civicrm_state_province.abbreviation, civicrm_county.name";
1891
1892 $dao = CRM_Core_DAO::executeQuery($query);
1893
1894 $result = array();
1895 while ($dao->fetch()) {
1896 $result[$dao->id] = $dao->abbreviation . ': ' . $dao->name;
1897 }
1898 }
1899 else {
1900
1901 static $_cache = NULL;
1902
1903 $cacheKey = "{$stateID}_name";
1904 if (!$_cache) {
1905 $_cache = array();
1906 }
1907
1908 if (!empty($_cache[$cacheKey])) {
1909 return $_cache[$cacheKey];
1910 }
1911
1912 $query = "
1913 SELECT civicrm_county.name name, civicrm_county.id id
1914 FROM civicrm_county
1915 WHERE state_province_id = %1
1916 ORDER BY name";
1917 $params = array(
1918 1 => array(
1919 $stateID,
1920 'Integer',
1921 ),
1922 );
1923
1924 $dao = CRM_Core_DAO::executeQuery($query, $params);
1925
1926 $result = array();
1927 while ($dao->fetch()) {
1928 $result[$dao->id] = $dao->name;
1929 }
1930 }
1931
1932 return $result;
1933 }
1934
1935 /**
1936 * Get all types of Greetings.
1937 *
1938 * The static array of greeting is returned
1939 *
1940 * @access public
1941 * @static
1942 *
1943 * @param $filter - get All Email Greetings - default is to get only active ones.
1944 *
1945 * @return array - array reference of all greetings.
1946 *
1947 */
1948 public static function greeting($filter, $columnName = 'label') {
1949 $index = $filter['greeting_type'] . '_' . $columnName;
1950
1951 // also add contactType to the array
1952 $contactType = CRM_Utils_Array::value('contact_type', $filter);
1953 if ($contactType) {
1954 $index .= '_' . $contactType;
1955 }
1956
1957 if (NULL === self::$greeting) {
1958 self::$greeting = array();
1959 }
1960
1961 if (!CRM_Utils_Array::value($index, self::$greeting)) {
1962 $filterCondition = NULL;
1963 if ($contactType) {
1964 $filterVal = 'v.filter =';
1965 switch ($contactType) {
1966 case 'Individual':
1967 $filterVal .= "1";
1968 break;
1969
1970 case 'Household':
1971 $filterVal .= "2";
1972 break;
1973
1974 case 'Organization':
1975 $filterVal .= "3";
1976 break;
1977 }
1978 $filterCondition .= "AND (v.filter = 0 OR {$filterVal}) ";
1979 }
1980
1981 self::$greeting[$index] = CRM_Core_OptionGroup::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName);
1982 }
1983
1984 return self::$greeting[$index];
1985 }
1986
1987 /**
1988 * Construct array of default greeting values for contact type
1989 *
1990 * @access public
1991 * @static
1992 *
1993 * @return array - array reference of default greetings.
1994 *
1995 */
1996 public static function &greetingDefaults() {
1997 if (!self::$greetingDefaults) {
1998 $defaultGreetings = array();
1999 $contactTypes = array(
2000 'Individual' => 1,
2001 'Household' => 2,
2002 'Organization' => 3,
2003 );
2004
2005 foreach ($contactTypes as $contactType => $filter) {
2006 $filterCondition = " AND (v.filter = 0 OR v.filter = $filter) AND v.is_default = 1 ";
2007
2008 foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
2009 $tokenVal = CRM_Core_OptionGroup::values($greeting, NULL, NULL, NULL, $filterCondition, 'label');
2010 $defaultGreetings[$contactType][$greeting] = $tokenVal;
2011 }
2012 }
2013
2014 self::$greetingDefaults = $defaultGreetings;
2015 }
2016
2017 return self::$greetingDefaults;
2018 }
2019
2020 /**
2021 * Get all the Languages from database.
2022 *
2023 * @access public
2024 * @static
2025 *
2026 * @return array self::languages - array reference of all languages
2027 *
2028 */
2029 public static function &languages() {
2030 return CRM_Core_I18n_PseudoConstant::languages();
2031 }
2032
2033 /**
2034 * Alias of above
2035 */
2036 public static function &preferredLanguage() {
2037 return CRM_Core_I18n_PseudoConstant::languages();
2038 }
2039
2040 /**
2041 * Get all extensions
2042 *
2043 * The static array extensions
2044 *
2045 * FIXME: This is called by civix but not by any core code. We
2046 * should provide an API call which civix can use instead.
2047 *
2048 * @access public
2049 * @static
2050 *
2051 * @return array - array($fullyQualifiedName => $label) list of extensions
2052 */
2053 public static function &getExtensions() {
2054 if (!self::$extensions) {
2055 self::$extensions = array();
2056 $sql = '
2057 SELECT full_name, label
2058 FROM civicrm_extension
2059 WHERE is_active = 1
2060 ';
2061 $dao = CRM_Core_DAO::executeQuery($sql);
2062 while ($dao->fetch()) {
2063 self::$extensions[$dao->full_name] = $dao->label;
2064 }
2065 }
2066
2067 return self::$extensions;
2068 }
2069
2070 /**
2071 * Fetch the list of active extensions of type 'module'
2072 *
2073 * @param $fresh bool whether to forcibly reload extensions list from canonical store
2074 * @access public
2075 * @static
2076 *
2077 * @return array - array(array('prefix' => $, 'file' => $))
2078 */
2079 public static function getModuleExtensions($fresh = FALSE) {
2080 return CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles($fresh);
2081 }
2082
2083 /**
2084 * Get all Activity Contacts
2085 *
2086 * The static array activityContacts is returned
2087 *
2088 * @access public
2089 * @static
2090 *
2091 * @param string $column db column name/label.
2092 *
2093 * @return array - array reference of all activity Contacts
2094 *
2095 */
2096 public static function &activityContacts($column = 'label') {
2097 if (!self::$activityContacts) {
2098 self::$activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, $column);
2099 }
2100 return self::$activityContacts;
2101 }
2102
2103 /**
2104 * Get all Event Contacts
2105 *
2106 * The static array eventContacts is returned
2107 *
2108 * @access public
2109 * @static
2110 *
2111 * @param string $column db column name/label.
2112 *
2113 * @return array - array reference of all event Contacts
2114 *
2115 */
2116 public static function &eventContacts($column = 'label') {
2117 if (!self::$eventContacts) {
2118 self::$eventContacts = CRM_Core_OptionGroup::values('event_contacts', FALSE, FALSE, FALSE, NULL, $column);
2119 }
2120 return self::$eventContacts;
2121 }
2122
2123 /**
2124 * Get all options values
2125 *
2126 * The static array option values is returned
2127 *
2128 * @access public
2129 * @static
2130 *
2131 * @param boolean $optionGroupName - get All Option Group values- default is to get only active ones.
2132 *
2133 * @return array - array reference of all Option Group Name
2134 *
2135 */
2136 public static function accountOptionValues($optionGroupName, $id = null, $condition = null) {
2137 $cacheKey = $optionGroupName . '_' . $condition;
2138 if (empty(self::$accountOptionValues[$cacheKey])) {
2139 self::$accountOptionValues[$cacheKey] = CRM_Core_OptionGroup::values($optionGroupName, false, false, false, $condition);
2140 }
2141 if ($id) {
2142 return CRM_Utils_Array::value($id, self::$accountOptionValues[$cacheKey]);
2143 }
2144
2145 return self::$accountOptionValues[$cacheKey];
2146 }
2147
2148 /**
2149 * Get all batch modes
2150 *
2151 * The static array batchModes
2152 *
2153 * @access public
2154 * @static
2155 *
2156 * @return array - array reference of all batch modes
2157 */
2158 public static function &getBatchMode($columnName = 'label') {
2159 if (!self::$batchModes) {
2160 self::$batchModes = CRM_Core_OptionGroup::values('batch_mode', false, false, false, null, $columnName);
2161 }
2162
2163 return self::$batchModes;
2164 }
2165
2166 /**
2167 * Get all batch types
2168 *
2169 * The static array batchTypes
2170 *
2171 * @access public
2172 * @static
2173 *
2174 * @return array - array reference of all batch types
2175 */
2176 public static function &getBatchType() {
2177 if (!self::$batchTypes) {
2178 self::$batchTypes = CRM_Core_OptionGroup::values('batch_type');
2179 }
2180
2181 return self::$batchTypes;
2182 }
2183
2184 /**
2185 * Get all batch statuses
2186 *
2187 * The static array batchStatues
2188 *
2189 * @access public
2190 * @static
2191 *
2192 * @return array - array reference of all batch statuses
2193 */
2194 public static function &getBatchStatus() {
2195 if (!self::$batchStatues) {
2196 self::$batchStatues = CRM_Core_OptionGroup::values('batch_status');
2197 }
2198
2199 return self::$batchStatues;
2200 }
2201
2202 /*
2203 * The static array contactType is returned
2204 *
2205 * @access public
2206 * @static
2207 * @param string $column db column name/label.
2208 *
2209 * @return array - array reference of all Types
2210 *
2211 */
2212
2213 public static function &contactType($column = 'label') {
2214 if (!self::$contactType) {
2215 self::$contactType = CRM_Contact_BAO_ContactType::basicTypePairs(TRUE);
2216 }
2217 return self::$contactType;
2218 }
2219
2220 /**
2221 * Get all the auto renew options
2222 *
2223 * @access public
2224 * @static
2225 *
2226 * @return array self::autoRenew - array reference of all autoRenew
2227 *
2228 */
2229 public static function &autoRenew() {
2230 if (!self::$autoRenew) {
2231 self::$autoRenew = CRM_Core_OptionGroup::values('auto_renew_options', FALSE, FALSE);
2232 }
2233 return self::$autoRenew;
2234 }
2235 }
2236