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
21 * This class holds all the Pseudo constants that are specific to Event. This avoids
22 * polluting the core class and isolates the Event
24 class CRM_Event_PseudoConstant
extends CRM_Core_PseudoConstant
{
31 private static $event;
38 private static $participantStatus;
45 private static $participantRole;
52 private static $participantListing;
59 private static $eventType;
62 * Event template titles
65 private static $eventTemplates;
68 * Personal campaign pages
72 private static $pcPage;
75 * Get all the n events
80 * @param null $condition
83 * array of all events if any
85 public static function event($id = NULL, $all = FALSE, $condition = NULL) {
86 $key = "{$id}_{$all}_{$condition}";
88 if (!isset(self
::$event[$key])) {
89 self
::$event[$key] = [];
92 if (!self
::$event[$key]) {
93 CRM_Core_PseudoConstant
::populate(self
::$event[$key],
94 'CRM_Event_DAO_Event',
95 $all, 'title', 'is_active', $condition, NULL
100 if (array_key_exists($id, self
::$event[$key])) {
101 return self
::$event[$key][$id];
107 return self
::$event[$key];
111 * Get all the n participant statuses.
116 * @param string $retColumn
117 * Tells populate() whether to return 'name' (default) or 'label' values.
120 * array reference of all participant statuses if any
122 public static function &participantStatus($id = NULL, $cond = NULL, $retColumn = 'name') {
123 if (self
::$participantStatus === NULL) {
124 self
::$participantStatus = [];
127 $index = $cond ?
$cond : 'No Condition';
128 $index = "{$index}_{$retColumn}";
129 if (empty(self
::$participantStatus[$index])) {
130 self
::$participantStatus[$index] = [];
131 CRM_Core_PseudoConstant
::populate(self
::$participantStatus[$index],
132 'CRM_Event_DAO_ParticipantStatusType',
133 FALSE, $retColumn, 'is_active', $cond, 'weight'
138 return self
::$participantStatus[$index][$id];
141 return self
::$participantStatus[$index];
145 * Get participant status class options.
149 public static function participantStatusClassOptions() {
151 'Positive' => ts('Positive'),
152 'Pending' => ts('Pending'),
153 'Waiting' => ts('Waiting'),
154 'Negative' => ts('Negative'),
159 * Return a status-type-keyed array of status classes
162 * Array of status classes, keyed by status type
164 public static function &participantStatusClass() {
165 static $statusClasses = NULL;
167 if ($statusClasses === NULL) {
168 self
::populate($statusClasses, 'CRM_Event_DAO_ParticipantStatusType', TRUE, 'class');
171 return $statusClasses;
175 * Get all the n participant roles.
181 * @return array|string
182 * array reference of all participant roles if any
184 public static function &participantRole($id = NULL, $cond = NULL) {
185 $index = $cond ?
$cond : 'No Condition';
186 if (empty(self
::$participantRole[$index])) {
187 self
::$participantRole[$index] = [];
192 $condition = "AND $cond";
195 self
::$participantRole[$index] = CRM_Core_OptionGroup
::values('participant_role', FALSE, FALSE,
201 return self
::$participantRole[$index][$id];
203 return self
::$participantRole[$index];
207 * Get all the participant listings.
211 * @return array|string
212 * array reference of all participant listings if any
214 public static function &participantListing($id = NULL) {
215 CRM_Core_Error
::deprecatedFunctionWarning('Function participantListing will be removed');
216 if (!self
::$participantListing) {
217 self
::$participantListing = [];
218 self
::$participantListing = CRM_Core_OptionGroup
::values('participant_listing');
222 return self
::$participantListing[$id];
225 return self
::$participantListing;
229 * Get all event types.
233 * @return array|string
234 * array reference of all event types.
236 public static function &eventType($id = NULL) {
237 if (!self
::$eventType) {
238 self
::$eventType = [];
239 self
::$eventType = CRM_Core_OptionGroup
::values('event_type');
243 return self
::$eventType[$id];
246 return self
::$eventType;
250 * Get event template titles.
255 * Array of event id → template title pairs
257 public static function &eventTemplates($id = NULL) {
258 if (!self
::$eventTemplates) {
259 CRM_Core_PseudoConstant
::populate(self
::$eventTemplates,
260 'CRM_Event_DAO_Event',
268 return self
::$eventTemplates[$id];
270 return self
::$eventTemplates;
274 * Flush given pseudoconstant so it can be reread from db
275 * nex time it's requested.
278 * @param bool|string $name pseudoconstant to be flushed
280 public static function flush($name = 'cache') {
281 if (isset(self
::$
$name)) {
287 * Get all the Personal campaign pages.
292 * array reference of all pcp if any
294 public static function &pcPage($id = NULL) {
295 CRM_Core_Error
::deprecatedFunctionWarning('Function pcPage will be removed');
296 if (!self
::$pcPage) {
297 CRM_Core_PseudoConstant
::populate(self
::$pcPage,
303 return self
::$pcPage[$id] ??
NULL;
305 return self
::$pcPage;