Merge pull request #19499 from eileenmcnaughton/silly_if
[civicrm-core.git] / CRM / Case / PseudoConstant.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class holds all the Pseudo constants that are specific for CiviCase.
20 */
21 class CRM_Case_PseudoConstant extends CRM_Core_PseudoConstant {
22
23 /**
24 * Get all the case statues.
25 *
26 *
27 * @param string $column
28 * @param bool $onlyActive
29 * @param null $condition
30 * @param bool $fresh
31 *
32 * @return array
33 * array reference of all case statues
34 */
35 public static function caseStatus($column = 'label', $onlyActive = TRUE, $condition = NULL, $fresh = FALSE) {
36 if (!$condition) {
37 $condition = 'AND filter = 0';
38 }
39
40 return CRM_Core_OptionGroup::values('case_status',
41 FALSE, FALSE, FALSE, $condition,
42 $column, $onlyActive, $fresh
43 );
44
45 }
46
47 /**
48 * Get all the redaction rules.
49 *
50 *
51 * @param null $filter
52 *
53 * @return array
54 * array reference of all redaction rules
55 */
56 public static function redactionRule($filter = NULL) {
57 $condition = NULL;
58 if ($filter === 0) {
59 $condition = " AND (v.filter = 0 OR v.filter IS NULL)";
60 }
61 elseif ($filter === 1) {
62 $condition = " AND v.filter = 1";
63 }
64
65 return CRM_Core_OptionGroup::values('redaction_rule', TRUE, FALSE, FALSE, $condition);
66 }
67
68 /**
69 * Get all the case type.
70 *
71 *
72 * @param string $column
73 * @param bool $onlyActive
74 *
75 * @return array
76 * array reference of all case type
77 */
78 public static function caseType($column = 'title', $onlyActive = TRUE) {
79 if ($onlyActive) {
80 $condition = " is_active = 1 ";
81 }
82 else {
83 $condition = NULL;
84 }
85 $caseType = NULL;
86 // FIXME: deprecated?
87 CRM_Core_PseudoConstant::populate(
88 $caseType,
89 'CRM_Case_DAO_CaseType',
90 TRUE,
91 $column,
92 '',
93 $condition,
94 'weight',
95 'id'
96 );
97
98 return $caseType;
99 }
100
101 /**
102 * Get all the Encounter Medium.
103 *
104 *
105 * @param string $column
106 * @param bool $onlyActive
107 *
108 * @return array
109 * array reference of all Encounter Medium.
110 */
111 public static function encounterMedium($column = 'label', $onlyActive = TRUE) {
112 return CRM_Core_OptionGroup::values('encounter_medium',
113 FALSE, FALSE, FALSE, NULL,
114 $column, $onlyActive
115 );
116 }
117
118 /**
119 * Get all Activity types for the CiviCase component.
120 *
121 * The static array activityType is returned
122 *
123 * @param bool $indexName
124 * True return activity name in array.
125 * key else activity id as array key.
126 *
127 * @param bool $all
128 *
129 *
130 * @return array
131 * array reference of all activity types.
132 */
133 public static function &caseActivityType($indexName = TRUE, $all = FALSE) {
134 $cache = (int) $indexName . '_' . (int) $all;
135
136 if (!isset(Civi::$statics[__CLASS__]['activityTypeList'][$cache])) {
137 Civi::$statics[__CLASS__]['activityTypeList'][$cache] = [];
138
139 $query = "
140 SELECT v.label as label ,v.value as value, v.name as name, v.description as description, v.icon
141 FROM civicrm_option_value v,
142 civicrm_option_group g
143 WHERE v.option_group_id = g.id
144 AND g.name = 'activity_type'
145 AND v.is_active = 1
146 AND g.is_active = 1";
147
148 if (!$all) {
149 $componentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Component',
150 'CiviCase',
151 'id', 'name'
152 );
153 $query .= " AND v.component_id = {$componentId} ";
154 }
155
156 $query .= " ORDER BY v.weight";
157
158 $dao = CRM_Core_DAO::executeQuery($query);
159
160 $activityTypes = [];
161 while ($dao->fetch()) {
162 if ($indexName) {
163 $index = $dao->name;
164 }
165 else {
166 $index = $dao->value;
167 }
168 $activityTypes[$index] = [];
169 $activityTypes[$index]['id'] = $dao->value;
170 $activityTypes[$index]['label'] = $dao->label;
171 $activityTypes[$index]['name'] = $dao->name;
172 $activityTypes[$index]['icon'] = $dao->icon;
173 $activityTypes[$index]['description'] = $dao->description;
174 }
175 Civi::$statics[__CLASS__]['activityTypeList'][$cache] = $activityTypes;
176 }
177 return Civi::$statics[__CLASS__]['activityTypeList'][$cache];
178 }
179
180 /**
181 * Flush given pseudoconstant so it can be reread from db
182 * next time it's requested.
183 *
184 *
185 * @param bool|string $name pseudoconstant to be flushed
186 */
187 public static function flush($name = 'cache') {
188 if (isset(self::$$name)) {
189 self::$$name = NULL;
190 }
191 }
192
193 }