Merge pull request #23956 from agh1/5.51.0-releasenotes-final
[civicrm-core.git] / CRM / Event / PseudoConstant.php
CommitLineData
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 */
22class 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 /**
3fd42bb5 73 * Get all events
6a488035 74 *
3fd42bb5 75 * @param int|null $id
77b97be7 76 * @param bool $all
3fd42bb5
BT
77 * @param string|null $condition
78 * Optional SQL where condition
77b97be7 79 *
3fd42bb5 80 * @return array|string|null
a6c01b45 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 /**
3fd42bb5 109 * Get all the event participant statuses.
6a488035 110 *
6a488035 111 *
3fd42bb5
BT
112 * @param int|null $id
113 * Return the specified participant status, or null to return all
114 * @param string|null $cond
115 * Optional SQL where condition
d4dd1e85
TO
116 * @param string $retColumn
117 * Tells populate() whether to return 'name' (default) or 'label' values.
6a488035 118 *
3fd42bb5
BT
119 * @return array|string
120 * array reference of all participant statuses if any, or single value if $id was passed
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
3fd42bb5
BT
179 * @param string|null $cond
180 * Optional SQL where condition
da6b46f4 181 *
8714579b 182 * @return array|string
a6c01b45 183 * array reference of all participant roles if any
6a488035
TO
184 */
185 public static function &participantRole($id = NULL, $cond = NULL) {
186 $index = $cond ? $cond : 'No Condition';
f3acfdd9 187 if (empty(self::$participantRole[$index])) {
be2fb01f 188 self::$participantRole[$index] = [];
6a488035
TO
189
190 $condition = NULL;
191
192 if ($cond) {
193 $condition = "AND $cond";
194 }
195
196 self::$participantRole[$index] = CRM_Core_OptionGroup::values('participant_role', FALSE, FALSE,
197 FALSE, $condition
198 );
199 }
200
201 if ($id) {
202 return self::$participantRole[$index][$id];
203 }
204 return self::$participantRole[$index];
205 }
206
207 /**
fe482240 208 * Get all the participant listings.
6a488035 209 *
8655187b 210 * @deprecated
100fef9d 211 * @param int $id
8714579b 212 * @return array|string
a6c01b45 213 * array reference of all participant listings if any
6a488035
TO
214 */
215 public static function &participantListing($id = NULL) {
8655187b 216 CRM_Core_Error::deprecatedFunctionWarning('Function participantListing will be removed');
6a488035 217 if (!self::$participantListing) {
be2fb01f 218 self::$participantListing = [];
6a488035
TO
219 self::$participantListing = CRM_Core_OptionGroup::values('participant_listing');
220 }
221
222 if ($id) {
223 return self::$participantListing[$id];
224 }
225
226 return self::$participantListing;
227 }
228
229 /**
230 * Get all event types.
231 *
6a488035 232 *
100fef9d 233 * @param int $id
8714579b 234 * @return array|string
a6c01b45 235 * array reference of all event types.
6a488035
TO
236 */
237 public static function &eventType($id = NULL) {
238 if (!self::$eventType) {
be2fb01f 239 self::$eventType = [];
6a488035
TO
240 self::$eventType = CRM_Core_OptionGroup::values('event_type');
241 }
242
243 if ($id) {
244 return self::$eventType[$id];
245 }
246
247 return self::$eventType;
248 }
249
250 /**
fe482240 251 * Get event template titles.
6a488035 252 *
100fef9d 253 * @param int $id
77b97be7 254 *
a6c01b45 255 * @return array
16b10e64 256 * Array of event id → template title pairs
6a488035
TO
257 */
258 public static function &eventTemplates($id = NULL) {
259 if (!self::$eventTemplates) {
260 CRM_Core_PseudoConstant::populate(self::$eventTemplates,
261 'CRM_Event_DAO_Event',
262 FALSE,
263 'template_title',
264 'is_active',
265 'is_template = 1'
266 );
267 }
268 if ($id) {
269 return self::$eventTemplates[$id];
270 }
271 return self::$eventTemplates;
272 }
273
274 /**
275 * Flush given pseudoconstant so it can be reread from db
3fd42bb5 276 * next time it's requested.
6a488035 277 *
6a488035 278 *
da6b46f4 279 * @param bool|string $name pseudoconstant to be flushed
6a488035 280 */
3fb36592 281 public static function flush($name = 'cache') {
0479b4c8 282 if (isset(self::$$name)) {
fa56270d 283 self::$$name = NULL;
353ffa53 284 }
6a488035
TO
285 }
286
287 /**
fe482240 288 * Get all the Personal campaign pages.
6a488035 289 *
8655187b 290 * @deprecated
100fef9d 291 * @param int $id
a6c01b45
CW
292 * @return array
293 * array reference of all pcp if any
6a488035
TO
294 */
295 public static function &pcPage($id = NULL) {
8655187b 296 CRM_Core_Error::deprecatedFunctionWarning('Function pcPage will be removed');
6a488035
TO
297 if (!self::$pcPage) {
298 CRM_Core_PseudoConstant::populate(self::$pcPage,
299 'CRM_PCP_DAO_PCP',
300 FALSE, 'title'
301 );
302 }
303 if ($id) {
914d3734 304 return self::$pcPage[$id] ?? NULL;
6a488035
TO
305 }
306 return self::$pcPage;
307 }
96025800 308
6a488035 309}