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