INFRA-132 - CRM/Case - Misc
[civicrm-core.git] / CRM / Case / PseudoConstant.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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 * Get all the case statues
79 *
80 *
81 * @param string $column
82 * @param bool $onlyActive
83 * @param null $condition
84 * @param bool $fresh
85 *
86 * @return array - array reference of all case statues
87 * @static
88 */
89 public static function caseStatus($column = 'label', $onlyActive = TRUE, $condition = NULL, $fresh = FALSE) {
90 $cacheKey = "{$column}_" . (int) $onlyActive;
91 if (!$condition) {
92 $condition = 'AND filter = 0';
93 }
94
95 if (!isset(self::$caseStatus[$cacheKey]) || $fresh) {
96 self::$caseStatus[$cacheKey] = CRM_Core_OptionGroup::values('case_status',
97 FALSE, FALSE, FALSE, $condition,
98 $column, $onlyActive, $fresh
99 );
100 }
101
102 return self::$caseStatus[$cacheKey];
103 }
104
105 /**
106 * Get all the redaction rules
107 *
108 *
109 * @param null $filter
110 *
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 *
137 *
138 * @param string $column
139 * @param bool $onlyActive
140 *
141 * @return array - array reference of all case type
142 * @static
143 */
144 public static function caseType($column = 'title', $onlyActive = TRUE) {
145 if ($onlyActive) {
146 $condition = " is_active = 1 ";
147 } else {
148 $condition = NULL;
149 }
150 $caseType = NULL;
151 // FIXME: deprecated?
152 CRM_Core_PseudoConstant::populate(
153 $caseType,
154 'CRM_Case_DAO_CaseType',
155 TRUE,
156 $column,
157 '',
158 $condition,
159 'weight',
160 'id'
161 );
162
163 return $caseType;
164 }
165
166 /**
167 * Get all the Encounter Medium
168 *
169 *
170 * @param string $column
171 * @param bool $onlyActive
172 *
173 * @return array - array reference of all Encounter Medium.
174 * @static
175 */
176 public static function encounterMedium($column = 'label', $onlyActive = TRUE) {
177 $cacheKey = "{$column}_" . (int) $onlyActive;
178 if (!isset(self::$encounterMedium[$cacheKey])) {
179 self::$encounterMedium[$cacheKey] = CRM_Core_OptionGroup::values('encounter_medium',
180 FALSE, FALSE, FALSE, NULL,
181 $column, $onlyActive
182 );
183 }
184
185 return self::$encounterMedium[$cacheKey];
186 }
187
188 /**
189 * Get all Activty types for the CiviCase component
190 *
191 * The static array activityType is returned
192 *
193 * @param bool $indexName
194 * True return activity name in array.
195 * key else activity id as array key.
196 *
197 * @param bool $all
198 *
199 * @static
200 *
201 * @return array - array reference of all activity types.
202 */
203 public static function &caseActivityType($indexName = TRUE, $all = FALSE) {
204 $cache = (int) $indexName . '_' . (int) $all;
205
206 if (!array_key_exists($cache, self::$activityTypeList)) {
207 self::$activityTypeList[$cache] = array();
208
209 $query = "
210 SELECT v.label as label ,v.value as value, v.name as name, v.description as description
211 FROM civicrm_option_value v,
212 civicrm_option_group g
213 WHERE v.option_group_id = g.id
214 AND g.name = 'activity_type'
215 AND v.is_active = 1
216 AND g.is_active = 1";
217
218 if (!$all) {
219 $componentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Component',
220 'CiviCase',
221 'id', 'name'
222 );
223 $query .= " AND v.component_id = {$componentId} ";
224 }
225
226 $query .= " ORDER BY v.weight";
227
228 $dao = CRM_Core_DAO::executeQuery($query);
229
230 $activityTypes = array();
231 while ($dao->fetch()) {
232 if ($indexName) {
233 $index = $dao->name;
234 }
235 else {
236 $index = $dao->value;
237 }
238 $activityTypes[$index] = array();
239 $activityTypes[$index]['id'] = $dao->value;
240 $activityTypes[$index]['label'] = $dao->label;
241 $activityTypes[$index]['name'] = $dao->name;
242 $activityTypes[$index]['description'] = $dao->description;
243 }
244 self::$activityTypeList[$cache] = $activityTypes;
245 }
246 return self::$activityTypeList[$cache];
247 }
248
249 /**
250 * Flush given pseudoconstant so it can be reread from db
251 * next time it's requested.
252 *
253 * @static
254 *
255 * @param bool|string $name pseudoconstant to be flushed
256 */
257 public static function flush($name = 'cache') {
258 if (isset(self::$$name)) {
259 self::$$name = NULL;
260 }
261 }
262 }