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