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