Merge pull request #888 from cividesk/CRM-12716
[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 * static cache for pseudoconstant arrays
54 * @var array
55 * @static
56 */
57 private static $cache;
58
59 /**
60 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
61 *
62 * activity type
63 * @var array
64 * @static
65 */
66 private static $activityType;
67
68 /**
69 * states, provinces
70 * @var array
71 * @static
72 */
73 private static $stateProvince;
74
75 /**
76 * counties
77 * @var array
78 * @static
79 */
80 private static $county;
81
82 /**
83 * states/provinces abbreviations
84 * @var array
85 * @static
86 */
87 private static $stateProvinceAbbreviation;
88
89 /**
90 * country
91 * @var array
92 * @static
93 */
94 private static $country;
95
96 /**
97 * countryIsoCode
98 * @var array
99 * @static
100 */
101 private static $countryIsoCode;
102
103 /**
104 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
105 *
106 * group
107 * @var array
108 * @static
109 */
110 private static $group;
111
112 /**
113 * groupIterator
114 * @var mixed
115 * @static
116 */
117 private static $groupIterator;
118
119 /**
120 * relationshipType
121 * @var array
122 * @static
123 */
124 private static $relationshipType;
125
126 /**
127 * civicrm groups that are not smart groups
128 * @var array
129 * @static
130 */
131 private static $staticGroup;
132
133 /**
134 * currency codes
135 * @var array
136 * @static
137 */
138 private static $currencyCode;
139
140 /**
141 * payment processor
142 * @var array
143 * @static
144 */
145 private static $paymentProcessor;
146
147 /**
148 * payment processor types
149 * @var array
150 * @static
151 */
152 private static $paymentProcessorType;
153
154 /**
155 * World Region
156 * @var array
157 * @static
158 */
159 private static $worldRegions;
160
161 /**
162 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
163 *
164 * activity status
165 * @var array
166 * @static
167 */
168 private static $activityStatus;
169
170 /**
171 * Visibility
172 * @var array
173 * @static
174 */
175 private static $visibility;
176
177 /**
178 * Greetings
179 * @var array
180 * @static
181 */
182 private static $greeting;
183
184 /**
185 * Default Greetings
186 * @var array
187 * @static
188 */
189 private static $greetingDefaults;
190
191 /**
192 * Extensions of type module
193 * @var array
194 * @static
195 */
196 private static $extensions;
197
198 /**
199 * Financial Account Type
200 * @var array
201 * @static
202 */
203 private static $accountOptionValues;
204
205 /**
206 * Low-level option getter, rarely accessed directly.
207 * NOTE: Rather than calling this function directly use CRM_*_BAO_*::buildOptions()
208 *
209 * @param String $daoName
210 * @param String $fieldName
211 * @param Array $params
212 * - name string name of the option group
213 * - flip boolean results are return in id => label format if false
214 * if true, the results are reversed
215 * - grouping boolean if true, return the value in 'grouping' column (currently unsupported for tables other than option_value)
216 * - localize boolean if true, localize the results before returning
217 * - condition string|array add condition(s) to the sql query - will be concatenated using 'AND'
218 * - keyColumn string the column to use for 'id'
219 * - labelColumn string the column to use for 'label'
220 * - orderColumn string the column to use for sorting, defaults to 'weight' column if one exists, else defaults to labelColumn
221 * - onlyActive boolean return only the action option values
222 * - fresh boolean ignore cache entries and go back to DB
223 *
224 * @return Array on success, FALSE on error.
225 *
226 * @static
227 */
228 public static function get($daoName, $fieldName, $params = array()) {
229 $flip = !empty($params['flip']);
230
231 // Custom fields are not in the schema
232 if (strpos($fieldName, 'custom') === 0) {
233 $dao = new CRM_Core_DAO_CustomField;
234 $dao->id = (int) substr($fieldName, 7);
235 $dao->find(TRUE);
236 $customField = (array) $dao;
237 $dao->free();
238 $output = array();
239 CRM_Core_BAO_CustomField::buildOption($customField, $output);
240 return $flip ? array_flip($output) : $output;
241 }
242
243 // Core field: load schema
244 $dao = new $daoName;
245 $fields = $dao->fields();
246 $fieldKeys = $dao->fieldKeys();
247 $fieldKey = $fieldKeys[$fieldName];
248 $dao->free();
249 if (empty($fields[$fieldKey])) {
250 return FALSE;
251 }
252 $fieldSpec = $fields[$fieldKey];
253
254 // If the field is an enum, explode the enum definition and return the array.
255 if (isset($fieldSpec['enumValues'])) {
256 // use of a space after the comma is inconsistent in xml
257 $enumStr = str_replace(', ', ',', $fieldSpec['enumValues']);
258 $output = explode(',', $enumStr);
259 return $flip ? array_flip($output) : $output;
260 }
261
262 elseif (!empty($fieldSpec['pseudoconstant'])) {
263 $pseudoconstant = $fieldSpec['pseudoconstant'];
264 // Merge params with defaults
265 $params += array(
266 'grouping' => FALSE,
267 'localize' => FALSE,
268 'condition' => CRM_Utils_Array::value('condition', $pseudoconstant),
269 'keyColumn' => CRM_Utils_Array::value('keyColumn', $pseudoconstant),
270 'labelColumn' => CRM_Utils_Array::value('labelColumn', $pseudoconstant),
271 'onlyActive' => TRUE,
272 'fresh' => FALSE,
273 );
274
275 // Fetch option group from option_value table
276 if(!empty($pseudoconstant['optionGroupName'])) {
277 // Call our generic fn for retrieving from the option_value table
278 return CRM_Core_OptionGroup::values(
279 $pseudoconstant['optionGroupName'],
280 $flip,
281 $params['grouping'],
282 $params['localize'],
283 $params['condition'] ? ' AND ' . implode(' AND ', (array) $params['condition']) : NULL,
284 $params['labelColumn'] ? $params['labelColumn'] : 'label',
285 $params['onlyActive'],
286 $params['fresh'],
287 $params['keyColumn'] ? $params['keyColumn'] : 'value'
288 );
289 }
290
291 // Fetch options from other tables
292 if (!empty($pseudoconstant['table'])) {
293 // Normalize params so the serialized cache string will be consistent.
294 CRM_Utils_Array::remove($params, 'flip', 'fresh');
295 ksort($params);
296 $cacheKey = $daoName . $fieldName . serialize($params);
297
298 // Retrieve cached options
299 if (isset(self::$cache[$cacheKey]) && empty($params['fresh'])) {
300 $output = self::$cache[$cacheKey];
301 }
302 else {
303 $daoName = CRM_Core_DAO_AllCoreTables::getClassForTable($pseudoconstant['table']);
304 if (!class_exists($daoName)) {
305 return FALSE;
306 }
307 // Get list of fields for the option table
308 $dao = new $daoName;
309 $availableFields = array_keys($dao->fieldKeys());
310 if (in_array('is_active', $availableFields)) {
311 $wheres[] = 'is_active = 1';
312 }
313 $dao->free();
314
315 $select = "SELECT %1 AS id, %2 AS label";
316 $from = "FROM %3";
317 $wheres = array();
318 $order = "ORDER BY %2";
319 // Condition param can be passed as an sql clause string or an array of clauses
320 if (!empty($params['condition'])) {
321 $wheres[] = implode(' AND ', (array) $params['condition']);
322 }
323 // onlyActive param will automatically filter on common flags
324 if (!empty($params['onlyActive'])) {
325 foreach (array('is_active' => 1, 'is_deleted' => 0, 'is_test' => 0) as $flag => $val) {
326 if (in_array($flag, $availableFields)) {
327 $wheres[] = "$flag = $val";
328 }
329 }
330 }
331 // Filter domain specific options
332 if (in_array('domain_id', $availableFields)) {
333 $wheres[] = 'domain_id = ' . CRM_Core_Config::domainID();
334 }
335 $queryParams = array(
336 1 => array($params['keyColumn'], 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES),
337 2 => array($params['labelColumn'], 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES),
338 3 => array($pseudoconstant['table'], 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES),
339 );
340 // Add orderColumn param
341 if (!empty($params['orderColumn'])) {
342 $queryParams[4] = array($params['orderColumn'], 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES);
343 $order = "ORDER BY %4";
344 }
345 // Support no sorting if $params[orderColumn] is FALSE
346 elseif (isset($params['orderColumn']) && $params['orderColumn'] === FALSE) {
347 $order = '';
348 }
349 // Default to 'weight' if that column exists
350 elseif (in_array('weight', $availableFields)) {
351 $order = "ORDER BY weight";
352 }
353
354 $output = array();
355 $query = "$select $from";
356 if ($wheres) {
357 $query .= " WHERE " . implode($wheres, ' AND ');
358 }
359 $query .= ' ' . $order;
360 $dao = CRM_Core_DAO::executeQuery($query, $queryParams);
361 while ($dao->fetch()) {
362 $output[$dao->id] = $dao->label;
363 }
364 $dao->free();
365 if (!empty($params['localize'])) {
366 $i18n = CRM_Core_I18n::singleton();
367 $i18n->localizeArray($output);
368 // Maintain sort by label
369 if ($order == "ORDER BY %2") {
370 CRM_Utils_Array::asort($output);
371 }
372 }
373 self::$cache[$cacheKey] = $output;
374 }
375 return $flip ? array_flip($output) : $output;
376 }
377 }
378 // If we're still here, it's an error. Return FALSE.
379 return FALSE;
380 }
381
382 /**
383 * Fetch the label (or other value) for a field given its key
384 *
385 * @param String $daoName
386 * @param String $fieldName
387 * @param String|Int $key
388 * @param Array $params will be passed into self::get
389 *
390 * @return string
391 */
392 function getValue($daoName, $fieldName, $key, $params = array()) {
393 $values = self::get($daoName, $fieldName, $params);
394 return CRM_Utils_Array::value($key, $values);
395 }
396
397 /**
398 * Fetch the key for a field option given its label/name
399 *
400 * @param String $daoName
401 * @param String $fieldName
402 * @param String|Int $value
403 * @param Array $params will be passed into self::get
404 *
405 * @return string
406 */
407 function getKey($daoName, $fieldName, $value, $params = array()) {
408 $values = self::get($daoName, $fieldName, $params);
409 return CRM_Utils_Array::key($value, $values);
410 }
411
412 /**
413 * DEPRECATED generic populate method
414 * All pseudoconstant functions that use this method are also deprecated.
415 *
416 * The static array $var is populated from the db
417 * using the <b>$name DAO</b>.
418 *
419 * Note: any database errors will be trapped by the DAO.
420 *
421 * @param array $var the associative array we will fill
422 * @param string $name the name of the DAO
423 * @param boolean $all get all objects. default is to get only active ones.
424 * @param string $retrieve the field that we are interested in (normally name, differs in some objects)
425 * @param string $filter the field that we want to filter the result set with
426 * @param string $condition the condition that gets passed to the final query as the WHERE clause
427 *
428 * @return void
429 * @access public
430 * @static
431 */
432 public static function populate(
433 &$var,
434 $name,
435 $all = FALSE,
436 $retrieve = 'name',
437 $filter = 'is_active',
438 $condition = NULL,
439 $orderby = NULL,
440 $key = 'id',
441 $force = NULL
442 ) {
443 $cacheKey = "CRM_PC_{$name}_{$all}_{$key}_{$retrieve}_{$filter}_{$condition}_{$orderby}";
444 $cache = CRM_Utils_Cache::singleton();
445 $var = $cache->get($cacheKey);
446 if ($var && empty($force)) {
447 return $var;
448 }
449
450 $object = new $name ( );
451
452 $object->selectAdd();
453 $object->selectAdd("$key, $retrieve");
454 if ($condition) {
455 $object->whereAdd($condition);
456 }
457
458 if (!$orderby) {
459 $object->orderBy($retrieve);
460 }
461 else {
462 $object->orderBy($orderby);
463 }
464
465 if (!$all) {
466 $object->$filter = 1;
467 }
468
469 $object->find();
470 $var = array();
471 while ($object->fetch()) {
472 $var[$object->$key] = $object->$retrieve;
473 }
474
475 $cache->set($cacheKey, $var);
476 }
477
478 /**
479 * Flush given pseudoconstant so it can be reread from db
480 * nex time it's requested.
481 *
482 * @access public
483 * @static
484 *
485 * @param boolean $name pseudoconstant to be flushed
486 *
487 */
488 public static function flush($name = 'cache') {
489 if (property_exists(self, $name)) {
490 self::$$name = NULL;
491 }
492 }
493
494 /**
495 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
496 *
497 * Get all Activty types.
498 *
499 * The static array activityType is returned
500 *
501 * @param boolean $all - get All Activity types - default is to get only active ones.
502 *
503 * @access public
504 * @static
505 *
506 * @return array - array reference of all activity types.
507 */
508 public static function &activityType() {
509 $args = func_get_args();
510 $all = CRM_Utils_Array::value(0, $args, TRUE);
511 $includeCaseActivities = CRM_Utils_Array::value(1, $args, FALSE);
512 $reset = CRM_Utils_Array::value(2, $args, FALSE);
513 $returnColumn = CRM_Utils_Array::value(3, $args, 'label');
514 $includeCampaignActivities = CRM_Utils_Array::value(4, $args, FALSE);
515 $onlyComponentActivities = CRM_Utils_Array::value(5, $args, FALSE);
516 $index = (int) $all . '_' . $returnColumn . '_' . (int) $includeCaseActivities;
517 $index .= '_' . (int) $includeCampaignActivities;
518 $index .= '_' . (int) $onlyComponentActivities;
519
520 if (NULL === self::$activityType) {
521 self::$activityType = array();
522 }
523
524 if (!isset(self::$activityType[$index]) || $reset) {
525 $condition = NULL;
526 if (!$all) {
527 $condition = 'AND filter = 0';
528 }
529 $componentClause = " v.component_id IS NULL";
530 if ($onlyComponentActivities) {
531 $componentClause = " v.component_id IS NOT NULL";
532 }
533
534 $componentIds = array();
535 $compInfo = CRM_Core_Component::getEnabledComponents();
536
537 // build filter for listing activity types only if their
538 // respective components are enabled
539 foreach ($compInfo as $compName => $compObj) {
540 if ($compName == 'CiviCase') {
541 if ($includeCaseActivities) {
542 $componentIds[] = $compObj->componentID;
543 }
544 }
545 elseif ($compName == 'CiviCampaign') {
546 if ($includeCampaignActivities) {
547 $componentIds[] = $compObj->componentID;
548 }
549 }
550 else {
551 $componentIds[] = $compObj->componentID;
552 }
553 }
554
555 if (count($componentIds)) {
556 $componentIds = implode(',', $componentIds);
557 $componentClause = " ($componentClause OR v.component_id IN ($componentIds))";
558 if ($onlyComponentActivities) {
559 $componentClause = " ( v.component_id IN ($componentIds ) )";
560 }
561 }
562 $condition = $condition . ' AND ' . $componentClause;
563
564 self::$activityType[$index] = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, $condition, $returnColumn);
565 }
566 return self::$activityType[$index];
567 }
568
569 /**
570 * Get all the State/Province from database.
571 *
572 * The static array stateProvince is returned, and if it's
573 * called the first time, the <b>State Province DAO</b> is used
574 * to get all the States.
575 *
576 * Note: any database errors will be trapped by the DAO.
577 *
578 * @access public
579 * @static
580 *
581 * @param int $id - Optional id to return
582 *
583 * @return array - array reference of all State/Provinces.
584 *
585 */
586 public static function &stateProvince($id = FALSE, $limit = TRUE) {
587 if (($id && !CRM_Utils_Array::value($id, self::$stateProvince)) || !self::$stateProvince || !$id) {
588 $whereClause = FALSE;
589 $config = CRM_Core_Config::singleton();
590 if ($limit) {
591 $countryIsoCodes = self::countryIsoCode();
592 $limitCodes = $config->provinceLimit();
593 $limitIds = array();
594 foreach ($limitCodes as $code) {
595 $limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
596 }
597 if (!empty($limitIds)) {
598 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
599 }
600 else {
601 $whereClause = FALSE;
602 }
603 }
604 self::populate(self::$stateProvince, 'CRM_Core_DAO_StateProvince', TRUE, 'name', 'is_active', $whereClause);
605
606 // localise the province names if in an non-en_US locale
607 global $tsLocale;
608 if ($tsLocale != '' and $tsLocale != 'en_US') {
609 $i18n = CRM_Core_I18n::singleton();
610 $i18n->localizeArray(self::$stateProvince, array(
611 'context' => 'province',
612 ));
613 self::$stateProvince = CRM_Utils_Array::asort(self::$stateProvince);
614 }
615 }
616 if ($id) {
617 if (array_key_exists($id, self::$stateProvince)) {
618 return self::$stateProvince[$id];
619 }
620 else {
621 $result = NULL;
622 return $result;
623 }
624 }
625 return self::$stateProvince;
626 }
627
628 /**
629 * Get all the State/Province abbreviations from the database.
630 *
631 * Same as above, except gets the abbreviations instead of the names.
632 *
633 * @access public
634 * @static
635 *
636 * @param int $id - Optional id to return
637 *
638 * @return array - array reference of all State/Province abbreviations.
639 */
640 public static function &stateProvinceAbbreviation($id = FALSE, $limit = TRUE) {
641 if ($id > 1) {
642 $query = "
643 SELECT abbreviation
644 FROM civicrm_state_province
645 WHERE id = %1";
646 $params = array(
647 1 => array(
648 $id,
649 'Integer',
650 ),
651 );
652 return CRM_Core_DAO::singleValueQuery($query, $params);
653 }
654
655 if (!self::$stateProvinceAbbreviation || !$id) {
656
657 $whereClause = FALSE;
658
659 if ($limit) {
660 $config = CRM_Core_Config::singleton();
661 $countryIsoCodes = self::countryIsoCode();
662 $limitCodes = $config->provinceLimit();
663 $limitIds = array();
664 foreach ($limitCodes as $code) {
665 $tmpArray = array_keys($countryIsoCodes, $code);
666
667 if (!empty($tmpArray)) {
668 $limitIds[] = array_shift($tmpArray);
669 }
670 }
671 if (!empty($limitIds)) {
672 $whereClause = 'country_id IN (' . implode(', ', $limitIds) . ')';
673 }
674 }
675 self::populate(self::$stateProvinceAbbreviation, 'CRM_Core_DAO_StateProvince', TRUE, 'abbreviation', 'is_active', $whereClause);
676 }
677
678 if ($id) {
679 if (array_key_exists($id, self::$stateProvinceAbbreviation)) {
680 return self::$stateProvinceAbbreviation[$id];
681 }
682 else {
683 $result = NULL;
684 return $result;
685 }
686 }
687 return self::$stateProvinceAbbreviation;
688 }
689
690 /**
691 * Get all the countries from database.
692 *
693 * The static array country is returned, and if it's
694 * called the first time, the <b>Country DAO</b> is used
695 * to get all the countries.
696 *
697 * Note: any database errors will be trapped by the DAO.
698 *
699 * @access public
700 * @static
701 *
702 * @param int $id - Optional id to return
703 *
704 * @return array - array reference of all countries.
705 *
706 */
707 public static function country($id = FALSE, $applyLimit = TRUE) {
708 if (($id && !CRM_Utils_Array::value($id, self::$country)) || !self::$country || !$id) {
709
710 $config = CRM_Core_Config::singleton();
711 $limitCodes = array();
712
713 if ($applyLimit) {
714 // limit the country list to the countries specified in CIVICRM_COUNTRY_LIMIT
715 // (ensuring it's a subset of the legal values)
716 // K/P: We need to fix this, i dont think it works with new setting files
717 $limitCodes = $config->countryLimit();
718 if (!is_array($limitCodes)) {
719 $limitCodes = array(
720 $config->countryLimit => 1,
721 );
722 }
723
724 $limitCodes = array_intersect(self::countryIsoCode(), $limitCodes);
725 }
726
727 if (count($limitCodes)) {
728 $whereClause = "iso_code IN ('" . implode("', '", $limitCodes) . "')";
729 }
730 else {
731 $whereClause = NULL;
732 }
733
734 self::populate(self::$country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active', $whereClause);
735
736 // if default country is set, percolate it to the top
737 if ($config->defaultContactCountry()) {
738 $countryIsoCodes = self::countryIsoCode();
739 $defaultID = array_search($config->defaultContactCountry(), $countryIsoCodes);
740 if ($defaultID !== FALSE) {
741 $default[$defaultID] = CRM_Utils_Array::value($defaultID, self::$country);
742 self::$country = $default + self::$country;
743 }
744 }
745
746 // localise the country names if in an non-en_US locale
747 global $tsLocale;
748 if ($tsLocale != '' and $tsLocale != 'en_US') {
749 $i18n = CRM_Core_I18n::singleton();
750 $i18n->localizeArray(self::$country, array(
751 'context' => 'country',
752 ));
753 self::$country = CRM_Utils_Array::asort(self::$country);
754 }
755 }
756 if ($id) {
757 if (array_key_exists($id, self::$country)) {
758 return self::$country[$id];
759 }
760 else {
761 return CRM_Core_DAO::$_nullObject;
762 }
763 }
764 return self::$country;
765 }
766
767 /**
768 * Get all the country ISO Code abbreviations from the database.
769 *
770 * The static array countryIsoCode is returned, and if it's
771 * called the first time, the <b>Country DAO</b> is used
772 * to get all the countries' ISO codes.
773 *
774 * Note: any database errors will be trapped by the DAO.
775 *
776 * @access public
777 * @static
778 *
779 * @return array - array reference of all country ISO codes.
780 *
781 */
782 public static function &countryIsoCode($id = FALSE) {
783 if (!self::$countryIsoCode) {
784 self::populate(self::$countryIsoCode, 'CRM_Core_DAO_Country', TRUE, 'iso_code');
785 }
786 if ($id) {
787 if (array_key_exists($id, self::$countryIsoCode)) {
788 return self::$countryIsoCode[$id];
789 }
790 else {
791 return CRM_Core_DAO::$_nullObject;
792 }
793 }
794 return self::$countryIsoCode;
795 }
796
797 /**
798 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
799 *
800 * Get all groups from database
801 *
802 * The static array group is returned, and if it's
803 * called the first time, the <b>Group DAO</b> is used
804 * to get all the groups.
805 *
806 * Note: any database errors will be trapped by the DAO.
807 *
808 * @param string $groupType type of group(Access/Mailing)
809 * @param boolen $excludeHidden exclude hidden groups.
810 *
811 * @access public
812 * @static
813 *
814 * @return array - array reference of all groups.
815 *
816 */
817 public static function &allGroup($groupType = NULL, $excludeHidden = TRUE) {
818 $condition = CRM_Contact_BAO_Group::groupTypeCondition($groupType, $excludeHidden);
819
820 if (!self::$group) {
821 self::$group = array();
822 }
823
824 $groupKey = $groupType ? $groupType : 'null';
825
826 if (!isset(self::$group[$groupKey])) {
827 self::$group[$groupKey] = NULL;
828 self::populate(self::$group[$groupKey], 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition);
829 }
830 return self::$group[$groupKey];
831 }
832
833 /**
834 * Create or get groups iterator (iterates over nested groups in a
835 * logical fashion)
836 *
837 * The GroupNesting instance is returned; it's created if this is being
838 * called for the first time
839 *
840 *
841 * @access public
842 * @static
843 *
844 * @return mixed - instance of CRM_Contact_BAO_GroupNesting
845 *
846 */
847 public static function &groupIterator($styledLabels = FALSE) {
848 if (!self::$groupIterator) {
849 /*
850 When used as an object, GroupNesting implements Iterator
851 and iterates nested groups in a logical manner for us
852 */
853 self::$groupIterator = new CRM_Contact_BAO_GroupNesting($styledLabels);
854 }
855 return self::$groupIterator;
856 }
857
858 /**
859 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
860 *
861 * Get all permissioned groups from database
862 *
863 * The static array group is returned, and if it's
864 * called the first time, the <b>Group DAO</b> is used
865 * to get all the groups.
866 *
867 * Note: any database errors will be trapped by the DAO.
868 *
869 * @param string $groupType type of group(Access/Mailing)
870 * @param boolen $excludeHidden exclude hidden groups.
871
872 * @access public
873 * @static
874 *
875 * @return array - array reference of all groups.
876 *
877 */
878 public static function group($groupType = NULL, $excludeHidden = TRUE) {
879 return CRM_Core_Permission::group($groupType, $excludeHidden);
880 }
881
882 /**
883 * Get all permissioned groups from database
884 *
885 * The static array group is returned, and if it's
886 * called the first time, the <b>Group DAO</b> is used
887 * to get all the groups.
888 *
889 * Note: any database errors will be trapped by the DAO.
890 *
891 * @access public
892 * @static
893 *
894 * @return array - array reference of all groups.
895 *
896 */
897 public static function &staticGroup($onlyPublic = FALSE, $groupType = NULL, $excludeHidden = TRUE) {
898 if (!self::$staticGroup) {
899 $condition = 'saved_search_id = 0 OR saved_search_id IS NULL';
900 if ($onlyPublic) {
901 $condition .= " AND visibility != 'User and User Admin Only'";
902 }
903
904 if ($groupType) {
905 $condition .= ' AND ' . CRM_Contact_BAO_Group::groupTypeCondition($groupType);
906 }
907
908 if ($excludeHidden) {
909 $condition .= ' AND is_hidden != 1 ';
910 }
911
912 self::populate(self::$staticGroup, 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition, 'title');
913 }
914
915 return self::$staticGroup;
916 }
917
918 /**
919 * Get all Relationship Types from database.
920 *
921 * The static array group is returned, and if it's
922 * called the first time, the <b>RelationshipType DAO</b> is used
923 * to get all the relationship types.
924 *
925 * Note: any database errors will be trapped by the DAO.
926 *
927 * @param string $valueColumnName db column name/label.
928 * @param boolean $reset reset relationship types if true
929 *
930 * @access public
931 * @static
932 *
933 * @return array - array reference of all relationship types.
934 */
935 public static function &relationshipType($valueColumnName = 'label', $reset = FALSE) {
936 if (!CRM_Utils_Array::value($valueColumnName, self::$relationshipType) || $reset) {
937 self::$relationshipType[$valueColumnName] = array();
938
939 //now we have name/label columns CRM-3336
940 $column_a_b = "{$valueColumnName}_a_b";
941 $column_b_a = "{$valueColumnName}_b_a";
942
943 $relationshipTypeDAO = new CRM_Contact_DAO_RelationshipType();
944 $relationshipTypeDAO->selectAdd();
945 $relationshipTypeDAO->selectAdd("id, {$column_a_b}, {$column_b_a}, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b");
946 $relationshipTypeDAO->is_active = 1;
947 $relationshipTypeDAO->find();
948 while ($relationshipTypeDAO->fetch()) {
949
950 self::$relationshipType[$valueColumnName][$relationshipTypeDAO->id] = array(
951 $column_a_b => $relationshipTypeDAO->$column_a_b,
952 $column_b_a => $relationshipTypeDAO->$column_b_a,
953 'contact_type_a' => "$relationshipTypeDAO->contact_type_a",
954 'contact_type_b' => "$relationshipTypeDAO->contact_type_b",
955 'contact_sub_type_a' => "$relationshipTypeDAO->contact_sub_type_a",
956 'contact_sub_type_b' => "$relationshipTypeDAO->contact_sub_type_b",
957 );
958 }
959 }
960
961 return self::$relationshipType[$valueColumnName];
962 }
963
964 /**
965 * get all the ISO 4217 currency codes
966 *
967 * so far, we use this for validation only, so there's no point of putting this into the database
968 *
969 * @access public
970 *
971 * @return array - array reference of all currency codes
972 * @static
973 */
974 public static function &currencyCode() {
975 if (!self::$currencyCode) {
976 self::$currencyCode = array(
977 'AFN',
978 'ALL',
979 'DZD',
980 'USD',
981 'EUR',
982 'AOA',
983 'XCD',
984 'XCD',
985 'ARS',
986 'AMD',
987 'AWG',
988 'AUD',
989 'EUR',
990 'AZM',
991 'BSD',
992 'BHD',
993 'BDT',
994 'BBD',
995 'BYR',
996 'EUR',
997 'BZD',
998 'XOF',
999 'BMD',
1000 'INR',
1001 'BTN',
1002 'BOB',
1003 'BOV',
1004 'BAM',
1005 'BWP',
1006 'NOK',
1007 'BRL',
1008 'USD',
1009 'BND',
1010 'BGN',
1011 'XOF',
1012 'BIF',
1013 'KHR',
1014 'XAF',
1015 'CAD',
1016 'CVE',
1017 'KYD',
1018 'XAF',
1019 'XAF',
1020 'CLP',
1021 'CLF',
1022 'CNY',
1023 'AUD',
1024 'AUD',
1025 'COP',
1026 'COU',
1027 'KMF',
1028 'XAF',
1029 'CDF',
1030 'NZD',
1031 'CRC',
1032 'XOF',
1033 'HRK',
1034 'CUP',
1035 'CYP',
1036 'CZK',
1037 'DKK',
1038 'DJF',
1039 'XCD',
1040 'DOP',
1041 'USD',
1042 'EGP',
1043 'SVC',
1044 'USD',
1045 'XAF',
1046 'ERN',
1047 'EEK',
1048 'ETB',
1049 'FKP',
1050 'DKK',
1051 'FJD',
1052 'EUR',
1053 'EUR',
1054 'EUR',
1055 'XPF',
1056 'EUR',
1057 'XAF',
1058 'GMD',
1059 'GEL',
1060 'EUR',
1061 'GHC',
1062 'GIP',
1063 'EUR',
1064 'DKK',
1065 'XCD',
1066 'EUR',
1067 'USD',
1068 'GTQ',
1069 'GNF',
1070 'GWP',
1071 'XOF',
1072 'GYD',
1073 'HTG',
1074 'USD',
1075 'AUD',
1076 'EUR',
1077 'HNL',
1078 'HKD',
1079 'HUF',
1080 'ISK',
1081 'INR',
1082 'IDR',
1083 'XDR',
1084 'IRR',
1085 'IQD',
1086 'EUR',
1087 'ILS',
1088 'EUR',
1089 'JMD',
1090 'JPY',
1091 'JOD',
1092 'KZT',
1093 'KES',
1094 'AUD',
1095 'KPW',
1096 'KRW',
1097 'KWD',
1098 'KGS',
1099 'LAK',
1100 'LVL',
1101 'LBP',
1102 'ZAR',
1103 'LSL',
1104 'LRD',
1105 'LYD',
1106 'CHF',
1107 'LTL',
1108 'EUR',
1109 'MOP',
1110 'MKD',
1111 'MGA',
1112 'MWK',
1113 'MYR',
1114 'MVR',
1115 'XOF',
1116 'MTL',
1117 'USD',
1118 'EUR',
1119 'MRO',
1120 'MUR',
1121 'EUR',
1122 'MXN',
1123 'MXV',
1124 'USD',
1125 'MDL',
1126 'EUR',
1127 'MNT',
1128 'XCD',
1129 'MAD',
1130 'MZM',
1131 'MMK',
1132 'ZAR',
1133 'NAD',
1134 'AUD',
1135 'NPR',
1136 'EUR',
1137 'ANG',
1138 'XPF',
1139 'NZD',
1140 'NIO',
1141 'XOF',
1142 'NGN',
1143 'NZD',
1144 'AUD',
1145 'USD',
1146 'NOK',
1147 'OMR',
1148 'PKR',
1149 'USD',
1150 'PAB',
1151 'USD',
1152 'PGK',
1153 'PYG',
1154 'PEN',
1155 'PHP',
1156 'NZD',
1157 'PLN',
1158 'EUR',
1159 'USD',
1160 'QAR',
1161 'EUR',
1162 'ROL',
1163 'RON',
1164 'RUB',
1165 'RWF',
1166 'SHP',
1167 'XCD',
1168 'XCD',
1169 'EUR',
1170 'XCD',
1171 'WST',
1172 'EUR',
1173 'STD',
1174 'SAR',
1175 'XOF',
1176 'CSD',
1177 'EUR',
1178 'SCR',
1179 'SLL',
1180 'SGD',
1181 'SKK',
1182 'SIT',
1183 'SBD',
1184 'SOS',
1185 'ZAR',
1186 'EUR',
1187 'LKR',
1188 'SDD',
1189 'SRD',
1190 'NOK',
1191 'SZL',
1192 'SEK',
1193 'CHF',
1194 'CHW',
1195 'CHE',
1196 'SYP',
1197 'TWD',
1198 'TJS',
1199 'TZS',
1200 'THB',
1201 'USD',
1202 'XOF',
1203 'NZD',
1204 'TOP',
1205 'TTD',
1206 'TND',
1207 'TRY',
1208 'TRL',
1209 'TMM',
1210 'USD',
1211 'AUD',
1212 'UGX',
1213 'UAH',
1214 'AED',
1215 'GBP',
1216 'USD',
1217 'USS',
1218 'USN',
1219 'USD',
1220 'UYU',
1221 'UZS',
1222 'VUV',
1223 'VEB',
1224 'VND',
1225 'USD',
1226 'USD',
1227 'XPF',
1228 'MAD',
1229 'YER',
1230 'ZMK',
1231 'ZWD',
1232 'XAU',
1233 'XBA',
1234 'XBB',
1235 'XBC',
1236 'XBD',
1237 'XPD',
1238 'XPT',
1239 'XAG',
1240 'XFU',
1241 'XFO',
1242 'XTS',
1243 'XXX',
1244 );
1245 }
1246 return self::$currencyCode;
1247 }
1248
1249 /**
1250 * Get all the County from database.
1251 *
1252 * The static array county is returned, and if it's
1253 * called the first time, the <b>County DAO</b> is used
1254 * to get all the Counties.
1255 *
1256 * Note: any database errors will be trapped by the DAO.
1257 *
1258 * @access public
1259 * @static
1260 *
1261 * @param int $id - Optional id to return
1262 *
1263 * @return array - array reference of all Counties
1264 *
1265 */
1266 public static function &county($id = FALSE) {
1267 if (!self::$county) {
1268
1269 $config = CRM_Core_Config::singleton();
1270 // order by id so users who populate civicrm_county can have more control over sort by the order they load the counties
1271 self::populate(self::$county, 'CRM_Core_DAO_County', TRUE, 'name', NULL, NULL, 'id');
1272 }
1273 if ($id) {
1274 if (array_key_exists($id, self::$county)) {
1275 return self::$county[$id];
1276 }
1277 else {
1278 return CRM_Core_DAO::$_nullObject;
1279 }
1280 }
1281 return self::$county;
1282 }
1283
1284 /**
1285 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1286 * Get all active payment processors
1287 *
1288 * The static array paymentProcessor is returned
1289 *
1290 * @access public
1291 * @static
1292 *
1293 * @param boolean $all - get payment processors - default is to get only active ones.
1294 * @param boolean $test - get test payment processors
1295 *
1296 * @return array - array of all payment processors
1297 *
1298 */
1299 public static function &paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
1300 $condition = "is_test = ";
1301 $condition .= ($test) ? '1' : '0';
1302
1303 if ($additionalCond) {
1304 $condition .= " AND ( $additionalCond ) ";
1305 }
1306
1307 // CRM-7178. Make sure we only include payment processors valid in ths
1308 // domain
1309 $condition .= " AND domain_id = " . CRM_Core_Config::domainID();
1310
1311 $cacheKey = $condition . '_' . (int) $all;
1312 if (!isset(self::$paymentProcessor[$cacheKey])) {
1313 self::populate(self::$paymentProcessor[$cacheKey], 'CRM_Financial_DAO_PaymentProcessor', $all, 'name', 'is_active', $condition, 'is_default desc, name');
1314 }
1315
1316 return self::$paymentProcessor[$cacheKey];
1317 }
1318
1319 /**
1320 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1321 *
1322 * The static array paymentProcessorType is returned
1323 *
1324 * @access public
1325 * @static
1326 *
1327 * @param boolean $all - get payment processors - default is to get only active ones.
1328 *
1329 * @return array - array of all payment processor types
1330 *
1331 */
1332 public static function &paymentProcessorType($all = FALSE, $id = NULL, $return = 'title') {
1333 $cacheKey = $id . '_' .$return;
1334 if (empty(self::$paymentProcessorType[$cacheKey])) {
1335 self::populate(self::$paymentProcessorType[$cacheKey], 'CRM_Financial_DAO_PaymentProcessorType', $all, $return, 'is_active', NULL, "is_default, $return", 'id');
1336 }
1337 if ($id && CRM_Utils_Array::value($id, self::$paymentProcessorType[$cacheKey])) {
1338 return self::$paymentProcessorType[$cacheKey][$id];
1339 }
1340 return self::$paymentProcessorType[$cacheKey];
1341 }
1342
1343 /**
1344 * Get all the World Regions from Database
1345 *
1346 * @access public
1347 *
1348 * @return array - array reference of all World Regions
1349 * @static
1350 */
1351 public static function &worldRegion($id = FALSE) {
1352 if (!self::$worldRegions) {
1353 self::populate(self::$worldRegions, 'CRM_Core_DAO_Worldregion', TRUE, 'name', NULL, NULL, 'id');
1354 }
1355
1356 if ($id) {
1357 if (array_key_exists($id, self::$worldRegions)) {
1358 return self::$worldRegions[$id];
1359 }
1360 else {
1361 return CRM_Core_DAO::$_nullObject;
1362 }
1363 }
1364
1365 return self::$worldRegions;
1366 }
1367
1368 /**
1369 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1370 *
1371 * Get all Activity Statuses.
1372 *
1373 * The static array activityStatus is returned
1374 *
1375 * @access public
1376 * @static
1377 *
1378 * @return array - array reference of all activity statuses
1379 */
1380 public static function &activityStatus($column = 'label') {
1381 if (NULL === self::$activityStatus) {
1382 self::$activityStatus = array();
1383 }
1384 if (!array_key_exists($column, self::$activityStatus)) {
1385 self::$activityStatus[$column] = array();
1386
1387 self::$activityStatus[$column] = CRM_Core_OptionGroup::values('activity_status', FALSE, FALSE, FALSE, NULL, $column);
1388 }
1389
1390 return self::$activityStatus[$column];
1391 }
1392
1393 /**
1394 * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object.
1395 *
1396 * Get all Visibility levels.
1397 *
1398 * The static array visibility is returned
1399 *
1400 * @access public
1401 * @static
1402 *
1403 * @return array - array reference of all Visibility levels.
1404 *
1405 */
1406 public static function &visibility($column = 'label') {
1407 if (!isset(self::$visibility)) {
1408 self::$visibility = array( );
1409 }
1410
1411 if (!isset(self::$visibility[$column])) {
1412 self::$visibility[$column] = CRM_Core_OptionGroup::values('visibility', FALSE, FALSE, FALSE, NULL, $column);
1413 }
1414
1415 return self::$visibility[$column];
1416 }
1417
1418 public static function &stateProvinceForCountry($countryID, $field = 'name') {
1419 static $_cache = NULL;
1420
1421 $cacheKey = "{$countryID}_{$field}";
1422 if (!$_cache) {
1423 $_cache = array();
1424 }
1425
1426 if (!empty($_cache[$cacheKey])) {
1427 return $_cache[$cacheKey];
1428 }
1429
1430 $query = "
1431 SELECT civicrm_state_province.{$field} name, civicrm_state_province.id id
1432 FROM civicrm_state_province
1433 WHERE country_id = %1
1434 ORDER BY name";
1435 $params = array(
1436 1 => array(
1437 $countryID,
1438 'Integer',
1439 ),
1440 );
1441
1442 $dao = CRM_Core_DAO::executeQuery($query, $params);
1443
1444 $result = array();
1445 while ($dao->fetch()) {
1446 $result[$dao->id] = $dao->name;
1447 }
1448
1449 // localise the stateProvince names if in an non-en_US locale
1450 $config = CRM_Core_Config::singleton();
1451 global $tsLocale;
1452 if ($tsLocale != '' and $tsLocale != 'en_US') {
1453 $i18n = CRM_Core_I18n::singleton();
1454 $i18n->localizeArray($result, array(
1455 'context' => 'province',
1456 ));
1457 $result = CRM_Utils_Array::asort($result);
1458 }
1459
1460 $_cache[$cacheKey] = $result;
1461
1462 CRM_Utils_Hook::buildStateProvinceForCountry($countryID, $result);
1463
1464 return $result;
1465 }
1466
1467 public static function &countyForState($stateID) {
1468 if (is_array($stateID)) {
1469 $states = implode(", ", $stateID);
1470 $query = "
1471 SELECT civicrm_county.name name, civicrm_county.id id, civicrm_state_province.abbreviation abbreviation
1472 FROM civicrm_county
1473 LEFT JOIN civicrm_state_province ON civicrm_county.state_province_id = civicrm_state_province.id
1474 WHERE civicrm_county.state_province_id in ( $states )
1475 ORDER BY civicrm_state_province.abbreviation, civicrm_county.name";
1476
1477 $dao = CRM_Core_DAO::executeQuery($query);
1478
1479 $result = array();
1480 while ($dao->fetch()) {
1481 $result[$dao->id] = $dao->abbreviation . ': ' . $dao->name;
1482 }
1483 }
1484 else {
1485
1486 static $_cache = NULL;
1487
1488 $cacheKey = "{$stateID}_name";
1489 if (!$_cache) {
1490 $_cache = array();
1491 }
1492
1493 if (!empty($_cache[$cacheKey])) {
1494 return $_cache[$cacheKey];
1495 }
1496
1497 $query = "
1498 SELECT civicrm_county.name name, civicrm_county.id id
1499 FROM civicrm_county
1500 WHERE state_province_id = %1
1501 ORDER BY name";
1502 $params = array(
1503 1 => array(
1504 $stateID,
1505 'Integer',
1506 ),
1507 );
1508
1509 $dao = CRM_Core_DAO::executeQuery($query, $params);
1510
1511 $result = array();
1512 while ($dao->fetch()) {
1513 $result[$dao->id] = $dao->name;
1514 }
1515 }
1516
1517 return $result;
1518 }
1519
1520 /**
1521 * Given a state ID return the country ID, this allows
1522 * us to populate forms and values for downstream code
1523 *
1524 * @param $stateID int
1525 *
1526 * @return int the country id that the state belongs to
1527 * @static
1528 * @public
1529 */
1530 static function countryIDForStateID($stateID) {
1531 if (empty($stateID)) {
1532 return CRM_Core_DAO::$_nullObject;
1533 }
1534
1535 $query = "
1536 SELECT country_id
1537 FROM civicrm_state_province
1538 WHERE id = %1
1539 ";
1540 $params = array(1 => array($stateID, 'Integer'));
1541
1542 return CRM_Core_DAO::singleValueQuery($query, $params);
1543 }
1544
1545 /**
1546 * Get all types of Greetings.
1547 *
1548 * The static array of greeting is returned
1549 *
1550 * @access public
1551 * @static
1552 *
1553 * @param $filter - get All Email Greetings - default is to get only active ones.
1554 *
1555 * @return array - array reference of all greetings.
1556 *
1557 */
1558 public static function greeting($filter, $columnName = 'label') {
1559 $index = $filter['greeting_type'] . '_' . $columnName;
1560
1561 // also add contactType to the array
1562 $contactType = CRM_Utils_Array::value('contact_type', $filter);
1563 if ($contactType) {
1564 $index .= '_' . $contactType;
1565 }
1566
1567 if (NULL === self::$greeting) {
1568 self::$greeting = array();
1569 }
1570
1571 if (!CRM_Utils_Array::value($index, self::$greeting)) {
1572 $filterCondition = NULL;
1573 if ($contactType) {
1574 $filterVal = 'v.filter =';
1575 switch ($contactType) {
1576 case 'Individual':
1577 $filterVal .= "1";
1578 break;
1579
1580 case 'Household':
1581 $filterVal .= "2";
1582 break;
1583
1584 case 'Organization':
1585 $filterVal .= "3";
1586 break;
1587 }
1588 $filterCondition .= "AND (v.filter = 0 OR {$filterVal}) ";
1589 }
1590
1591 self::$greeting[$index] = CRM_Core_OptionGroup::values($filter['greeting_type'], NULL, NULL, NULL, $filterCondition, $columnName);
1592 }
1593
1594 return self::$greeting[$index];
1595 }
1596
1597 /**
1598 * Construct array of default greeting values for contact type
1599 *
1600 * @access public
1601 * @static
1602 *
1603 * @return array - array reference of default greetings.
1604 *
1605 */
1606 public static function &greetingDefaults() {
1607 if (!self::$greetingDefaults) {
1608 $defaultGreetings = array();
1609 $contactTypes = self::get('CRM_Contact_DAO_Contact', 'contact_type', array('keyColumn' => 'id', 'labelColumn' => 'name'));
1610
1611 foreach ($contactTypes as $filter => $contactType) {
1612 $filterCondition = " AND (v.filter = 0 OR v.filter = $filter) AND v.is_default = 1 ";
1613
1614 foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
1615 $tokenVal = CRM_Core_OptionGroup::values($greeting, NULL, NULL, NULL, $filterCondition, 'label');
1616 $defaultGreetings[$contactType][$greeting] = $tokenVal;
1617 }
1618 }
1619
1620 self::$greetingDefaults = $defaultGreetings;
1621 }
1622
1623 return self::$greetingDefaults;
1624 }
1625
1626 /**
1627 * Get all extensions
1628 *
1629 * The static array extensions
1630 *
1631 * FIXME: This is called by civix but not by any core code. We
1632 * should provide an API call which civix can use instead.
1633 *
1634 * @access public
1635 * @static
1636 *
1637 * @return array - array($fullyQualifiedName => $label) list of extensions
1638 */
1639 public static function &getExtensions() {
1640 if (!self::$extensions) {
1641 self::$extensions = array();
1642 $sql = '
1643 SELECT full_name, label
1644 FROM civicrm_extension
1645 WHERE is_active = 1
1646 ';
1647 $dao = CRM_Core_DAO::executeQuery($sql);
1648 while ($dao->fetch()) {
1649 self::$extensions[$dao->full_name] = $dao->label;
1650 }
1651 }
1652
1653 return self::$extensions;
1654 }
1655
1656 /**
1657 * Get all options values
1658 *
1659 * The static array option values is returned
1660 *
1661 * @access public
1662 * @static
1663 *
1664 * @param boolean $optionGroupName - get All Option Group values- default is to get only active ones.
1665 *
1666 * @return array - array reference of all Option Group Name
1667 *
1668 */
1669 public static function accountOptionValues($optionGroupName, $id = null, $condition = null) {
1670 $cacheKey = $optionGroupName . '_' . $condition;
1671 if (empty(self::$accountOptionValues[$cacheKey])) {
1672 self::$accountOptionValues[$cacheKey] = CRM_Core_OptionGroup::values($optionGroupName, false, false, false, $condition);
1673 }
1674 if ($id) {
1675 return CRM_Utils_Array::value($id, self::$accountOptionValues[$cacheKey]);
1676 }
1677
1678 return self::$accountOptionValues[$cacheKey];
1679 }
1680
1681 /**
1682 * Fetch the list of active extensions of type 'module'
1683 *
1684 * @param $fresh bool whether to forcibly reload extensions list from canonical store
1685 * @access public
1686 * @static
1687 *
1688 * @return array - array(array('prefix' => $, 'file' => $))
1689 */
1690 public static function getModuleExtensions($fresh = FALSE) {
1691 return CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles($fresh);
1692 }
1693 }
1694