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 | * | |
6a488035 TO |
86 | * @return array - array reference of all case statues |
87 | * @static | |
88 | */ | |
7733e5a2 | 89 | public static function caseStatus($column = 'label', $onlyActive = TRUE, $condition = NULL, $fresh = FALSE) { |
e547f744 | 90 | $cacheKey = "{$column}_" . (int) $onlyActive; |
1957e5cb | 91 | if (!$condition) { |
92 | $condition = 'AND filter = 0'; | |
93 | } | |
94 | ||
7733e5a2 | 95 | if (!isset(self::$caseStatus[$cacheKey]) || $fresh) { |
6a488035 | 96 | self::$caseStatus[$cacheKey] = CRM_Core_OptionGroup::values('case_status', |
1957e5cb | 97 | FALSE, FALSE, FALSE, $condition, |
7733e5a2 | 98 | $column, $onlyActive, $fresh |
6a488035 TO |
99 | ); |
100 | } | |
101 | ||
102 | return self::$caseStatus[$cacheKey]; | |
103 | } | |
104 | ||
105 | /** | |
106 | * Get all the redaction rules | |
107 | * | |
6a488035 | 108 | * |
745b795a EM |
109 | * @param null $filter |
110 | * | |
6a488035 TO |
111 | * @return array - array reference of all redaction rules |
112 | * @static | |
113 | */ | |
114 | ||
115 | public static function redactionRule($filter = NULL) { | |
116 | // if ( ! self::$redactionRule ) { | |
117 | self::$redactionRule = array(); | |
118 | ||
119 | if ($filter === 0) { | |
120 | $condition = " AND (v.filter = 0 OR v.filter IS NULL)"; | |
121 | } | |
122 | elseif ($filter === 1) { | |
123 | $condition = " AND v.filter = 1"; | |
124 | } | |
125 | elseif ($filter === NULL) { | |
126 | $condition = NULL; | |
127 | } | |
128 | ||
129 | self::$redactionRule = CRM_Core_OptionGroup::values('redaction_rule', TRUE, FALSE, FALSE, $condition); | |
130 | // } | |
131 | return self::$redactionRule; | |
132 | } | |
133 | ||
134 | /** | |
135 | * Get all the case type | |
136 | * | |
6a488035 | 137 | * |
4f8ccea0 EM |
138 | * @param string $column |
139 | * @param bool $onlyActive | |
140 | * | |
6a488035 TO |
141 | * @return array - array reference of all case type |
142 | * @static | |
143 | */ | |
8ffdec17 ARW |
144 | public static function caseType($column = 'title', $onlyActive = TRUE) { |
145 | if ($onlyActive) { | |
146 | $condition = " is_active = 1 "; | |
0db6c3e1 TO |
147 | } |
148 | else { | |
8ffdec17 | 149 | $condition = NULL; |
6a488035 | 150 | } |
8ffdec17 ARW |
151 | $caseType = NULL; |
152 | // FIXME: deprecated? | |
153 | CRM_Core_PseudoConstant::populate( | |
154 | $caseType, | |
155 | 'CRM_Case_DAO_CaseType', | |
156 | TRUE, | |
157 | $column, | |
158 | '', | |
159 | $condition, | |
160 | 'weight', | |
161 | 'id' | |
162 | ); | |
163 | ||
164 | return $caseType; | |
6a488035 TO |
165 | } |
166 | ||
167 | /** | |
168 | * Get all the Encounter Medium | |
169 | * | |
6a488035 | 170 | * |
4f8ccea0 EM |
171 | * @param string $column |
172 | * @param bool $onlyActive | |
173 | * | |
6a488035 TO |
174 | * @return array - array reference of all Encounter Medium. |
175 | * @static | |
176 | */ | |
177 | public static function encounterMedium($column = 'label', $onlyActive = TRUE) { | |
e547f744 | 178 | $cacheKey = "{$column}_" . (int) $onlyActive; |
6a488035 TO |
179 | if (!isset(self::$encounterMedium[$cacheKey])) { |
180 | self::$encounterMedium[$cacheKey] = CRM_Core_OptionGroup::values('encounter_medium', | |
181 | FALSE, FALSE, FALSE, NULL, | |
182 | $column, $onlyActive | |
183 | ); | |
184 | } | |
185 | ||
186 | return self::$encounterMedium[$cacheKey]; | |
187 | } | |
188 | ||
189 | /** | |
190 | * Get all Activty types for the CiviCase component | |
191 | * | |
192 | * The static array activityType is returned | |
193 | * | |
64bd5a0e TO |
194 | * @param bool $indexName |
195 | * True return activity name in array. | |
6a488035 TO |
196 | * key else activity id as array key. |
197 | * | |
4f8ccea0 EM |
198 | * @param bool $all |
199 | * | |
6a488035 TO |
200 | * @static |
201 | * | |
a953bf20 | 202 | * @return array - array reference of all activity types. |
6a488035 TO |
203 | */ |
204 | public static function &caseActivityType($indexName = TRUE, $all = FALSE) { | |
205 | $cache = (int) $indexName . '_' . (int) $all; | |
206 | ||
207 | if (!array_key_exists($cache, self::$activityTypeList)) { | |
208 | self::$activityTypeList[$cache] = array(); | |
209 | ||
210 | $query = " | |
211 | SELECT v.label as label ,v.value as value, v.name as name, v.description as description | |
212 | FROM civicrm_option_value v, | |
213 | civicrm_option_group g | |
214 | WHERE v.option_group_id = g.id | |
215 | AND g.name = 'activity_type' | |
8ef12e64 | 216 | AND v.is_active = 1 |
6a488035 TO |
217 | AND g.is_active = 1"; |
218 | ||
219 | if (!$all) { | |
220 | $componentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Component', | |
221 | 'CiviCase', | |
222 | 'id', 'name' | |
223 | ); | |
224 | $query .= " AND v.component_id = {$componentId} "; | |
225 | } | |
226 | ||
227 | $query .= " ORDER BY v.weight"; | |
228 | ||
229 | $dao = CRM_Core_DAO::executeQuery($query); | |
230 | ||
231 | $activityTypes = array(); | |
232 | while ($dao->fetch()) { | |
233 | if ($indexName) { | |
234 | $index = $dao->name; | |
235 | } | |
236 | else { | |
237 | $index = $dao->value; | |
238 | } | |
239 | $activityTypes[$index] = array(); | |
240 | $activityTypes[$index]['id'] = $dao->value; | |
241 | $activityTypes[$index]['label'] = $dao->label; | |
242 | $activityTypes[$index]['name'] = $dao->name; | |
243 | $activityTypes[$index]['description'] = $dao->description; | |
244 | } | |
245 | self::$activityTypeList[$cache] = $activityTypes; | |
246 | } | |
247 | return self::$activityTypeList[$cache]; | |
248 | } | |
249 | ||
6a488035 TO |
250 | /** |
251 | * Flush given pseudoconstant so it can be reread from db | |
3f3a3ba0 | 252 | * next time it's requested. |
6a488035 | 253 | * |
6a488035 TO |
254 | * @static |
255 | * | |
745b795a | 256 | * @param bool|string $name pseudoconstant to be flushed |
6a488035 | 257 | */ |
3f3a3ba0 | 258 | public static function flush($name = 'cache') { |
e547f744 | 259 | if (isset(self::$$name)) { |
fa56270d CW |
260 | self::$$name = NULL; |
261 | } | |
6a488035 TO |
262 | } |
263 | } |