INFRA-132 - Fix spacing of @return tag in comments
[civicrm-core.git] / CRM / Event / PseudoConstant.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
31 * @copyright CiviCRM LLC (c) 2004-2014
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 */
40 class 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 /**
83 * Event template titles
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 *
99 * @param int $id
100 * @param bool $all
101 * @param null $condition
102 *
103 * @return array
104 * array of all events if any
105 * @static
106 */
107 public static function event($id = NULL, $all = FALSE, $condition = NULL) {
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 *
136 * @param int $id
137 * @param null $cond
138 * @param string $retColumn
139 * Tells populate() whether to return 'name' (default) or 'label' values.
140 *
141 * @return array
142 * array reference of all participant statuses if any
143 * @static
144 */
145 public static function &participantStatus($id = NULL, $cond = NULL, $retColumn = 'name') {
146 if (self::$participantStatus === NULL) {
147 self::$participantStatus = array();
148 }
149
150 $index = $cond ? $cond : 'No Condition';
151 $index = "{$index}_{$retColumn}";
152 if (!CRM_Utils_Array::value($index, self::$participantStatus)) {
153 self::$participantStatus[$index] = array();
154 CRM_Core_PseudoConstant::populate(self::$participantStatus[$index],
155 'CRM_Event_DAO_ParticipantStatusType',
156 FALSE, $retColumn, 'is_active', $cond, 'weight'
157 );
158 }
159
160 if ($id) {
161 return self::$participantStatus[$index][$id];
162 }
163
164 return self::$participantStatus[$index];
165 }
166
167 public static function participantStatusClassOptions() {
168 return array(
169 'Positive' => ts('Positive'),
170 'Pending' => ts('Pending'),
171 'Waiting' => ts('Waiting'),
172 'Negative' => ts('Negative'),
173 );
174 }
175
176 /**
177 * Return a status-type-keyed array of status classes
178 *
179 * @return array
180 * of status classes, keyed by status type
181 */
182 public static function &participantStatusClass() {
183 static $statusClasses = NULL;
184
185 if ($statusClasses === NULL) {
186 self::populate($statusClasses, 'CRM_Event_DAO_ParticipantStatusType', TRUE, 'class');
187 }
188
189 return $statusClasses;
190 }
191
192 /**
193 * Get all the n participant roles
194 *
195 *
196 * @param int $id
197 * @param null $cond
198 *
199 * @return array
200 * array reference of all participant roles if any
201 * @static
202 */
203 public static function &participantRole($id = NULL, $cond = NULL) {
204 $index = $cond ? $cond : 'No Condition';
205 if (!CRM_Utils_Array::value($index, self::$participantRole)) {
206 self::$participantRole[$index] = array();
207
208 $condition = NULL;
209
210 if ($cond) {
211 $condition = "AND $cond";
212 }
213
214 self::$participantRole[$index] = CRM_Core_OptionGroup::values('participant_role', FALSE, FALSE,
215 FALSE, $condition
216 );
217 }
218
219 if ($id) {
220 return self::$participantRole[$index][$id];
221 }
222 return self::$participantRole[$index];
223 }
224
225 /**
226 * Get all the participant listings
227 *
228 *
229 * @param int $id
230 *
231 * @return array
232 * array reference of all participant listings if any
233 * @static
234 */
235 public static function &participantListing($id = NULL) {
236 if (!self::$participantListing) {
237 self::$participantListing = array();
238 self::$participantListing = CRM_Core_OptionGroup::values('participant_listing');
239 }
240
241 if ($id) {
242 return self::$participantListing[$id];
243 }
244
245 return self::$participantListing;
246 }
247
248 /**
249 * Get all event types.
250 *
251 *
252 * @param int $id
253 * @return array
254 * array reference of all event types.
255 * @static
256 */
257 public static function &eventType($id = NULL) {
258 if (!self::$eventType) {
259 self::$eventType = array();
260 self::$eventType = CRM_Core_OptionGroup::values('event_type');
261 }
262
263 if ($id) {
264 return self::$eventType[$id];
265 }
266
267 return self::$eventType;
268 }
269
270 /**
271 * Get event template titles
272 *
273 * @param int $id
274 *
275 * @return array
276 * of event id → template title pairs
277 */
278 public static function &eventTemplates($id = NULL) {
279 if (!self::$eventTemplates) {
280 CRM_Core_PseudoConstant::populate(self::$eventTemplates,
281 'CRM_Event_DAO_Event',
282 FALSE,
283 'template_title',
284 'is_active',
285 'is_template = 1'
286 );
287 }
288 if ($id) {
289 return self::$eventTemplates[$id];
290 }
291 return self::$eventTemplates;
292 }
293
294 /**
295 * Flush given pseudoconstant so it can be reread from db
296 * nex time it's requested.
297 *
298 * @static
299 *
300 * @param bool|string $name pseudoconstant to be flushed
301 */
302 public static function flush($name = 'cache') {
303 if (isset(self::$$name)) {
304 self::$$name = NULL;
305 }
306 }
307
308 /**
309 * Get all the Personal campaign pages
310 *
311 *
312 * @param int $id
313 * @return array
314 * array reference of all pcp if any
315 * @static
316 */
317 public static function &pcPage($id = NULL) {
318 if (!self::$pcPage) {
319 CRM_Core_PseudoConstant::populate(self::$pcPage,
320 'CRM_PCP_DAO_PCP',
321 FALSE, 'title'
322 );
323 }
324 if ($id) {
325 return CRM_Utils_Array::value($id, self::$pcPage);
326 }
327 return self::$pcPage;
328 }
329 }