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