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