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