Merge pull request #5819 from guanhuan/batch-export
[civicrm-core.git] / CRM / Case / PseudoConstant.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
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 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 72 /**
fe482240 73 * Get all the case statues.
6a488035 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 /**
fe482240 101 * Get all the redaction rules.
6a488035 102 *
6a488035 103 *
745b795a
EM
104 * @param null $filter
105 *
a6c01b45
CW
106 * @return array
107 * array reference of all redaction rules
6a488035 108 */
6a488035
TO
109 public static function redactionRule($filter = NULL) {
110 // if ( ! self::$redactionRule ) {
111 self::$redactionRule = array();
112
113 if ($filter === 0) {
114 $condition = " AND (v.filter = 0 OR v.filter IS NULL)";
115 }
116 elseif ($filter === 1) {
117 $condition = " AND v.filter = 1";
118 }
119 elseif ($filter === NULL) {
120 $condition = NULL;
121 }
122
123 self::$redactionRule = CRM_Core_OptionGroup::values('redaction_rule', TRUE, FALSE, FALSE, $condition);
124 // }
125 return self::$redactionRule;
126 }
127
128 /**
fe482240 129 * Get all the case type.
6a488035 130 *
6a488035 131 *
4f8ccea0
EM
132 * @param string $column
133 * @param bool $onlyActive
134 *
a6c01b45
CW
135 * @return array
136 * array reference of all case type
6a488035 137 */
8ffdec17
ARW
138 public static function caseType($column = 'title', $onlyActive = TRUE) {
139 if ($onlyActive) {
140 $condition = " is_active = 1 ";
0db6c3e1
TO
141 }
142 else {
8ffdec17 143 $condition = NULL;
6a488035 144 }
8ffdec17
ARW
145 $caseType = NULL;
146 // FIXME: deprecated?
147 CRM_Core_PseudoConstant::populate(
148 $caseType,
149 'CRM_Case_DAO_CaseType',
150 TRUE,
151 $column,
152 '',
153 $condition,
154 'weight',
155 'id'
156 );
157
158 return $caseType;
6a488035
TO
159 }
160
161 /**
fe482240 162 * Get all the Encounter Medium.
6a488035 163 *
6a488035 164 *
4f8ccea0
EM
165 * @param string $column
166 * @param bool $onlyActive
167 *
a6c01b45
CW
168 * @return array
169 * array reference of all Encounter Medium.
6a488035
TO
170 */
171 public static function encounterMedium($column = 'label', $onlyActive = TRUE) {
e547f744 172 $cacheKey = "{$column}_" . (int) $onlyActive;
6a488035
TO
173 if (!isset(self::$encounterMedium[$cacheKey])) {
174 self::$encounterMedium[$cacheKey] = CRM_Core_OptionGroup::values('encounter_medium',
175 FALSE, FALSE, FALSE, NULL,
176 $column, $onlyActive
177 );
178 }
179
180 return self::$encounterMedium[$cacheKey];
181 }
182
183 /**
fe482240 184 * Get all Activity types for the CiviCase component.
6a488035
TO
185 *
186 * The static array activityType is returned
187 *
64bd5a0e
TO
188 * @param bool $indexName
189 * True return activity name in array.
16b10e64 190 * key else activity id as array key.
6a488035 191 *
4f8ccea0
EM
192 * @param bool $all
193 *
6a488035 194 *
a6c01b45
CW
195 * @return array
196 * array reference of all activity types.
6a488035
TO
197 */
198 public static function &caseActivityType($indexName = TRUE, $all = FALSE) {
199 $cache = (int) $indexName . '_' . (int) $all;
200
201 if (!array_key_exists($cache, self::$activityTypeList)) {
202 self::$activityTypeList[$cache] = array();
203
204 $query = "
205 SELECT v.label as label ,v.value as value, v.name as name, v.description as description
206 FROM civicrm_option_value v,
207 civicrm_option_group g
208 WHERE v.option_group_id = g.id
209 AND g.name = 'activity_type'
8ef12e64 210 AND v.is_active = 1
6a488035
TO
211 AND g.is_active = 1";
212
213 if (!$all) {
214 $componentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Component',
215 'CiviCase',
216 'id', 'name'
217 );
218 $query .= " AND v.component_id = {$componentId} ";
219 }
220
221 $query .= " ORDER BY v.weight";
222
223 $dao = CRM_Core_DAO::executeQuery($query);
224
225 $activityTypes = array();
226 while ($dao->fetch()) {
227 if ($indexName) {
228 $index = $dao->name;
229 }
230 else {
231 $index = $dao->value;
232 }
233 $activityTypes[$index] = array();
234 $activityTypes[$index]['id'] = $dao->value;
235 $activityTypes[$index]['label'] = $dao->label;
236 $activityTypes[$index]['name'] = $dao->name;
237 $activityTypes[$index]['description'] = $dao->description;
238 }
239 self::$activityTypeList[$cache] = $activityTypes;
240 }
241 return self::$activityTypeList[$cache];
242 }
243
6a488035
TO
244 /**
245 * Flush given pseudoconstant so it can be reread from db
3f3a3ba0 246 * next time it's requested.
6a488035 247 *
6a488035 248 *
745b795a 249 * @param bool|string $name pseudoconstant to be flushed
6a488035 250 */
3f3a3ba0 251 public static function flush($name = 'cache') {
e547f744 252 if (isset(self::$$name)) {
fa56270d
CW
253 self::$$name = NULL;
254 }
6a488035 255 }
96025800 256
6a488035 257}