Commit | Line | Data |
---|---|---|
6a488035 TO |
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 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
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 | /** | |
43 | * case statues | |
44 | * @var array | |
45 | * @static | |
46 | */ | |
47 | static $caseStatus = array(); | |
48 | ||
49 | /** | |
50 | * redaction rules | |
51 | * @var array | |
52 | * @static | |
53 | */ | |
54 | static $redactionRule; | |
55 | ||
56 | /** | |
57 | * case type | |
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 | /** | |
71 | * activity type | |
72 | * @var array | |
73 | * @static | |
74 | */ | |
75 | static $activityTypeList = array(); | |
76 | ||
77 | /** | |
78 | * case type | |
79 | * @var array | |
80 | * @static | |
81 | */ | |
82 | static $caseTypePair = array(); | |
83 | ||
84 | /** | |
85 | * Get all the case statues | |
86 | * | |
87 | * @access public | |
88 | * | |
89 | * @return array - array reference of all case statues | |
90 | * @static | |
91 | */ | |
92 | public static function caseStatus($column = 'label', $onlyActive = TRUE) { | |
93 | $cacheKey = "{$column}_" . (int)$onlyActive; | |
94 | if (!isset(self::$caseStatus[$cacheKey])) { | |
95 | self::$caseStatus[$cacheKey] = CRM_Core_OptionGroup::values('case_status', | |
96 | FALSE, FALSE, FALSE, NULL, | |
97 | $column, $onlyActive | |
98 | ); | |
99 | } | |
100 | ||
101 | return self::$caseStatus[$cacheKey]; | |
102 | } | |
103 | ||
104 | /** | |
105 | * Get all the redaction rules | |
106 | * | |
107 | * @access public | |
108 | * | |
109 | * @return array - array reference of all redaction rules | |
110 | * @static | |
111 | */ | |
112 | ||
113 | public static function redactionRule($filter = NULL) { | |
114 | // if ( ! self::$redactionRule ) { | |
115 | self::$redactionRule = array(); | |
116 | ||
117 | if ($filter === 0) { | |
118 | $condition = " AND (v.filter = 0 OR v.filter IS NULL)"; | |
119 | } | |
120 | elseif ($filter === 1) { | |
121 | $condition = " AND v.filter = 1"; | |
122 | } | |
123 | elseif ($filter === NULL) { | |
124 | $condition = NULL; | |
125 | } | |
126 | ||
127 | self::$redactionRule = CRM_Core_OptionGroup::values('redaction_rule', TRUE, FALSE, FALSE, $condition); | |
128 | // } | |
129 | return self::$redactionRule; | |
130 | } | |
131 | ||
132 | /** | |
133 | * Get all the case type | |
134 | * | |
135 | * @access public | |
136 | * | |
137 | * @return array - array reference of all case type | |
138 | * @static | |
139 | */ | |
140 | public static function caseType($column = 'label', $onlyActive = TRUE) { | |
141 | $cacheKey = "{$column}_" . (int)$onlyActive; | |
142 | if (!isset(self::$caseType[$cacheKey])) { | |
143 | self::$caseType[$cacheKey] = CRM_Core_OptionGroup::values('case_type', | |
144 | FALSE, FALSE, FALSE, NULL, | |
145 | $column, $onlyActive | |
146 | ); | |
147 | } | |
148 | ||
149 | return self::$caseType[$cacheKey]; | |
150 | } | |
151 | ||
152 | /** | |
153 | * Get all the Encounter Medium | |
154 | * | |
155 | * @access public | |
156 | * | |
157 | * @return array - array reference of all Encounter Medium. | |
158 | * @static | |
159 | */ | |
160 | public static function encounterMedium($column = 'label', $onlyActive = TRUE) { | |
161 | $cacheKey = "{$column}_" . (int)$onlyActive; | |
162 | if (!isset(self::$encounterMedium[$cacheKey])) { | |
163 | self::$encounterMedium[$cacheKey] = CRM_Core_OptionGroup::values('encounter_medium', | |
164 | FALSE, FALSE, FALSE, NULL, | |
165 | $column, $onlyActive | |
166 | ); | |
167 | } | |
168 | ||
169 | return self::$encounterMedium[$cacheKey]; | |
170 | } | |
171 | ||
172 | /** | |
173 | * Get all Activty types for the CiviCase component | |
174 | * | |
175 | * The static array activityType is returned | |
176 | * | |
177 | * @param boolean $indexName - true return activity name in array | |
178 | * key else activity id as array key. | |
179 | * | |
180 | * @access public | |
181 | * @static | |
182 | * | |
183 | * @return array - array reference of all activty types. | |
184 | */ | |
185 | public static function &caseActivityType($indexName = TRUE, $all = FALSE) { | |
186 | $cache = (int) $indexName . '_' . (int) $all; | |
187 | ||
188 | if (!array_key_exists($cache, self::$activityTypeList)) { | |
189 | self::$activityTypeList[$cache] = array(); | |
190 | ||
191 | $query = " | |
192 | SELECT v.label as label ,v.value as value, v.name as name, v.description as description | |
193 | FROM civicrm_option_value v, | |
194 | civicrm_option_group g | |
195 | WHERE v.option_group_id = g.id | |
196 | AND g.name = 'activity_type' | |
197 | AND v.is_active = 1 | |
198 | AND g.is_active = 1"; | |
199 | ||
200 | if (!$all) { | |
201 | $componentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Component', | |
202 | 'CiviCase', | |
203 | 'id', 'name' | |
204 | ); | |
205 | $query .= " AND v.component_id = {$componentId} "; | |
206 | } | |
207 | ||
208 | $query .= " ORDER BY v.weight"; | |
209 | ||
210 | $dao = CRM_Core_DAO::executeQuery($query); | |
211 | ||
212 | $activityTypes = array(); | |
213 | while ($dao->fetch()) { | |
214 | if ($indexName) { | |
215 | $index = $dao->name; | |
216 | } | |
217 | else { | |
218 | $index = $dao->value; | |
219 | } | |
220 | $activityTypes[$index] = array(); | |
221 | $activityTypes[$index]['id'] = $dao->value; | |
222 | $activityTypes[$index]['label'] = $dao->label; | |
223 | $activityTypes[$index]['name'] = $dao->name; | |
224 | $activityTypes[$index]['description'] = $dao->description; | |
225 | } | |
226 | self::$activityTypeList[$cache] = $activityTypes; | |
227 | } | |
228 | return self::$activityTypeList[$cache]; | |
229 | } | |
230 | ||
231 | /** | |
232 | * Get the associated case type name/id, given a case Id | |
233 | * | |
234 | * @access public | |
235 | * | |
236 | * @return array - array reference of all case type name/id | |
237 | * @static | |
238 | */ | |
239 | public static function caseTypeName($caseId, $column = 'name') { | |
240 | if (!$caseId) { | |
241 | return FALSE; | |
242 | } | |
243 | ||
244 | if (!array_key_exists($caseId, self::$caseTypePair) || empty(self::$caseTypePair[$caseId][$column])) { | |
245 | $caseTypes = self::caseType($column); | |
246 | $caseTypeIds = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', | |
247 | $caseId, | |
248 | 'case_type_id' | |
249 | ); | |
250 | $caseTypeId = explode(CRM_Core_DAO::VALUE_SEPARATOR, | |
251 | trim($caseTypeIds, | |
252 | CRM_Core_DAO::VALUE_SEPARATOR | |
253 | ) | |
254 | ); | |
255 | $caseTypeId = $caseTypeId[0]; | |
256 | ||
257 | self::$caseTypePair[$caseId][$column] = array( | |
258 | 'id' => $caseTypeId, | |
259 | 'name' => $caseTypes[$caseTypeId], | |
260 | ); | |
261 | } | |
262 | ||
263 | return self::$caseTypePair[$caseId][$column]; | |
264 | } | |
265 | ||
266 | /** | |
267 | * Flush given pseudoconstant so it can be reread from db | |
268 | * nex time it's requested. | |
269 | * | |
270 | * @access public | |
271 | * @static | |
272 | * | |
273 | * @param boolean $name pseudoconstant to be flushed | |
274 | * | |
275 | */ | |
276 | public static function flush($name) { | |
fa56270d CW |
277 | if (isset(self::$$name)) { |
278 | self::$$name = NULL; | |
279 | } | |
6a488035 TO |
280 | } |
281 | } | |
282 |