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;
77 * @param string|null $condition
78 * Optional SQL where condition
80 * @return array|string|null
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 event participant statuses.
112 * @param int|null $id
113 * Return the specified participant status, or null to return all
114 * @param string|null $cond
115 * Optional SQL where condition
116 * @param string $retColumn
117 * Tells populate() whether to return 'name' (default) or 'label' values.
119 * @return array|string
120 * array reference of all participant statuses if any, or single value if $id was passed
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.
179 * @param string|null $cond
180 * Optional SQL where condition
182 * @return array|string
183 * array reference of all participant roles if any
185 public static function &participantRole($id = NULL, $cond = NULL) {
186 $index = $cond ?
$cond : 'No Condition';
187 if (empty(self
::$participantRole[$index])) {
188 self
::$participantRole[$index] = [];
193 $condition = "AND $cond";
196 self
::$participantRole[$index] = CRM_Core_OptionGroup
::values('participant_role', FALSE, FALSE,
202 return self
::$participantRole[$index][$id];
204 return self
::$participantRole[$index];
208 * Get all the participant listings.
212 * @return array|string
213 * array reference of all participant listings if any
215 public static function &participantListing($id = NULL) {
216 CRM_Core_Error
::deprecatedFunctionWarning('Function participantListing will be removed');
217 if (!self
::$participantListing) {
218 self
::$participantListing = [];
219 self
::$participantListing = CRM_Core_OptionGroup
::values('participant_listing');
223 return self
::$participantListing[$id];
226 return self
::$participantListing;
230 * Get all event types.
234 * @return array|string
235 * array reference of all event types.
237 public static function &eventType($id = NULL) {
238 if (!self
::$eventType) {
239 self
::$eventType = [];
240 self
::$eventType = CRM_Core_OptionGroup
::values('event_type');
244 return self
::$eventType[$id];
247 return self
::$eventType;
251 * Get event template titles.
256 * Array of event id → template title pairs
258 public static function &eventTemplates($id = NULL) {
259 if (!self
::$eventTemplates) {
260 CRM_Core_PseudoConstant
::populate(self
::$eventTemplates,
261 'CRM_Event_DAO_Event',
269 return self
::$eventTemplates[$id];
271 return self
::$eventTemplates;
275 * Flush given pseudoconstant so it can be reread from db
276 * next time it's requested.
279 * @param bool|string $name pseudoconstant to be flushed
281 public static function flush($name = 'cache') {
282 if (isset(self
::$
$name)) {
288 * Get all the Personal campaign pages.
293 * array reference of all pcp if any
295 public static function &pcPage($id = NULL) {
296 CRM_Core_Error
::deprecatedFunctionWarning('Function pcPage will be removed');
297 if (!self
::$pcPage) {
298 CRM_Core_PseudoConstant
::populate(self
::$pcPage,
304 return self
::$pcPage[$id] ??
NULL;
306 return self
::$pcPage;