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