Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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-2013 | |
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 | * | |
100 | * @return array - array reference of all events if any | |
101 | * @static | |
102 | */ | |
103 | public static function &event($id = NULL, $all = FALSE, $condition = NULL) { | |
104 | $key = "{$id}_{$all}_{$condition}"; | |
105 | ||
106 | if (!isset(self::$event[$key])) { | |
107 | self::$event[$key] = array(); | |
108 | } | |
109 | ||
110 | if (!self::$event[$key]) { | |
111 | CRM_Core_PseudoConstant::populate(self::$event[$key], | |
112 | 'CRM_Event_DAO_Event', | |
113 | $all, 'title', 'is_active', $condition, NULL | |
114 | ); | |
115 | } | |
116 | ||
117 | if ($id) { | |
118 | if (array_key_exists($id, self::$event[$key])) { | |
119 | return self::$event[$key][$id]; | |
120 | } | |
121 | else { | |
122 | return NULL; | |
123 | } | |
124 | } | |
125 | return self::$event[$key]; | |
126 | } | |
127 | ||
128 | /** | |
129 | * Get all the n participant statuses | |
130 | * | |
131 | * @access public | |
132 | * | |
133 | * @param string - $retColumn tells populate() whether to return 'name' (default) or 'label' values | |
134 | * | |
135 | * @return array - array reference of all participant statuses if any | |
136 | * @static | |
137 | */ | |
138 | public static function &participantStatus($id = NULL, $cond = NULL, $retColumn = 'name') { | |
139 | if (self::$participantStatus === NULL) { | |
140 | self::$participantStatus = array(); | |
141 | } | |
142 | ||
143 | $index = $cond ? $cond : 'No Condition'; | |
144 | $index = "{$index}_{$retColumn}"; | |
145 | if (!CRM_Utils_Array::value($index, self::$participantStatus)) { | |
146 | self::$participantStatus[$index] = array(); | |
147 | CRM_Core_PseudoConstant::populate(self::$participantStatus[$index], | |
148 | 'CRM_Event_DAO_ParticipantStatusType', | |
149 | FALSE, $retColumn, 'is_active', $cond, 'weight' | |
150 | ); | |
151 | } | |
152 | ||
153 | if ($id) { | |
154 | return self::$participantStatus[$index][$id]; | |
155 | } | |
156 | ||
157 | return self::$participantStatus[$index]; | |
158 | } | |
159 | ||
160 | /** | |
161 | * Return a status-type-keyed array of status classes | |
162 | * | |
163 | * @return array of status classes, keyed by status type | |
164 | */ | |
165 | static function &participantStatusClass() { | |
166 | static $statusClasses = NULL; | |
167 | ||
168 | if ($statusClasses === NULL) { | |
169 | self::populate($statusClasses, 'CRM_Event_DAO_ParticipantStatusType', TRUE, 'class'); | |
170 | } | |
171 | ||
172 | return $statusClasses; | |
173 | } | |
174 | ||
175 | /** | |
176 | * Get all the n participant roles | |
177 | * | |
178 | * @access public | |
179 | * | |
180 | * @return array - array reference of all participant roles if any | |
181 | * @static | |
182 | */ | |
183 | public static function &participantRole($id = NULL, $cond = NULL) { | |
184 | $index = $cond ? $cond : 'No Condition'; | |
185 | if (!CRM_Utils_Array::value($index, self::$participantRole)) { | |
186 | self::$participantRole[$index] = array(); | |
187 | ||
188 | $condition = NULL; | |
189 | ||
190 | if ($cond) { | |
191 | $condition = "AND $cond"; | |
192 | } | |
193 | ||
194 | self::$participantRole[$index] = CRM_Core_OptionGroup::values('participant_role', FALSE, FALSE, | |
195 | FALSE, $condition | |
196 | ); | |
197 | } | |
198 | ||
199 | if ($id) { | |
200 | return self::$participantRole[$index][$id]; | |
201 | } | |
202 | return self::$participantRole[$index]; | |
203 | } | |
204 | ||
205 | /** | |
206 | * Get all the participant listings | |
207 | * | |
208 | * @access public | |
209 | * | |
210 | * @return array - array reference of all participant listings if any | |
211 | * @static | |
212 | */ | |
213 | public static function &participantListing($id = NULL) { | |
214 | if (!self::$participantListing) { | |
215 | self::$participantListing = array(); | |
216 | self::$participantListing = CRM_Core_OptionGroup::values('participant_listing'); | |
217 | } | |
218 | ||
219 | if ($id) { | |
220 | return self::$participantListing[$id]; | |
221 | } | |
222 | ||
223 | return self::$participantListing; | |
224 | } | |
225 | ||
226 | /** | |
227 | * Get all event types. | |
228 | * | |
229 | * @access public | |
230 | * | |
231 | * @return array - array reference of all event types. | |
232 | * @static | |
233 | */ | |
234 | public static function &eventType($id = NULL) { | |
235 | if (!self::$eventType) { | |
236 | self::$eventType = array(); | |
237 | self::$eventType = CRM_Core_OptionGroup::values('event_type'); | |
238 | } | |
239 | ||
240 | if ($id) { | |
241 | return self::$eventType[$id]; | |
242 | } | |
243 | ||
244 | return self::$eventType; | |
245 | } | |
246 | ||
247 | /** | |
248 | * get event template titles | |
249 | * | |
250 | * @return array of event id → template title pairs | |
251 | */ | |
252 | public static function &eventTemplates($id = NULL) { | |
253 | if (!self::$eventTemplates) { | |
254 | CRM_Core_PseudoConstant::populate(self::$eventTemplates, | |
255 | 'CRM_Event_DAO_Event', | |
256 | FALSE, | |
257 | 'template_title', | |
258 | 'is_active', | |
259 | 'is_template = 1' | |
260 | ); | |
261 | } | |
262 | if ($id) { | |
263 | return self::$eventTemplates[$id]; | |
264 | } | |
265 | return self::$eventTemplates; | |
266 | } | |
267 | ||
268 | /** | |
269 | * Flush given pseudoconstant so it can be reread from db | |
270 | * nex time it's requested. | |
271 | * | |
272 | * @access public | |
273 | * @static | |
274 | * | |
275 | * @param boolean $name pseudoconstant to be flushed | |
276 | * | |
277 | */ | |
278 | public static function flush($name) { | |
279 | self::$$name = NULL; | |
280 | } | |
281 | ||
282 | /** | |
283 | * Get all the Personal campaign pages | |
284 | * | |
285 | * @access public | |
286 | * | |
287 | * @return array - array reference of all pcp if any | |
288 | * @static | |
289 | */ | |
290 | public static function &pcPage($id = NULL) { | |
291 | if (!self::$pcPage) { | |
292 | CRM_Core_PseudoConstant::populate(self::$pcPage, | |
293 | 'CRM_PCP_DAO_PCP', | |
294 | FALSE, 'title' | |
295 | ); | |
296 | } | |
297 | if ($id) { | |
298 | return CRM_Utils_Array::value($id, self::$pcPage); | |
299 | } | |
300 | return self::$pcPage; | |
301 | } | |
302 | } | |
303 |