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 | * $Id$ |
17 | * | |
18 | */ | |
19 | ||
20 | /** | |
21 | * This class holds all the Pseudo constants that are specific to Event. This avoids | |
22 | * polluting the core class and isolates the Event | |
23 | */ | |
24 | class CRM_Event_PseudoConstant extends CRM_Core_PseudoConstant { | |
25 | ||
26 | /** | |
27 | * Event | |
28 | * | |
29 | * @var array | |
6a488035 TO |
30 | */ |
31 | private static $event; | |
32 | ||
33 | /** | |
34 | * Participant Status | |
35 | * | |
36 | * @var array | |
6a488035 TO |
37 | */ |
38 | private static $participantStatus; | |
39 | ||
40 | /** | |
41 | * Participant Role | |
42 | * | |
43 | * @var array | |
6a488035 TO |
44 | */ |
45 | private static $participantRole; | |
46 | ||
47 | /** | |
48 | * Participant Listing | |
6a488035 | 49 | * @var array |
8655187b | 50 | * @deprecated |
6a488035 TO |
51 | */ |
52 | private static $participantListing; | |
53 | ||
54 | /** | |
55 | * Event Type. | |
56 | * | |
57 | * @var array | |
6a488035 TO |
58 | */ |
59 | private static $eventType; | |
60 | ||
61 | /** | |
100fef9d | 62 | * Event template titles |
6a488035 TO |
63 | * @var array |
64 | */ | |
65 | private static $eventTemplates; | |
66 | ||
67 | /** | |
68 | * Personal campaign pages | |
69 | * @var array | |
8655187b | 70 | * @deprecated |
6a488035 TO |
71 | */ |
72 | private static $pcPage; | |
73 | ||
74 | /** | |
75 | * Get all the n events | |
76 | * | |
6a488035 | 77 | * |
100fef9d | 78 | * @param int $id |
77b97be7 EM |
79 | * @param bool $all |
80 | * @param null $condition | |
81 | * | |
a6c01b45 CW |
82 | * @return array |
83 | * array of all events if any | |
6a488035 | 84 | */ |
870b4076 | 85 | public static function event($id = NULL, $all = FALSE, $condition = NULL) { |
6a488035 TO |
86 | $key = "{$id}_{$all}_{$condition}"; |
87 | ||
88 | if (!isset(self::$event[$key])) { | |
be2fb01f | 89 | self::$event[$key] = []; |
6a488035 TO |
90 | } |
91 | ||
92 | if (!self::$event[$key]) { | |
93 | CRM_Core_PseudoConstant::populate(self::$event[$key], | |
94 | 'CRM_Event_DAO_Event', | |
95 | $all, 'title', 'is_active', $condition, NULL | |
96 | ); | |
97 | } | |
98 | ||
99 | if ($id) { | |
100 | if (array_key_exists($id, self::$event[$key])) { | |
101 | return self::$event[$key][$id]; | |
102 | } | |
103 | else { | |
104 | return NULL; | |
105 | } | |
106 | } | |
107 | return self::$event[$key]; | |
108 | } | |
109 | ||
110 | /** | |
fe482240 | 111 | * Get all the n participant statuses. |
6a488035 | 112 | * |
6a488035 | 113 | * |
100fef9d | 114 | * @param int $id |
fd31fa4c | 115 | * @param null $cond |
d4dd1e85 TO |
116 | * @param string $retColumn |
117 | * Tells populate() whether to return 'name' (default) or 'label' values. | |
6a488035 | 118 | * |
a6c01b45 CW |
119 | * @return array |
120 | * array reference of all participant statuses if any | |
6a488035 TO |
121 | */ |
122 | public static function &participantStatus($id = NULL, $cond = NULL, $retColumn = 'name') { | |
123 | if (self::$participantStatus === NULL) { | |
be2fb01f | 124 | self::$participantStatus = []; |
6a488035 TO |
125 | } |
126 | ||
127 | $index = $cond ? $cond : 'No Condition'; | |
128 | $index = "{$index}_{$retColumn}"; | |
f3acfdd9 | 129 | if (empty(self::$participantStatus[$index])) { |
be2fb01f | 130 | self::$participantStatus[$index] = []; |
6a488035 TO |
131 | CRM_Core_PseudoConstant::populate(self::$participantStatus[$index], |
132 | 'CRM_Event_DAO_ParticipantStatusType', | |
133 | FALSE, $retColumn, 'is_active', $cond, 'weight' | |
134 | ); | |
135 | } | |
136 | ||
137 | if ($id) { | |
138 | return self::$participantStatus[$index][$id]; | |
139 | } | |
140 | ||
141 | return self::$participantStatus[$index]; | |
142 | } | |
143 | ||
2e2605fe EM |
144 | /** |
145 | * Get participant status class options. | |
146 | * | |
147 | * @return array | |
148 | */ | |
84403e23 | 149 | public static function participantStatusClassOptions() { |
be2fb01f | 150 | return [ |
84403e23 CW |
151 | 'Positive' => ts('Positive'), |
152 | 'Pending' => ts('Pending'), | |
153 | 'Waiting' => ts('Waiting'), | |
154 | 'Negative' => ts('Negative'), | |
be2fb01f | 155 | ]; |
84403e23 CW |
156 | } |
157 | ||
6a488035 TO |
158 | /** |
159 | * Return a status-type-keyed array of status classes | |
160 | * | |
a6c01b45 | 161 | * @return array |
16b10e64 | 162 | * Array of status classes, keyed by status type |
6a488035 | 163 | */ |
00be9182 | 164 | public static function &participantStatusClass() { |
6a488035 TO |
165 | static $statusClasses = NULL; |
166 | ||
167 | if ($statusClasses === NULL) { | |
168 | self::populate($statusClasses, 'CRM_Event_DAO_ParticipantStatusType', TRUE, 'class'); | |
169 | } | |
170 | ||
171 | return $statusClasses; | |
172 | } | |
173 | ||
174 | /** | |
fe482240 | 175 | * Get all the n participant roles. |
6a488035 | 176 | * |
6a488035 | 177 | * |
100fef9d | 178 | * @param int $id |
da6b46f4 EM |
179 | * @param null $cond |
180 | * | |
8714579b | 181 | * @return array|string |
a6c01b45 | 182 | * array reference of all participant roles if any |
6a488035 TO |
183 | */ |
184 | public static function &participantRole($id = NULL, $cond = NULL) { | |
185 | $index = $cond ? $cond : 'No Condition'; | |
f3acfdd9 | 186 | if (empty(self::$participantRole[$index])) { |
be2fb01f | 187 | self::$participantRole[$index] = []; |
6a488035 TO |
188 | |
189 | $condition = NULL; | |
190 | ||
191 | if ($cond) { | |
192 | $condition = "AND $cond"; | |
193 | } | |
194 | ||
195 | self::$participantRole[$index] = CRM_Core_OptionGroup::values('participant_role', FALSE, FALSE, | |
196 | FALSE, $condition | |
197 | ); | |
198 | } | |
199 | ||
200 | if ($id) { | |
201 | return self::$participantRole[$index][$id]; | |
202 | } | |
203 | return self::$participantRole[$index]; | |
204 | } | |
205 | ||
206 | /** | |
fe482240 | 207 | * Get all the participant listings. |
6a488035 | 208 | * |
8655187b | 209 | * @deprecated |
100fef9d | 210 | * @param int $id |
8714579b | 211 | * @return array|string |
a6c01b45 | 212 | * array reference of all participant listings if any |
6a488035 TO |
213 | */ |
214 | public static function &participantListing($id = NULL) { | |
8655187b | 215 | CRM_Core_Error::deprecatedFunctionWarning('Function participantListing will be removed'); |
6a488035 | 216 | if (!self::$participantListing) { |
be2fb01f | 217 | self::$participantListing = []; |
6a488035 TO |
218 | self::$participantListing = CRM_Core_OptionGroup::values('participant_listing'); |
219 | } | |
220 | ||
221 | if ($id) { | |
222 | return self::$participantListing[$id]; | |
223 | } | |
224 | ||
225 | return self::$participantListing; | |
226 | } | |
227 | ||
228 | /** | |
229 | * Get all event types. | |
230 | * | |
6a488035 | 231 | * |
100fef9d | 232 | * @param int $id |
8714579b | 233 | * @return array|string |
a6c01b45 | 234 | * array reference of all event types. |
6a488035 TO |
235 | */ |
236 | public static function &eventType($id = NULL) { | |
237 | if (!self::$eventType) { | |
be2fb01f | 238 | self::$eventType = []; |
6a488035 TO |
239 | self::$eventType = CRM_Core_OptionGroup::values('event_type'); |
240 | } | |
241 | ||
242 | if ($id) { | |
243 | return self::$eventType[$id]; | |
244 | } | |
245 | ||
246 | return self::$eventType; | |
247 | } | |
248 | ||
249 | /** | |
fe482240 | 250 | * Get event template titles. |
6a488035 | 251 | * |
100fef9d | 252 | * @param int $id |
77b97be7 | 253 | * |
a6c01b45 | 254 | * @return array |
16b10e64 | 255 | * Array of event id → template title pairs |
6a488035 TO |
256 | */ |
257 | public static function &eventTemplates($id = NULL) { | |
258 | if (!self::$eventTemplates) { | |
259 | CRM_Core_PseudoConstant::populate(self::$eventTemplates, | |
260 | 'CRM_Event_DAO_Event', | |
261 | FALSE, | |
262 | 'template_title', | |
263 | 'is_active', | |
264 | 'is_template = 1' | |
265 | ); | |
266 | } | |
267 | if ($id) { | |
268 | return self::$eventTemplates[$id]; | |
269 | } | |
270 | return self::$eventTemplates; | |
271 | } | |
272 | ||
273 | /** | |
274 | * Flush given pseudoconstant so it can be reread from db | |
275 | * nex time it's requested. | |
276 | * | |
6a488035 | 277 | * |
da6b46f4 | 278 | * @param bool|string $name pseudoconstant to be flushed |
6a488035 | 279 | */ |
3fb36592 | 280 | public static function flush($name = 'cache') { |
0479b4c8 | 281 | if (isset(self::$$name)) { |
fa56270d | 282 | self::$$name = NULL; |
353ffa53 | 283 | } |
6a488035 TO |
284 | } |
285 | ||
286 | /** | |
fe482240 | 287 | * Get all the Personal campaign pages. |
6a488035 | 288 | * |
8655187b | 289 | * @deprecated |
100fef9d | 290 | * @param int $id |
a6c01b45 CW |
291 | * @return array |
292 | * array reference of all pcp if any | |
6a488035 TO |
293 | */ |
294 | public static function &pcPage($id = NULL) { | |
8655187b | 295 | CRM_Core_Error::deprecatedFunctionWarning('Function pcPage will be removed'); |
6a488035 TO |
296 | if (!self::$pcPage) { |
297 | CRM_Core_PseudoConstant::populate(self::$pcPage, | |
298 | 'CRM_PCP_DAO_PCP', | |
299 | FALSE, 'title' | |
300 | ); | |
301 | } | |
302 | if ($id) { | |
914d3734 | 303 | return self::$pcPage[$id] ?? NULL; |
6a488035 TO |
304 | } |
305 | return self::$pcPage; | |
306 | } | |
96025800 | 307 | |
6a488035 | 308 | } |