Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
fa938177 | 31 | * @copyright CiviCRM LLC (c) 2004-2016 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
35 | * This class holds all the Pseudo constants that are specific for CiviCase. | |
6a488035 TO |
36 | */ |
37 | class CRM_Case_PseudoConstant extends CRM_Core_PseudoConstant { | |
38 | ||
39 | /** | |
100fef9d | 40 | * Case statues |
6a488035 | 41 | * @var array |
6a488035 TO |
42 | */ |
43 | static $caseStatus = array(); | |
44 | ||
45 | /** | |
100fef9d | 46 | * Redaction rules |
6a488035 | 47 | * @var array |
6a488035 TO |
48 | */ |
49 | static $redactionRule; | |
50 | ||
51 | /** | |
100fef9d | 52 | * Case type |
6a488035 | 53 | * @var array |
6a488035 TO |
54 | */ |
55 | static $caseType = array(); | |
56 | ||
57 | /** | |
58 | * Encounter Medium | |
59 | * @var array | |
6a488035 TO |
60 | */ |
61 | static $encounterMedium = array(); | |
62 | ||
63 | /** | |
100fef9d | 64 | * Activity type |
6a488035 | 65 | * @var array |
6a488035 TO |
66 | */ |
67 | static $activityTypeList = array(); | |
68 | ||
6a488035 | 69 | /** |
fe482240 | 70 | * Get all the case statues. |
6a488035 | 71 | * |
6a488035 | 72 | * |
745b795a EM |
73 | * @param string $column |
74 | * @param bool $onlyActive | |
75 | * @param null $condition | |
76 | * @param bool $fresh | |
77 | * | |
a6c01b45 CW |
78 | * @return array |
79 | * array reference of all case statues | |
6a488035 | 80 | */ |
7733e5a2 | 81 | public static function caseStatus($column = 'label', $onlyActive = TRUE, $condition = NULL, $fresh = FALSE) { |
e547f744 | 82 | $cacheKey = "{$column}_" . (int) $onlyActive; |
1957e5cb | 83 | if (!$condition) { |
84 | $condition = 'AND filter = 0'; | |
85 | } | |
86 | ||
7733e5a2 | 87 | if (!isset(self::$caseStatus[$cacheKey]) || $fresh) { |
6a488035 | 88 | self::$caseStatus[$cacheKey] = CRM_Core_OptionGroup::values('case_status', |
1957e5cb | 89 | FALSE, FALSE, FALSE, $condition, |
7733e5a2 | 90 | $column, $onlyActive, $fresh |
6a488035 TO |
91 | ); |
92 | } | |
93 | ||
94 | return self::$caseStatus[$cacheKey]; | |
95 | } | |
96 | ||
97 | /** | |
fe482240 | 98 | * Get all the redaction rules. |
6a488035 | 99 | * |
6a488035 | 100 | * |
745b795a EM |
101 | * @param null $filter |
102 | * | |
a6c01b45 CW |
103 | * @return array |
104 | * array reference of all redaction rules | |
6a488035 | 105 | */ |
6a488035 TO |
106 | public static function redactionRule($filter = NULL) { |
107 | // if ( ! self::$redactionRule ) { | |
108 | self::$redactionRule = array(); | |
109 | ||
110 | if ($filter === 0) { | |
111 | $condition = " AND (v.filter = 0 OR v.filter IS NULL)"; | |
112 | } | |
113 | elseif ($filter === 1) { | |
114 | $condition = " AND v.filter = 1"; | |
115 | } | |
116 | elseif ($filter === NULL) { | |
117 | $condition = NULL; | |
118 | } | |
119 | ||
120 | self::$redactionRule = CRM_Core_OptionGroup::values('redaction_rule', TRUE, FALSE, FALSE, $condition); | |
121 | // } | |
122 | return self::$redactionRule; | |
123 | } | |
124 | ||
125 | /** | |
fe482240 | 126 | * Get all the case type. |
6a488035 | 127 | * |
6a488035 | 128 | * |
4f8ccea0 EM |
129 | * @param string $column |
130 | * @param bool $onlyActive | |
131 | * | |
a6c01b45 CW |
132 | * @return array |
133 | * array reference of all case type | |
6a488035 | 134 | */ |
8ffdec17 ARW |
135 | public static function caseType($column = 'title', $onlyActive = TRUE) { |
136 | if ($onlyActive) { | |
137 | $condition = " is_active = 1 "; | |
0db6c3e1 TO |
138 | } |
139 | else { | |
8ffdec17 | 140 | $condition = NULL; |
6a488035 | 141 | } |
8ffdec17 ARW |
142 | $caseType = NULL; |
143 | // FIXME: deprecated? | |
144 | CRM_Core_PseudoConstant::populate( | |
145 | $caseType, | |
146 | 'CRM_Case_DAO_CaseType', | |
147 | TRUE, | |
148 | $column, | |
149 | '', | |
150 | $condition, | |
151 | 'weight', | |
152 | 'id' | |
153 | ); | |
154 | ||
155 | return $caseType; | |
6a488035 TO |
156 | } |
157 | ||
158 | /** | |
fe482240 | 159 | * Get all the Encounter Medium. |
6a488035 | 160 | * |
6a488035 | 161 | * |
4f8ccea0 EM |
162 | * @param string $column |
163 | * @param bool $onlyActive | |
164 | * | |
a6c01b45 CW |
165 | * @return array |
166 | * array reference of all Encounter Medium. | |
6a488035 TO |
167 | */ |
168 | public static function encounterMedium($column = 'label', $onlyActive = TRUE) { | |
e547f744 | 169 | $cacheKey = "{$column}_" . (int) $onlyActive; |
6a488035 TO |
170 | if (!isset(self::$encounterMedium[$cacheKey])) { |
171 | self::$encounterMedium[$cacheKey] = CRM_Core_OptionGroup::values('encounter_medium', | |
172 | FALSE, FALSE, FALSE, NULL, | |
173 | $column, $onlyActive | |
174 | ); | |
175 | } | |
176 | ||
177 | return self::$encounterMedium[$cacheKey]; | |
178 | } | |
179 | ||
180 | /** | |
fe482240 | 181 | * Get all Activity types for the CiviCase component. |
6a488035 TO |
182 | * |
183 | * The static array activityType is returned | |
184 | * | |
64bd5a0e TO |
185 | * @param bool $indexName |
186 | * True return activity name in array. | |
16b10e64 | 187 | * key else activity id as array key. |
6a488035 | 188 | * |
4f8ccea0 EM |
189 | * @param bool $all |
190 | * | |
6a488035 | 191 | * |
a6c01b45 CW |
192 | * @return array |
193 | * array reference of all activity types. | |
6a488035 TO |
194 | */ |
195 | public static function &caseActivityType($indexName = TRUE, $all = FALSE) { | |
196 | $cache = (int) $indexName . '_' . (int) $all; | |
197 | ||
198 | if (!array_key_exists($cache, self::$activityTypeList)) { | |
199 | self::$activityTypeList[$cache] = array(); | |
200 | ||
201 | $query = " | |
8c99c0bb | 202 | SELECT v.label as label ,v.value as value, v.name as name, v.description as description, v.icon |
6a488035 TO |
203 | FROM civicrm_option_value v, |
204 | civicrm_option_group g | |
205 | WHERE v.option_group_id = g.id | |
206 | AND g.name = 'activity_type' | |
8ef12e64 | 207 | AND v.is_active = 1 |
6a488035 TO |
208 | AND g.is_active = 1"; |
209 | ||
210 | if (!$all) { | |
211 | $componentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Component', | |
212 | 'CiviCase', | |
213 | 'id', 'name' | |
214 | ); | |
215 | $query .= " AND v.component_id = {$componentId} "; | |
216 | } | |
217 | ||
218 | $query .= " ORDER BY v.weight"; | |
219 | ||
220 | $dao = CRM_Core_DAO::executeQuery($query); | |
221 | ||
222 | $activityTypes = array(); | |
223 | while ($dao->fetch()) { | |
224 | if ($indexName) { | |
225 | $index = $dao->name; | |
226 | } | |
227 | else { | |
228 | $index = $dao->value; | |
229 | } | |
230 | $activityTypes[$index] = array(); | |
231 | $activityTypes[$index]['id'] = $dao->value; | |
232 | $activityTypes[$index]['label'] = $dao->label; | |
233 | $activityTypes[$index]['name'] = $dao->name; | |
8c99c0bb | 234 | $activityTypes[$index]['icon'] = $dao->icon; |
6a488035 TO |
235 | $activityTypes[$index]['description'] = $dao->description; |
236 | } | |
237 | self::$activityTypeList[$cache] = $activityTypes; | |
238 | } | |
239 | return self::$activityTypeList[$cache]; | |
240 | } | |
241 | ||
6a488035 TO |
242 | /** |
243 | * Flush given pseudoconstant so it can be reread from db | |
3f3a3ba0 | 244 | * next time it's requested. |
6a488035 | 245 | * |
6a488035 | 246 | * |
745b795a | 247 | * @param bool|string $name pseudoconstant to be flushed |
6a488035 | 248 | */ |
3f3a3ba0 | 249 | public static function flush($name = 'cache') { |
e547f744 | 250 | if (isset(self::$$name)) { |
fa56270d CW |
251 | self::$$name = NULL; |
252 | } | |
6a488035 | 253 | } |
96025800 | 254 | |
6a488035 | 255 | } |