Merge pull request #23689 from eileenmcnaughton/member_really_labels
[civicrm-core.git] / CRM / Case / PseudoConstant.php
CommitLineData
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 */
21class 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
3fd42bb5 29 * @param string|null $condition
745b795a
EM
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 *
5e21e0f3 50 * @param int $filter
745b795a 51 *
a6c01b45
CW
52 * @return array
53 * array reference of all redaction rules
6a488035 54 */
6a488035 55 public static function redactionRule($filter = NULL) {
d99f53e7 56 $condition = NULL;
6a488035
TO
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 }
6a488035 63
d99f53e7 64 return CRM_Core_OptionGroup::values('redaction_rule', TRUE, FALSE, FALSE, $condition);
6a488035
TO
65 }
66
67 /**
fe482240 68 * Get all the case type.
6a488035 69 *
6a488035 70 *
4f8ccea0
EM
71 * @param string $column
72 * @param bool $onlyActive
73 *
a6c01b45
CW
74 * @return array
75 * array reference of all case type
6a488035 76 */
8ffdec17
ARW
77 public static function caseType($column = 'title', $onlyActive = TRUE) {
78 if ($onlyActive) {
79 $condition = " is_active = 1 ";
0db6c3e1
TO
80 }
81 else {
8ffdec17 82 $condition = NULL;
6a488035 83 }
8ffdec17
ARW
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;
6a488035
TO
98 }
99
100 /**
fe482240 101 * Get all the Encounter Medium.
6a488035 102 *
6a488035 103 *
4f8ccea0
EM
104 * @param string $column
105 * @param bool $onlyActive
106 *
a6c01b45
CW
107 * @return array
108 * array reference of all Encounter Medium.
6a488035
TO
109 */
110 public static function encounterMedium($column = 'label', $onlyActive = TRUE) {
d99f53e7
CW
111 return CRM_Core_OptionGroup::values('encounter_medium',
112 FALSE, FALSE, FALSE, NULL,
113 $column, $onlyActive
114 );
6a488035
TO
115 }
116
117 /**
fe482240 118 * Get all Activity types for the CiviCase component.
6a488035
TO
119 *
120 * The static array activityType is returned
121 *
64bd5a0e
TO
122 * @param bool $indexName
123 * True return activity name in array.
16b10e64 124 * key else activity id as array key.
6a488035 125 *
4f8ccea0
EM
126 * @param bool $all
127 *
6a488035 128 *
a6c01b45
CW
129 * @return array
130 * array reference of all activity types.
6a488035
TO
131 */
132 public static function &caseActivityType($indexName = TRUE, $all = FALSE) {
133 $cache = (int) $indexName . '_' . (int) $all;
134
0d83522a
D
135 if (!isset(Civi::$statics[__CLASS__]['activityTypeList'][$cache])) {
136 Civi::$statics[__CLASS__]['activityTypeList'][$cache] = [];
6a488035
TO
137
138 $query = "
8c99c0bb 139 SELECT v.label as label ,v.value as value, v.name as name, v.description as description, v.icon
6a488035
TO
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'
8ef12e64 144 AND v.is_active = 1
6a488035
TO
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
be2fb01f 159 $activityTypes = [];
6a488035
TO
160 while ($dao->fetch()) {
161 if ($indexName) {
162 $index = $dao->name;
163 }
164 else {
165 $index = $dao->value;
166 }
be2fb01f 167 $activityTypes[$index] = [];
6a488035
TO
168 $activityTypes[$index]['id'] = $dao->value;
169 $activityTypes[$index]['label'] = $dao->label;
170 $activityTypes[$index]['name'] = $dao->name;
8c99c0bb 171 $activityTypes[$index]['icon'] = $dao->icon;
6a488035
TO
172 $activityTypes[$index]['description'] = $dao->description;
173 }
0d83522a 174 Civi::$statics[__CLASS__]['activityTypeList'][$cache] = $activityTypes;
6a488035 175 }
0d83522a 176 return Civi::$statics[__CLASS__]['activityTypeList'][$cache];
6a488035
TO
177 }
178
6a488035
TO
179 /**
180 * Flush given pseudoconstant so it can be reread from db
3f3a3ba0 181 * next time it's requested.
6a488035 182 *
6a488035 183 *
745b795a 184 * @param bool|string $name pseudoconstant to be flushed
6a488035 185 */
3f3a3ba0 186 public static function flush($name = 'cache') {
e547f744 187 if (isset(self::$$name)) {
fa56270d
CW
188 self::$$name = NULL;
189 }
6a488035 190 }
96025800 191
6a488035 192}