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 * Page for displaying list of events
23 class CRM_Event_Page_ManageEvent
extends CRM_Core_Page
{
26 * The action links that we need to display for the browse screen.
30 public static $_actionLinks = NULL;
33 * The event links to display for the browse screen.
36 public static $_eventLinks = NULL;
38 public static $_links = NULL;
40 public static $_tabLinks = NULL;
42 protected $_pager = NULL;
44 protected $_sortByCharacter;
46 protected $_isTemplate = FALSE;
52 * (reference) of action links
54 public function &links() {
55 if (!(self
::$_actionLinks)) {
56 // helper variable for nicer formatting
57 $copyExtra = ts('Are you sure you want to make a copy of this Event?');
58 $deleteExtra = ts('Are you sure you want to delete this Event?');
60 self
::$_actionLinks = [
61 CRM_Core_Action
::DISABLE
=> [
62 'name' => ts('Disable'),
63 'ref' => 'crm-enable-disable',
64 'title' => ts('Disable Event'),
66 CRM_Core_Action
::ENABLE
=> [
67 'name' => ts('Enable'),
68 'ref' => 'crm-enable-disable',
69 'title' => ts('Enable Event'),
71 CRM_Core_Action
::DELETE
=> [
72 'name' => ts('Delete'),
73 'url' => CRM_Utils_System
::currentPath(),
74 'qs' => 'action=delete&id=%%id%%',
75 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
76 'title' => ts('Delete Event'),
78 CRM_Core_Action
::COPY
=> [
80 'url' => CRM_Utils_System
::currentPath(),
81 'qs' => 'reset=1&action=copy&id=%%id%%',
82 'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"',
83 'title' => ts('Copy Event'),
87 return self
::$_actionLinks;
90 public function eventLinks() {
91 if (!(self
::$_eventLinks)) {
92 self
::$_eventLinks = [
93 'register_participant' => [
94 'name' => ts('Register Participant'),
95 'title' => ts('Register Participant'),
96 'url' => 'civicrm/participant/add',
97 'qs' => 'reset=1&action=add&context=standalone&eid=%%id%%',
100 'name' => ts('Event Info'),
101 'title' => ts('Event Info'),
102 'url' => 'civicrm/event/info',
103 'qs' => 'reset=1&id=%%id%%',
106 'online_registration_test' => [
107 'name' => ts('Registration (Test-drive)'),
108 'title' => ts('Online Registration (Test-drive)'),
109 'url' => 'civicrm/event/register',
110 'qs' => 'reset=1&action=preview&id=%%id%%',
113 'online_registration_live' => [
114 'name' => ts('Registration (Live)'),
115 'title' => ts('Online Registration (Live)'),
116 'url' => 'civicrm/event/register',
117 'qs' => 'reset=1&id=%%id%%',
122 return self
::$_eventLinks;
126 * Get tab Links for events.
131 * (reference) of tab links
133 public static function &tabs($enableCart) {
134 $cacheKey = $enableCart ?
1 : 0;
135 if (!(self
::$_tabLinks)) {
136 self
::$_tabLinks = [];
138 if (!isset(self
::$_tabLinks[$cacheKey])) {
139 self
::$_tabLinks[$cacheKey]['settings']
141 'title' => ts('Info and Settings'),
142 'url' => 'civicrm/event/manage/settings',
145 self
::$_tabLinks[$cacheKey]['location']
147 'title' => ts('Location'),
148 'url' => 'civicrm/event/manage/location',
149 'field' => 'loc_block_id',
152 self
::$_tabLinks[$cacheKey]['fee']
154 'title' => ts('Fees'),
155 'url' => 'civicrm/event/manage/fee',
156 'field' => 'is_monetary',
158 self
::$_tabLinks[$cacheKey]['registration']
160 'title' => ts('Online Registration'),
161 'url' => 'civicrm/event/manage/registration',
162 'field' => 'is_online_registration',
165 // @fixme I don't understand the event permissions check here - can we just get rid of it?
166 $permissions = CRM_Event_BAO_Event
::getAllPermissions();
167 if (CRM_Core_Permission
::check('administer CiviCRM') ||
!empty($permissions[CRM_Core_Permission
::EDIT
])) {
168 self
::$_tabLinks[$cacheKey]['reminder']
170 'title' => ts('Schedule Reminders'),
171 'url' => 'civicrm/event/manage/reminder',
172 'field' => 'reminder',
175 self
::$_tabLinks[$cacheKey]['conference']
177 'title' => ts('Conference Slots'),
178 'url' => 'civicrm/event/manage/conference',
179 'field' => 'slot_label_id',
181 self
::$_tabLinks[$cacheKey]['friend']
183 'title' => ts('Tell a Friend'),
184 'url' => 'civicrm/event/manage/friend',
187 self
::$_tabLinks[$cacheKey]['pcp']
189 'title' => ts('Personal Campaign Pages'),
190 'url' => 'civicrm/event/manage/pcp',
191 'field' => 'is_pcp_enabled',
193 self
::$_tabLinks[$cacheKey]['repeat']
195 'title' => ts('Repeat'),
196 'url' => 'civicrm/event/manage/repeat',
197 'field' => 'is_repeating_event',
202 unset(self
::$_tabLinks[$cacheKey]['conference']);
205 CRM_Utils_Hook
::tabset('civicrm/event/manage', self
::$_tabLinks[$cacheKey], []);
206 return self
::$_tabLinks[$cacheKey];
212 * This method is called after the page is created. It checks for the
213 * type of action and executes that action.
214 * Finally it calls the parent's run method.
218 public function run() {
219 // get the requested action
220 $action = CRM_Utils_Request
::retrieve('action', 'String',
221 // default to 'browse'
222 $this, FALSE, 'browse'
225 // assign vars to templates
226 $this->assign('action', $action);
227 $this->assign('iCal', CRM_Event_BAO_Event
::getICalLinks());
228 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
229 $this, FALSE, 0, 'REQUEST'
232 // figure out whether we’re handling an event or an event template
234 $this->_isTemplate
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $id, 'is_template');
236 elseif ($action & CRM_Core_Action
::ADD
) {
237 $this->_isTemplate
= CRM_Utils_Request
::retrieve('is_template', 'Boolean', $this);
240 if (!$this->_isTemplate
&& $id) {
243 'title' => ts('Manage Events'),
244 'url' => CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'),
247 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
250 // what action to take ?
251 if ($action & CRM_Core_Action
::DELETE
) {
252 $session = CRM_Core_Session
::singleton();
253 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1&action=browse'));
254 $controller = new CRM_Core_Controller_Simple('CRM_Event_Form_ManageEvent_Delete',
258 $controller->set('id', $id);
259 $controller->process();
260 return $controller->run();
262 elseif ($action & CRM_Core_Action
::COPY
) {
266 // finally browse the custom groups
270 return parent
::run();
278 public function browse() {
279 Civi
::resources()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
281 $this->_sortByCharacter
= CRM_Utils_Request
::retrieve('sortByCharacter',
285 $createdId = CRM_Utils_Request
::retrieve('cid', 'Positive', $this, FALSE, 0);
286 if (strtolower($this->_sortByCharacter
) == 'all' ||
289 $this->_sortByCharacter
= '';
290 $this->set('sortByCharacter', '');
293 $this->_force
= $this->_searchResult
= NULL;
298 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean',
301 $this->_searchResult
= CRM_Utils_Request
::retrieve('searchResult', 'Boolean', $this);
303 $whereClause = $this->whereClause($params, FALSE, $this->_force
);
305 if (CRM_Core_Config
::singleton()->includeAlphabeticalPager
) {
306 $this->pagerAToZ($whereClause, $params);
310 $whereClause = $this->whereClause($params, TRUE, $this->_force
);
311 // because is_template != 1 would be to simple
312 $whereClause .= ' AND (is_template = 0 OR is_template IS NULL)';
314 $this->pager($whereClause, $params);
316 list($offset, $rowCount) = $this->_pager
->getOffsetAndRowCount();
318 // get all custom groups sorted by weight
325 ORDER BY start_date desc
326 LIMIT $offset, $rowCount";
328 $dao = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Event_DAO_Event');
329 $permittedEventsByAction = CRM_Event_BAO_Event
::getAllPermissions();
332 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
334 // get the list of active event pcps
337 $pcpDao = new CRM_PCP_DAO_PCPBlock();
338 $pcpDao->entity_table
= 'civicrm_event';
341 while ($pcpDao->fetch()) {
342 $eventPCPS[$pcpDao->entity_id
] = $pcpDao->entity_id
;
344 // check if we're in shopping cart mode for events
345 $enableCart = Civi
::settings()->get('enable_cart');
346 $this->assign('eventCartEnabled', $enableCart);
347 $mapping = CRM_Utils_Array
::first(CRM_Core_BAO_ActionSchedule
::getMappings([
348 'id' => CRM_Event_ActionMapping
::EVENT_NAME_MAPPING_ID
,
350 $eventType = CRM_Core_OptionGroup
::values('event_type');
351 while ($dao->fetch()) {
352 if (in_array($dao->id
, $permittedEventsByAction[CRM_Core_Permission
::VIEW
])) {
353 $manageEvent[$dao->id
] = [];
354 $repeat = CRM_Core_BAO_RecurringEntity
::getPositionAndCount($dao->id
, 'civicrm_event');
355 $manageEvent[$dao->id
]['repeat'] = '';
357 $manageEvent[$dao->id
]['repeat'] = ts('Repeating (%1 of %2)', [1 => $repeat[0], 2 => $repeat[1]]);
359 CRM_Core_DAO
::storeValues($dao, $manageEvent[$dao->id
]);
361 // form all action links
362 $action = array_sum(array_keys($this->links()));
364 if ($dao->is_active
) {
365 $action -= CRM_Core_Action
::ENABLE
;
368 $action -= CRM_Core_Action
::DISABLE
;
371 if (!in_array($dao->id
, $permittedEventsByAction[CRM_Core_Permission
::DELETE
])) {
372 $action -= CRM_Core_Action
::DELETE
;
374 if (!in_array($dao->id
, $permittedEventsByAction[CRM_Core_Permission
::EDIT
])) {
375 $action -= CRM_Core_Action
::UPDATE
;
378 $eventLinks = self
::eventLinks();
379 if (!CRM_Core_Permission
::check('edit event participants')) {
380 unset($eventLinks['register_participant']);
383 $manageEvent[$dao->id
]['eventlinks'] = CRM_Core_Action
::formLink($eventLinks,
388 'event.manage.eventlinks',
392 $manageEvent[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::links(),
403 'entity_id' => $dao->id
,
404 'entity_table' => 'civicrm_event',
408 $defaults['location'] = CRM_Core_BAO_Location
::getValues($params, TRUE);
410 $manageEvent[$dao->id
]['friend'] = CRM_Friend_BAO_Friend
::getValues($params);
412 if (isset($defaults['location']['address'][1]['city'])) {
413 $manageEvent[$dao->id
]['city'] = $defaults['location']['address'][1]['city'];
415 if (isset($defaults['location']['address'][1]['state_province_id'])) {
416 $manageEvent[$dao->id
]['state_province'] = CRM_Core_PseudoConstant
::stateProvince($defaults['location']['address'][1]['state_province_id']);
419 //show campaigns on selector.
420 $manageEvent[$dao->id
]['campaign'] = $allCampaigns[$dao->campaign_id
] ??
NULL;
421 $manageEvent[$dao->id
]['reminder'] = CRM_Core_BAO_ActionSchedule
::isConfigured($dao->id
, $mapping->getId());
422 $manageEvent[$dao->id
]['is_pcp_enabled'] = $eventPCPS[$dao->id
] ??
NULL;
423 $manageEvent[$dao->id
]['event_type'] = $eventType[$manageEvent[$dao->id
]['event_type_id']] ??
NULL;
424 $manageEvent[$dao->id
]['is_repeating_event'] = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_RecurringEntity', $dao->id
, 'parent_id', 'entity_id');
425 // allow hooks to set 'field' value which allows configuration pop-up to show a tab as enabled/disabled
426 CRM_Utils_Hook
::tabset('civicrm/event/manage/rows', $manageEvent, ['event_id' => $dao->id
]);
430 $manageEvent['tab'] = self
::tabs($enableCart);
431 $this->assign('rows', $manageEvent);
433 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1', 'label');
434 $statusTypesPending = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0', 'label');
435 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
436 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
437 $this->assign('findParticipants', $findParticipants);
441 * make a copy of a Event, including
442 * all the fields in the event wizard
445 * @throws \CRM_Core_Exception
447 public function copy() {
448 $id = CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE, 0, 'GET');
450 $urlString = 'civicrm/event/manage';
451 $copyEvent = CRM_Event_BAO_Event
::copy($id);
452 $urlParams = 'reset=1';
453 // Redirect to Copied Event Configuration
454 if ($copyEvent->id
) {
455 $urlString = 'civicrm/event/manage/settings';
456 $urlParams .= '&action=update&id=' . $copyEvent->id
;
459 return CRM_Utils_System
::redirect(CRM_Utils_System
::url($urlString, $urlParams));
462 public function search() {
463 if (isset($this->_action
) & (CRM_Core_Action
::ADD |
464 CRM_Core_Action
::UPDATE |
465 CRM_Core_Action
::DELETE
471 $form = new CRM_Core_Controller_Simple('CRM_Event_Form_SearchEvent', ts('Search Events'), CRM_Core_Action
::ADD
);
472 $form->setEmbedded(TRUE);
473 $form->setParent($this);
479 * @param array $params
480 * @param bool $sortBy
485 public function whereClause(&$params, $sortBy = TRUE, $force) {
488 $title = $this->get('title');
489 $createdId = $this->get('cid');
492 $clauses[] = "(created_id = {$createdId})";
496 $clauses[] = "title LIKE %1";
497 if (strpos($title, '%') !== FALSE) {
498 $params[1] = [trim($title), 'String', FALSE];
501 $params[1] = [trim($title), 'String', TRUE];
505 $value = $this->get('event_type_id');
507 if (is_array($value)) {
508 $type = implode(',', $value);
510 $clauses[] = "event_type_id IN (%2)";
511 $params[2] = [$type, 'String'];
514 $eventsByDates = $this->get('eventsByDates');
515 if ($this->_searchResult
) {
516 if ($eventsByDates) {
518 $from = $this->get('start_date');
519 if (!CRM_Utils_System
::isNull($from)) {
520 $clauses[] = '( end_date >= %3 OR end_date IS NULL )';
521 $params[3] = [$from, 'String'];
524 $to = $this->get('end_date');
525 if (!CRM_Utils_System
::isNull($to)) {
526 $clauses[] = '( start_date <= %4 OR start_date IS NULL )';
527 $params[4] = [$to, 'String'];
531 $curDate = date('YmdHis');
532 $clauses[] = "(end_date >= {$curDate} OR end_date IS NULL)";
536 $curDate = date('YmdHis');
537 $clauses[] = "(end_date >= {$curDate} OR end_date IS NULL)";
541 $this->_sortByCharacter
!== NULL
543 $clauses[] = "title LIKE '" . strtolower(CRM_Core_DAO
::escapeWildCardString($this->_sortByCharacter
)) . "%'";
546 $campaignIds = $this->get('campaign_id');
547 if (!CRM_Utils_System
::isNull($campaignIds)) {
548 if (!is_array($campaignIds)) {
549 $campaignIds = [$campaignIds];
551 $clauses[] = '( campaign_id IN ( ' . implode(' , ', array_values($campaignIds)) . ' ) )';
554 // don't do a the below assignment when doing a
557 if (count($clauses) > 1 ||
$eventsByDates) {
558 $this->assign('isSearch', 1);
561 $this->assign('isSearch', 0);
565 return !empty($clauses) ?
implode(' AND ', $clauses) : '(1)';
569 * @param $whereClause
570 * @param array $whereParams
572 public function pager($whereClause, $whereParams) {
574 $params['status'] = ts('Event %%StatusMessage%%');
575 $params['csvString'] = NULL;
576 $params['buttonTop'] = 'PagerTopButton';
577 $params['buttonBottom'] = 'PagerBottomButton';
578 $params['rowCount'] = $this->get(CRM_Utils_Pager
::PAGE_ROWCOUNT
);
579 if (!$params['rowCount']) {
580 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
588 $params['total'] = CRM_Core_DAO
::singleValueQuery($query, $whereParams);
590 $this->_pager
= new CRM_Utils_Pager($params);
591 $this->assign_by_ref('pager', $this->_pager
);
595 * @param $whereClause
596 * @param array $whereParams
598 public function pagerAtoZ($whereClause, $whereParams) {
601 SELECT DISTINCT UPPER(LEFT(title, 1)) as sort_name
604 ORDER BY UPPER(LEFT(title, 1))
606 $dao = CRM_Core_DAO
::executeQuery($query, $whereParams);
608 $aToZBar = CRM_Utils_PagerAToZ
::getAToZBar($dao, $this->_sortByCharacter
, TRUE);
609 $this->assign('aToZ', $aToZBar);