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