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