Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
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 | /** | |
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 | ||
6a488035 TO |
77 | /** |
78 | * Get all the case statues | |
79 | * | |
80 | * @access public | |
81 | * | |
745b795a EM |
82 | * @param string $column |
83 | * @param bool $onlyActive | |
84 | * @param null $condition | |
85 | * @param bool $fresh | |
86 | * | |
6a488035 TO |
87 | * @return array - array reference of all case statues |
88 | * @static | |
89 | */ | |
7733e5a2 | 90 | public static function caseStatus($column = 'label', $onlyActive = TRUE, $condition = NULL, $fresh = FALSE) { |
6a488035 | 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 | * | |
109 | * @access public | |
110 | * | |
745b795a EM |
111 | * @param null $filter |
112 | * | |
6a488035 TO |
113 | * @return array - array reference of all redaction rules |
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 | * | |
139 | * @access public | |
140 | * | |
4f8ccea0 EM |
141 | * @param string $column |
142 | * @param bool $onlyActive | |
143 | * | |
6a488035 TO |
144 | * @return array - array reference of all case type |
145 | * @static | |
146 | */ | |
8ffdec17 ARW |
147 | public static function caseType($column = 'title', $onlyActive = TRUE) { |
148 | if ($onlyActive) { | |
149 | $condition = " is_active = 1 "; | |
150 | } else { | |
151 | $condition = NULL; | |
6a488035 | 152 | } |
8ffdec17 ARW |
153 | $caseType = NULL; |
154 | // FIXME: deprecated? | |
155 | CRM_Core_PseudoConstant::populate( | |
156 | $caseType, | |
157 | 'CRM_Case_DAO_CaseType', | |
158 | TRUE, | |
159 | $column, | |
160 | '', | |
161 | $condition, | |
162 | 'weight', | |
163 | 'id' | |
164 | ); | |
165 | ||
166 | return $caseType; | |
6a488035 TO |
167 | } |
168 | ||
169 | /** | |
170 | * Get all the Encounter Medium | |
171 | * | |
172 | * @access public | |
173 | * | |
4f8ccea0 EM |
174 | * @param string $column |
175 | * @param bool $onlyActive | |
176 | * | |
6a488035 TO |
177 | * @return array - array reference of all Encounter Medium. |
178 | * @static | |
179 | */ | |
180 | public static function encounterMedium($column = 'label', $onlyActive = TRUE) { | |
181 | $cacheKey = "{$column}_" . (int)$onlyActive; | |
182 | if (!isset(self::$encounterMedium[$cacheKey])) { | |
183 | self::$encounterMedium[$cacheKey] = CRM_Core_OptionGroup::values('encounter_medium', | |
184 | FALSE, FALSE, FALSE, NULL, | |
185 | $column, $onlyActive | |
186 | ); | |
187 | } | |
188 | ||
189 | return self::$encounterMedium[$cacheKey]; | |
190 | } | |
191 | ||
192 | /** | |
193 | * Get all Activty types for the CiviCase component | |
194 | * | |
195 | * The static array activityType is returned | |
196 | * | |
197 | * @param boolean $indexName - true return activity name in array | |
198 | * key else activity id as array key. | |
199 | * | |
4f8ccea0 EM |
200 | * @param bool $all |
201 | * | |
6a488035 TO |
202 | * @access public |
203 | * @static | |
204 | * | |
205 | * @return array - array reference of all activty types. | |
206 | */ | |
207 | public static function &caseActivityType($indexName = TRUE, $all = FALSE) { | |
208 | $cache = (int) $indexName . '_' . (int) $all; | |
209 | ||
210 | if (!array_key_exists($cache, self::$activityTypeList)) { | |
211 | self::$activityTypeList[$cache] = array(); | |
212 | ||
213 | $query = " | |
214 | SELECT v.label as label ,v.value as value, v.name as name, v.description as description | |
215 | FROM civicrm_option_value v, | |
216 | civicrm_option_group g | |
217 | WHERE v.option_group_id = g.id | |
218 | AND g.name = 'activity_type' | |
8ef12e64 | 219 | AND v.is_active = 1 |
6a488035 TO |
220 | AND g.is_active = 1"; |
221 | ||
222 | if (!$all) { | |
223 | $componentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Component', | |
224 | 'CiviCase', | |
225 | 'id', 'name' | |
226 | ); | |
227 | $query .= " AND v.component_id = {$componentId} "; | |
228 | } | |
229 | ||
230 | $query .= " ORDER BY v.weight"; | |
231 | ||
232 | $dao = CRM_Core_DAO::executeQuery($query); | |
233 | ||
234 | $activityTypes = array(); | |
235 | while ($dao->fetch()) { | |
236 | if ($indexName) { | |
237 | $index = $dao->name; | |
238 | } | |
239 | else { | |
240 | $index = $dao->value; | |
241 | } | |
242 | $activityTypes[$index] = array(); | |
243 | $activityTypes[$index]['id'] = $dao->value; | |
244 | $activityTypes[$index]['label'] = $dao->label; | |
245 | $activityTypes[$index]['name'] = $dao->name; | |
246 | $activityTypes[$index]['description'] = $dao->description; | |
247 | } | |
248 | self::$activityTypeList[$cache] = $activityTypes; | |
249 | } | |
250 | return self::$activityTypeList[$cache]; | |
251 | } | |
252 | ||
6a488035 TO |
253 | /** |
254 | * Flush given pseudoconstant so it can be reread from db | |
3f3a3ba0 | 255 | * next time it's requested. |
6a488035 TO |
256 | * |
257 | * @access public | |
258 | * @static | |
259 | * | |
745b795a | 260 | * @param bool|string $name pseudoconstant to be flushed |
6a488035 | 261 | */ |
3f3a3ba0 | 262 | public static function flush($name = 'cache') { |
fa56270d CW |
263 | if (isset(self::$$name)) { |
264 | self::$$name = NULL; | |
265 | } | |
6a488035 TO |
266 | } |
267 | } | |
268 |