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