Merge pull request #24192 from demeritcowboy/php81-frontend4
[civicrm-core.git] / CRM / Case / PseudoConstant.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class holds all the Pseudo constants that are specific for CiviCase.
20 */
21 class CRM_Case_PseudoConstant extends CRM_Core_PseudoConstant {
22
23 /**
24 * Get all the case statues.
25 *
26 *
27 * @param string $column
28 * @param bool $onlyActive
29 * @param string|null $condition
30 * @param bool $fresh
31 *
32 * @return array
33 * array reference of all case statues
34 */
35 public static function caseStatus($column = 'label', $onlyActive = TRUE, $condition = NULL, $fresh = FALSE) {
36 if (!$condition) {
37 $condition = 'AND filter = 0';
38 }
39
40 return CRM_Core_OptionGroup::values('case_status',
41 FALSE, FALSE, FALSE, $condition,
42 $column, $onlyActive, $fresh
43 );
44
45 }
46
47 /**
48 * Get all the redaction rules.
49 *
50 * @param int $filter
51 *
52 * @return array
53 * array reference of all redaction rules
54 */
55 public static function redactionRule($filter = NULL) {
56 $condition = NULL;
57 if ($filter === 0) {
58 $condition = " AND (v.filter = 0 OR v.filter IS NULL)";
59 }
60 elseif ($filter === 1) {
61 $condition = " AND v.filter = 1";
62 }
63
64 return CRM_Core_OptionGroup::values('redaction_rule', TRUE, FALSE, FALSE, $condition);
65 }
66
67 /**
68 * Get all the case type.
69 *
70 *
71 * @param string $column
72 * @param bool $onlyActive
73 *
74 * @return array
75 * array reference of all case type
76 */
77 public static function caseType($column = 'title', $onlyActive = TRUE) {
78 if ($onlyActive) {
79 $condition = " is_active = 1 ";
80 }
81 else {
82 $condition = NULL;
83 }
84 $caseType = NULL;
85 // FIXME: deprecated?
86 CRM_Core_PseudoConstant::populate(
87 $caseType,
88 'CRM_Case_DAO_CaseType',
89 TRUE,
90 $column,
91 '',
92 $condition,
93 'weight',
94 'id'
95 );
96
97 return $caseType;
98 }
99
100 /**
101 * Get all the Encounter Medium.
102 *
103 *
104 * @param string $column
105 * @param bool $onlyActive
106 *
107 * @return array
108 * array reference of all Encounter Medium.
109 */
110 public static function encounterMedium($column = 'label', $onlyActive = TRUE) {
111 return CRM_Core_OptionGroup::values('encounter_medium',
112 FALSE, FALSE, FALSE, NULL,
113 $column, $onlyActive
114 );
115 }
116
117 /**
118 * Get all Activity types for the CiviCase component.
119 *
120 * The static array activityType is returned
121 *
122 * @param bool $indexName
123 * True return activity name in array.
124 * key else activity id as array key.
125 *
126 * @param bool $all
127 *
128 *
129 * @return array
130 * array reference of all activity types.
131 */
132 public static function &caseActivityType($indexName = TRUE, $all = FALSE) {
133 $cache = (int) $indexName . '_' . (int) $all;
134
135 if (!isset(Civi::$statics[__CLASS__]['activityTypeList'][$cache])) {
136 Civi::$statics[__CLASS__]['activityTypeList'][$cache] = [];
137
138 $query = "
139 SELECT v.label as label ,v.value as value, v.name as name, v.description as description, v.icon
140 FROM civicrm_option_value v,
141 civicrm_option_group g
142 WHERE v.option_group_id = g.id
143 AND g.name = 'activity_type'
144 AND v.is_active = 1
145 AND g.is_active = 1";
146
147 if (!$all) {
148 $componentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Component',
149 'CiviCase',
150 'id', 'name'
151 );
152 $query .= " AND v.component_id = {$componentId} ";
153 }
154
155 $query .= " ORDER BY v.weight";
156
157 $dao = CRM_Core_DAO::executeQuery($query);
158
159 $activityTypes = [];
160 while ($dao->fetch()) {
161 if ($indexName) {
162 $index = $dao->name;
163 }
164 else {
165 $index = $dao->value;
166 }
167 $activityTypes[$index] = [];
168 $activityTypes[$index]['id'] = $dao->value;
169 $activityTypes[$index]['label'] = $dao->label;
170 $activityTypes[$index]['name'] = $dao->name;
171 $activityTypes[$index]['icon'] = $dao->icon;
172 $activityTypes[$index]['description'] = $dao->description;
173 }
174 Civi::$statics[__CLASS__]['activityTypeList'][$cache] = $activityTypes;
175 }
176 return Civi::$statics[__CLASS__]['activityTypeList'][$cache];
177 }
178
179 /**
180 * Flush given pseudoconstant so it can be reread from db
181 * next time it's requested.
182 *
183 *
184 * @param bool|string $name pseudoconstant to be flushed
185 */
186 public static function flush($name = 'cache') {
187 if (isset(self::$$name)) {
188 self::$$name = NULL;
189 }
190 }
191
192 }