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