INFRA-132 - Spaces around "."
[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 }
148 else {
149 $condition = NULL;
150 }
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;
165 }
166
167 /**
168 * Get all the Encounter Medium
169 *
170 *
171 * @param string $column
172 * @param bool $onlyActive
173 *
174 * @return array - array reference of all Encounter Medium.
175 * @static
176 */
177 public static function encounterMedium($column = 'label', $onlyActive = TRUE) {
178 $cacheKey = "{$column}_" . (int) $onlyActive;
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 *
194 * @param bool $indexName
195 * True return activity name in array.
196 * key else activity id as array key.
197 *
198 * @param bool $all
199 *
200 * @static
201 *
202 * @return array - array reference of all activity types.
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'
216 AND v.is_active = 1
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
250 /**
251 * Flush given pseudoconstant so it can be reread from db
252 * next time it's requested.
253 *
254 * @static
255 *
256 * @param bool|string $name pseudoconstant to be flushed
257 */
258 public static function flush($name = 'cache') {
259 if (isset(self::$$name)) {
260 self::$$name = NULL;
261 }
262 }
263 }