INFRA-132 - CRM/Campaign - Convert single-line @param to multi-line
[civicrm-core.git] / CRM / Case / PseudoConstant.php
CommitLineData
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 */
40class CRM_Case_PseudoConstant extends CRM_Core_PseudoConstant {
41
42 /**
100fef9d 43 * Case statues
6a488035
TO
44 * @var array
45 * @static
46 */
47 static $caseStatus = array();
48
49 /**
100fef9d 50 * Redaction rules
6a488035
TO
51 * @var array
52 * @static
53 */
54 static $redactionRule;
55
56 /**
100fef9d 57 * Case type
6a488035
TO
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 /**
100fef9d 71 * Activity type
6a488035
TO
72 * @var array
73 * @static
74 */
75 static $activityTypeList = array();
76
6a488035
TO
77 /**
78 * Get all the case statues
79 *
6a488035 80 *
745b795a
EM
81 * @param string $column
82 * @param bool $onlyActive
83 * @param null $condition
84 * @param bool $fresh
85 *
6a488035
TO
86 * @return array - array reference of all case statues
87 * @static
88 */
7733e5a2 89 public static function caseStatus($column = 'label', $onlyActive = TRUE, $condition = NULL, $fresh = FALSE) {
6a488035 90 $cacheKey = "{$column}_" . (int)$onlyActive;
1957e5cb 91 if (!$condition) {
92 $condition = 'AND filter = 0';
93 }
94
7733e5a2 95 if (!isset(self::$caseStatus[$cacheKey]) || $fresh) {
6a488035 96 self::$caseStatus[$cacheKey] = CRM_Core_OptionGroup::values('case_status',
1957e5cb 97 FALSE, FALSE, FALSE, $condition,
7733e5a2 98 $column, $onlyActive, $fresh
6a488035
TO
99 );
100 }
101
102 return self::$caseStatus[$cacheKey];
103 }
104
105 /**
106 * Get all the redaction rules
107 *
6a488035 108 *
745b795a
EM
109 * @param null $filter
110 *
6a488035
TO
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 *
6a488035 137 *
4f8ccea0
EM
138 * @param string $column
139 * @param bool $onlyActive
140 *
6a488035
TO
141 * @return array - array reference of all case type
142 * @static
143 */
8ffdec17
ARW
144 public static function caseType($column = 'title', $onlyActive = TRUE) {
145 if ($onlyActive) {
146 $condition = " is_active = 1 ";
147 } else {
148 $condition = NULL;
6a488035 149 }
8ffdec17
ARW
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;
6a488035
TO
164 }
165
166 /**
167 * Get all the Encounter Medium
168 *
6a488035 169 *
4f8ccea0
EM
170 * @param string $column
171 * @param bool $onlyActive
172 *
6a488035
TO
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 boolean $indexName - true return activity name in array
194 * key else activity id as array key.
195 *
4f8ccea0
EM
196 * @param bool $all
197 *
6a488035
TO
198 * @static
199 *
a953bf20 200 * @return array - array reference of all activity types.
6a488035
TO
201 */
202 public static function &caseActivityType($indexName = TRUE, $all = FALSE) {
203 $cache = (int) $indexName . '_' . (int) $all;
204
205 if (!array_key_exists($cache, self::$activityTypeList)) {
206 self::$activityTypeList[$cache] = array();
207
208 $query = "
209 SELECT v.label as label ,v.value as value, v.name as name, v.description as description
210 FROM civicrm_option_value v,
211 civicrm_option_group g
212 WHERE v.option_group_id = g.id
213 AND g.name = 'activity_type'
8ef12e64 214 AND v.is_active = 1
6a488035
TO
215 AND g.is_active = 1";
216
217 if (!$all) {
218 $componentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Component',
219 'CiviCase',
220 'id', 'name'
221 );
222 $query .= " AND v.component_id = {$componentId} ";
223 }
224
225 $query .= " ORDER BY v.weight";
226
227 $dao = CRM_Core_DAO::executeQuery($query);
228
229 $activityTypes = array();
230 while ($dao->fetch()) {
231 if ($indexName) {
232 $index = $dao->name;
233 }
234 else {
235 $index = $dao->value;
236 }
237 $activityTypes[$index] = array();
238 $activityTypes[$index]['id'] = $dao->value;
239 $activityTypes[$index]['label'] = $dao->label;
240 $activityTypes[$index]['name'] = $dao->name;
241 $activityTypes[$index]['description'] = $dao->description;
242 }
243 self::$activityTypeList[$cache] = $activityTypes;
244 }
245 return self::$activityTypeList[$cache];
246 }
247
6a488035
TO
248 /**
249 * Flush given pseudoconstant so it can be reread from db
3f3a3ba0 250 * next time it's requested.
6a488035 251 *
6a488035
TO
252 * @static
253 *
745b795a 254 * @param bool|string $name pseudoconstant to be flushed
6a488035 255 */
3f3a3ba0 256 public static function flush($name = 'cache') {
fa56270d
CW
257 if (isset(self::$$name)) {
258 self::$$name = NULL;
259 }
6a488035
TO
260 }
261}