fda9f63e8c362212b6b5808082028f334e3920e7
[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 - array of all events if any
104 * @static
105 */
106 public static function event($id = NULL, $all = FALSE, $condition = NULL) {
107 $key = "{$id}_{$all}_{$condition}";
108
109 if (!isset(self::$event[$key])) {
110 self::$event[$key] = array();
111 }
112
113 if (!self::$event[$key]) {
114 CRM_Core_PseudoConstant::populate(self::$event[$key],
115 'CRM_Event_DAO_Event',
116 $all, 'title', 'is_active', $condition, NULL
117 );
118 }
119
120 if ($id) {
121 if (array_key_exists($id, self::$event[$key])) {
122 return self::$event[$key][$id];
123 }
124 else {
125 return NULL;
126 }
127 }
128 return self::$event[$key];
129 }
130
131 /**
132 * Get all the n participant statuses
133 *
134 *
135 * @param int $id
136 * @param null $cond
137 * @param string $retColumn
138 * Tells populate() whether to return 'name' (default) or 'label' values.
139 *
140 * @return array - array reference of all participant statuses if any
141 * @static
142 */
143 public static function &participantStatus($id = NULL, $cond = NULL, $retColumn = 'name') {
144 if (self::$participantStatus === NULL) {
145 self::$participantStatus = array();
146 }
147
148 $index = $cond ? $cond : 'No Condition';
149 $index = "{$index}_{$retColumn}";
150 if (!CRM_Utils_Array::value($index, self::$participantStatus)) {
151 self::$participantStatus[$index] = array();
152 CRM_Core_PseudoConstant::populate(self::$participantStatus[$index],
153 'CRM_Event_DAO_ParticipantStatusType',
154 FALSE, $retColumn, 'is_active', $cond, 'weight'
155 );
156 }
157
158 if ($id) {
159 return self::$participantStatus[$index][$id];
160 }
161
162 return self::$participantStatus[$index];
163 }
164
165 public static function participantStatusClassOptions() {
166 return array(
167 'Positive' => ts('Positive'),
168 'Pending' => ts('Pending'),
169 'Waiting' => ts('Waiting'),
170 'Negative' => ts('Negative'),
171 );
172 }
173
174 /**
175 * Return a status-type-keyed array of status classes
176 *
177 * @return array of status classes, keyed by status type
178 */
179 public static function &participantStatusClass() {
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 /**
190 * Get all the n participant roles
191 *
192 *
193 * @param int $id
194 * @param null $cond
195 *
196 * @return array - array reference of all participant roles if any
197 * @static
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 /**
222 * Get all the participant listings
223 *
224 *
225 * @param int $id
226 *
227 * @return array - array reference of all participant listings if any
228 * @static
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 *
246 *
247 * @param int $id
248 * @return array - array reference of all event types.
249 * @static
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 /**
265 * Get event template titles
266 *
267 * @param int $id
268 *
269 * @return array of event id → template title pairs
270 */
271 public static function &eventTemplates($id = NULL) {
272 if (!self::$eventTemplates) {
273 CRM_Core_PseudoConstant::populate(self::$eventTemplates,
274 'CRM_Event_DAO_Event',
275 FALSE,
276 'template_title',
277 'is_active',
278 'is_template = 1'
279 );
280 }
281 if ($id) {
282 return self::$eventTemplates[$id];
283 }
284 return self::$eventTemplates;
285 }
286
287 /**
288 * Flush given pseudoconstant so it can be reread from db
289 * nex time it's requested.
290 *
291 * @static
292 *
293 * @param bool|string $name pseudoconstant to be flushed
294 */
295 public static function flush($name = 'cache') {
296 if (isset(self::$$name)) {
297 self::$$name = NULL;
298 }
299 }
300
301 /**
302 * Get all the Personal campaign pages
303 *
304 *
305 * @param int $id
306 * @return array - array reference of all pcp if any
307 * @static
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 }
321 }