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
71 private static $pcPage;
74 * Get all the n events
79 * @param null $condition
82 * array of all events if any
84 public static function event($id = NULL, $all = FALSE, $condition = NULL) {
85 $key = "{$id}_{$all}_{$condition}";
87 if (!isset(self
::$event[$key])) {
88 self
::$event[$key] = [];
91 if (!self
::$event[$key]) {
92 CRM_Core_PseudoConstant
::populate(self
::$event[$key],
93 'CRM_Event_DAO_Event',
94 $all, 'title', 'is_active', $condition, NULL
99 if (array_key_exists($id, self
::$event[$key])) {
100 return self
::$event[$key][$id];
106 return self
::$event[$key];
110 * Get all the n participant statuses.
115 * @param string $retColumn
116 * Tells populate() whether to return 'name' (default) or 'label' values.
119 * array reference of all participant statuses if any
121 public static function &participantStatus($id = NULL, $cond = NULL, $retColumn = 'name') {
122 if (self
::$participantStatus === NULL) {
123 self
::$participantStatus = [];
126 $index = $cond ?
$cond : 'No Condition';
127 $index = "{$index}_{$retColumn}";
128 if (empty(self
::$participantStatus[$index])) {
129 self
::$participantStatus[$index] = [];
130 CRM_Core_PseudoConstant
::populate(self
::$participantStatus[$index],
131 'CRM_Event_DAO_ParticipantStatusType',
132 FALSE, $retColumn, 'is_active', $cond, 'weight'
137 return self
::$participantStatus[$index][$id];
140 return self
::$participantStatus[$index];
144 * Get participant status class options.
148 public static function participantStatusClassOptions() {
150 'Positive' => ts('Positive'),
151 'Pending' => ts('Pending'),
152 'Waiting' => ts('Waiting'),
153 'Negative' => ts('Negative'),
158 * Return a status-type-keyed array of status classes
161 * Array of status classes, keyed by status type
163 public static function &participantStatusClass() {
164 static $statusClasses = NULL;
166 if ($statusClasses === NULL) {
167 self
::populate($statusClasses, 'CRM_Event_DAO_ParticipantStatusType', TRUE, 'class');
170 return $statusClasses;
174 * Get all the n participant roles.
180 * @return array|string
181 * array reference of all participant roles if any
183 public static function &participantRole($id = NULL, $cond = NULL) {
184 $index = $cond ?
$cond : 'No Condition';
185 if (empty(self
::$participantRole[$index])) {
186 self
::$participantRole[$index] = [];
191 $condition = "AND $cond";
194 self
::$participantRole[$index] = CRM_Core_OptionGroup
::values('participant_role', FALSE, FALSE,
200 return self
::$participantRole[$index][$id];
202 return self
::$participantRole[$index];
206 * 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 if (!self
::$participantListing) {
216 self
::$participantListing = [];
217 self
::$participantListing = CRM_Core_OptionGroup
::values('participant_listing');
221 return self
::$participantListing[$id];
224 return self
::$participantListing;
228 * Get all event types.
232 * @return array|string
233 * array reference of all event types.
235 public static function &eventType($id = NULL) {
236 if (!self
::$eventType) {
237 self
::$eventType = [];
238 self
::$eventType = CRM_Core_OptionGroup
::values('event_type');
242 return self
::$eventType[$id];
245 return self
::$eventType;
249 * Get event template titles.
254 * Array of event id → template title pairs
256 public static function &eventTemplates($id = NULL) {
257 if (!self
::$eventTemplates) {
258 CRM_Core_PseudoConstant
::populate(self
::$eventTemplates,
259 'CRM_Event_DAO_Event',
267 return self
::$eventTemplates[$id];
269 return self
::$eventTemplates;
273 * Flush given pseudoconstant so it can be reread from db
274 * nex time it's requested.
277 * @param bool|string $name pseudoconstant to be flushed
279 public static function flush($name = 'cache') {
280 if (isset(self
::$
$name)) {
286 * Get all the Personal campaign pages.
291 * array reference of all pcp if any
293 public static function &pcPage($id = NULL) {
294 if (!self
::$pcPage) {
295 CRM_Core_PseudoConstant
::populate(self
::$pcPage,
301 return CRM_Utils_Array
::value($id, self
::$pcPage);
303 return self
::$pcPage;