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