Add CRM_Utils_JS::encode function
[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 * Get all the case statues.
41 *
42 *
43 * @param string $column
44 * @param bool $onlyActive
45 * @param null $condition
46 * @param bool $fresh
47 *
48 * @return array
49 * array reference of all case statues
50 */
51 public static function caseStatus($column = 'label', $onlyActive = TRUE, $condition = NULL, $fresh = FALSE) {
52 if (!$condition) {
53 $condition = 'AND filter = 0';
54 }
55
56 return CRM_Core_OptionGroup::values('case_status',
57 FALSE, FALSE, FALSE, $condition,
58 $column, $onlyActive, $fresh
59 );
60
61 }
62
63 /**
64 * Get all the redaction rules.
65 *
66 *
67 * @param null $filter
68 *
69 * @return array
70 * array reference of all redaction rules
71 */
72 public static function redactionRule($filter = NULL) {
73 $condition = NULL;
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 }
80
81 return CRM_Core_OptionGroup::values('redaction_rule', TRUE, FALSE, FALSE, $condition);
82 }
83
84 /**
85 * Get all the case type.
86 *
87 *
88 * @param string $column
89 * @param bool $onlyActive
90 *
91 * @return array
92 * array reference of all case type
93 */
94 public static function caseType($column = 'title', $onlyActive = TRUE) {
95 if ($onlyActive) {
96 $condition = " is_active = 1 ";
97 }
98 else {
99 $condition = NULL;
100 }
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;
115 }
116
117 /**
118 * Get all the Encounter Medium.
119 *
120 *
121 * @param string $column
122 * @param bool $onlyActive
123 *
124 * @return array
125 * array reference of all Encounter Medium.
126 */
127 public static function encounterMedium($column = 'label', $onlyActive = TRUE) {
128 return CRM_Core_OptionGroup::values('encounter_medium',
129 FALSE, FALSE, FALSE, NULL,
130 $column, $onlyActive
131 );
132 }
133
134 /**
135 * Get all Activity types for the CiviCase component.
136 *
137 * The static array activityType is returned
138 *
139 * @param bool $indexName
140 * True return activity name in array.
141 * key else activity id as array key.
142 *
143 * @param bool $all
144 *
145 *
146 * @return array
147 * array reference of all activity types.
148 */
149 public static function &caseActivityType($indexName = TRUE, $all = FALSE) {
150 $cache = (int) $indexName . '_' . (int) $all;
151
152 if (!isset(Civi::$statics[__CLASS__]['activityTypeList'][$cache])) {
153 Civi::$statics[__CLASS__]['activityTypeList'][$cache] = [];
154
155 $query = "
156 SELECT v.label as label ,v.value as value, v.name as name, v.description as description, v.icon
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'
161 AND v.is_active = 1
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
176 $activityTypes = [];
177 while ($dao->fetch()) {
178 if ($indexName) {
179 $index = $dao->name;
180 }
181 else {
182 $index = $dao->value;
183 }
184 $activityTypes[$index] = [];
185 $activityTypes[$index]['id'] = $dao->value;
186 $activityTypes[$index]['label'] = $dao->label;
187 $activityTypes[$index]['name'] = $dao->name;
188 $activityTypes[$index]['icon'] = $dao->icon;
189 $activityTypes[$index]['description'] = $dao->description;
190 }
191 Civi::$statics[__CLASS__]['activityTypeList'][$cache] = $activityTypes;
192 }
193 return Civi::$statics[__CLASS__]['activityTypeList'][$cache];
194 }
195
196 /**
197 * Flush given pseudoconstant so it can be reread from db
198 * next time it's requested.
199 *
200 *
201 * @param bool|string $name pseudoconstant to be flushed
202 */
203 public static function flush($name = 'cache') {
204 if (isset(self::$$name)) {
205 self::$$name = NULL;
206 }
207 }
208
209 }