Merge pull request #14128 from agileware/CIVICRM-1143
[civicrm-core.git] / CRM / Case / PseudoConstant.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
32 */
33
34 /**
35 * This class holds all the Pseudo constants that are specific for CiviCase.
36 */
37 class CRM_Case_PseudoConstant extends CRM_Core_PseudoConstant {
38
39 /**
40 * Activity type
41 * @var array
42 */
43 public static $activityTypeList = [];
44
45 /**
46 * Get all the case statues.
47 *
48 *
49 * @param string $column
50 * @param bool $onlyActive
51 * @param null $condition
52 * @param bool $fresh
53 *
54 * @return array
55 * array reference of all case statues
56 */
57 public static function caseStatus($column = 'label', $onlyActive = TRUE, $condition = NULL, $fresh = FALSE) {
58 if (!$condition) {
59 $condition = 'AND filter = 0';
60 }
61
62 return CRM_Core_OptionGroup::values('case_status',
63 FALSE, FALSE, FALSE, $condition,
64 $column, $onlyActive, $fresh
65 );
66
67 }
68
69 /**
70 * Get all the redaction rules.
71 *
72 *
73 * @param null $filter
74 *
75 * @return array
76 * array reference of all redaction rules
77 */
78 public static function redactionRule($filter = NULL) {
79 $condition = NULL;
80 if ($filter === 0) {
81 $condition = " AND (v.filter = 0 OR v.filter IS NULL)";
82 }
83 elseif ($filter === 1) {
84 $condition = " AND v.filter = 1";
85 }
86
87 return CRM_Core_OptionGroup::values('redaction_rule', TRUE, FALSE, FALSE, $condition);
88 }
89
90 /**
91 * Get all the case type.
92 *
93 *
94 * @param string $column
95 * @param bool $onlyActive
96 *
97 * @return array
98 * array reference of all case type
99 */
100 public static function caseType($column = 'title', $onlyActive = TRUE) {
101 if ($onlyActive) {
102 $condition = " is_active = 1 ";
103 }
104 else {
105 $condition = NULL;
106 }
107 $caseType = NULL;
108 // FIXME: deprecated?
109 CRM_Core_PseudoConstant::populate(
110 $caseType,
111 'CRM_Case_DAO_CaseType',
112 TRUE,
113 $column,
114 '',
115 $condition,
116 'weight',
117 'id'
118 );
119
120 return $caseType;
121 }
122
123 /**
124 * Get all the Encounter Medium.
125 *
126 *
127 * @param string $column
128 * @param bool $onlyActive
129 *
130 * @return array
131 * array reference of all Encounter Medium.
132 */
133 public static function encounterMedium($column = 'label', $onlyActive = TRUE) {
134 return CRM_Core_OptionGroup::values('encounter_medium',
135 FALSE, FALSE, FALSE, NULL,
136 $column, $onlyActive
137 );
138 }
139
140 /**
141 * Get all Activity types for the CiviCase component.
142 *
143 * The static array activityType is returned
144 *
145 * @param bool $indexName
146 * True return activity name in array.
147 * key else activity id as array key.
148 *
149 * @param bool $all
150 *
151 *
152 * @return array
153 * array reference of all activity types.
154 */
155 public static function &caseActivityType($indexName = TRUE, $all = FALSE) {
156 $cache = (int) $indexName . '_' . (int) $all;
157
158 if (!array_key_exists($cache, self::$activityTypeList)) {
159 self::$activityTypeList[$cache] = [];
160
161 $query = "
162 SELECT v.label as label ,v.value as value, v.name as name, v.description as description, v.icon
163 FROM civicrm_option_value v,
164 civicrm_option_group g
165 WHERE v.option_group_id = g.id
166 AND g.name = 'activity_type'
167 AND v.is_active = 1
168 AND g.is_active = 1";
169
170 if (!$all) {
171 $componentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Component',
172 'CiviCase',
173 'id', 'name'
174 );
175 $query .= " AND v.component_id = {$componentId} ";
176 }
177
178 $query .= " ORDER BY v.weight";
179
180 $dao = CRM_Core_DAO::executeQuery($query);
181
182 $activityTypes = [];
183 while ($dao->fetch()) {
184 if ($indexName) {
185 $index = $dao->name;
186 }
187 else {
188 $index = $dao->value;
189 }
190 $activityTypes[$index] = [];
191 $activityTypes[$index]['id'] = $dao->value;
192 $activityTypes[$index]['label'] = $dao->label;
193 $activityTypes[$index]['name'] = $dao->name;
194 $activityTypes[$index]['icon'] = $dao->icon;
195 $activityTypes[$index]['description'] = $dao->description;
196 }
197 self::$activityTypeList[$cache] = $activityTypes;
198 }
199 return self::$activityTypeList[$cache];
200 }
201
202 /**
203 * Flush given pseudoconstant so it can be reread from db
204 * next time it's requested.
205 *
206 *
207 * @param bool|string $name pseudoconstant to be flushed
208 */
209 public static function flush($name = 'cache') {
210 if (isset(self::$$name)) {
211 self::$$name = NULL;
212 }
213 }
214
215 }