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