3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class holds all the Pseudo constants that are specific to Event. This avoids
20 * polluting the core class and isolates the Event
22 class CRM_Event_PseudoConstant
extends CRM_Core_PseudoConstant
{
29 private static $event;
36 private static $participantStatus;
43 private static $participantRole;
50 private static $participantListing;
57 private static $eventType;
60 * Event template titles
63 private static $eventTemplates;
66 * Personal campaign pages
70 private static $pcPage;
73 * Get all the n events
78 * @param null $condition
81 * array of all events if any
83 public static function event($id = NULL, $all = FALSE, $condition = NULL) {
84 $key = "{$id}_{$all}_{$condition}";
86 if (!isset(self
::$event[$key])) {
87 self
::$event[$key] = [];
90 if (!self
::$event[$key]) {
91 CRM_Core_PseudoConstant
::populate(self
::$event[$key],
92 'CRM_Event_DAO_Event',
93 $all, 'title', 'is_active', $condition, NULL
98 if (array_key_exists($id, self
::$event[$key])) {
99 return self
::$event[$key][$id];
105 return self
::$event[$key];
109 * Get all the n participant statuses.
114 * @param string $retColumn
115 * Tells populate() whether to return 'name' (default) or 'label' values.
118 * array reference of all participant statuses if any
120 public static function &participantStatus($id = NULL, $cond = NULL, $retColumn = 'name') {
121 if (self
::$participantStatus === NULL) {
122 self
::$participantStatus = [];
125 $index = $cond ?
$cond : 'No Condition';
126 $index = "{$index}_{$retColumn}";
127 if (empty(self
::$participantStatus[$index])) {
128 self
::$participantStatus[$index] = [];
129 CRM_Core_PseudoConstant
::populate(self
::$participantStatus[$index],
130 'CRM_Event_DAO_ParticipantStatusType',
131 FALSE, $retColumn, 'is_active', $cond, 'weight'
136 return self
::$participantStatus[$index][$id];
139 return self
::$participantStatus[$index];
143 * Get participant status class options.
147 public static function participantStatusClassOptions() {
149 'Positive' => ts('Positive'),
150 'Pending' => ts('Pending'),
151 'Waiting' => ts('Waiting'),
152 'Negative' => ts('Negative'),
157 * Return a status-type-keyed array of status classes
160 * Array of status classes, keyed by status type
162 public static function &participantStatusClass() {
163 static $statusClasses = NULL;
165 if ($statusClasses === NULL) {
166 self
::populate($statusClasses, 'CRM_Event_DAO_ParticipantStatusType', TRUE, 'class');
169 return $statusClasses;
173 * Get all the n participant roles.
179 * @return array|string
180 * array reference of all participant roles if any
182 public static function &participantRole($id = NULL, $cond = NULL) {
183 $index = $cond ?
$cond : 'No Condition';
184 if (empty(self
::$participantRole[$index])) {
185 self
::$participantRole[$index] = [];
190 $condition = "AND $cond";
193 self
::$participantRole[$index] = CRM_Core_OptionGroup
::values('participant_role', FALSE, FALSE,
199 return self
::$participantRole[$index][$id];
201 return self
::$participantRole[$index];
205 * Get all the participant listings.
209 * @return array|string
210 * array reference of all participant listings if any
212 public static function &participantListing($id = NULL) {
213 CRM_Core_Error
::deprecatedFunctionWarning('Function participantListing will be removed');
214 if (!self
::$participantListing) {
215 self
::$participantListing = [];
216 self
::$participantListing = CRM_Core_OptionGroup
::values('participant_listing');
220 return self
::$participantListing[$id];
223 return self
::$participantListing;
227 * Get all event types.
231 * @return array|string
232 * array reference of all event types.
234 public static function &eventType($id = NULL) {
235 if (!self
::$eventType) {
236 self
::$eventType = [];
237 self
::$eventType = CRM_Core_OptionGroup
::values('event_type');
241 return self
::$eventType[$id];
244 return self
::$eventType;
248 * Get event template titles.
253 * Array of event id → template title pairs
255 public static function &eventTemplates($id = NULL) {
256 if (!self
::$eventTemplates) {
257 CRM_Core_PseudoConstant
::populate(self
::$eventTemplates,
258 'CRM_Event_DAO_Event',
266 return self
::$eventTemplates[$id];
268 return self
::$eventTemplates;
272 * Flush given pseudoconstant so it can be reread from db
273 * nex time it's requested.
276 * @param bool|string $name pseudoconstant to be flushed
278 public static function flush($name = 'cache') {
279 if (isset(self
::$
$name)) {
285 * Get all the Personal campaign pages.
290 * array reference of all pcp if any
292 public static function &pcPage($id = NULL) {
293 CRM_Core_Error
::deprecatedFunctionWarning('Function pcPage will be removed');
294 if (!self
::$pcPage) {
295 CRM_Core_PseudoConstant
::populate(self
::$pcPage,
301 return self
::$pcPage[$id] ??
NULL;
303 return self
::$pcPage;