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 * Page for displaying list of events
21 class CRM_Event_Page_ManageEvent
extends CRM_Core_Page
{
24 * The action links that we need to display for the browse screen.
28 public static $_actionLinks = NULL;
31 * The event links to display for the browse screen.
34 public static $_eventLinks = NULL;
36 public static $_links = NULL;
38 public static $_tabLinks = NULL;
40 protected $_pager = NULL;
42 protected $_sortByCharacter;
44 protected $_isTemplate = FALSE;
50 * (reference) of action links
52 public function &links() {
53 if (!(self
::$_actionLinks)) {
54 // helper variable for nicer formatting
55 $copyExtra = ts('Are you sure you want to make a copy of this Event?');
56 $deleteExtra = ts('Are you sure you want to delete this Event?');
58 self
::$_actionLinks = [
59 CRM_Core_Action
::DISABLE
=> [
60 'name' => ts('Disable'),
61 'ref' => 'crm-enable-disable',
62 'title' => ts('Disable Event'),
64 CRM_Core_Action
::ENABLE
=> [
65 'name' => ts('Enable'),
66 'ref' => 'crm-enable-disable',
67 'title' => ts('Enable Event'),
69 CRM_Core_Action
::DELETE
=> [
70 'name' => ts('Delete'),
71 'url' => CRM_Utils_System
::currentPath(),
72 'qs' => 'action=delete&id=%%id%%',
73 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
74 'title' => ts('Delete Event'),
76 CRM_Core_Action
::COPY
=> [
78 'url' => CRM_Utils_System
::currentPath(),
79 'qs' => 'reset=1&action=copy&id=%%id%%',
80 'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"',
81 'title' => ts('Copy Event'),
85 return self
::$_actionLinks;
88 public function eventLinks() {
89 if (!(self
::$_eventLinks)) {
90 self
::$_eventLinks = [
91 'register_participant' => [
92 'name' => ts('Register Participant'),
93 'title' => ts('Register Participant'),
94 'url' => 'civicrm/participant/add',
95 'qs' => 'reset=1&action=add&context=standalone&eid=%%id%%',
98 'name' => ts('Event Info'),
99 'title' => ts('Event Info'),
100 'url' => 'civicrm/event/info',
101 'qs' => 'reset=1&id=%%id%%',
104 'online_registration_test' => [
105 'name' => ts('Registration (Test-drive)'),
106 'title' => ts('Online Registration (Test-drive)'),
107 'url' => 'civicrm/event/register',
108 'qs' => 'reset=1&action=preview&id=%%id%%',
111 'online_registration_live' => [
112 'name' => ts('Registration (Live)'),
113 'title' => ts('Online Registration (Live)'),
114 'url' => 'civicrm/event/register',
115 'qs' => 'reset=1&id=%%id%%',
120 return self
::$_eventLinks;
124 * Get tab Links for events.
127 * (reference) of tab links
128 * @throws \CiviCRM_API3_Exception
130 public static function &tabs() {
131 // @todo Move to eventcart extension
132 // check if we're in shopping cart mode for events
133 $enableCart = (bool) Civi
::settings()->get('enable_cart');
135 $cacheKey = $enableCart ?
1 : 0;
136 if (!(self
::$_tabLinks)) {
137 self
::$_tabLinks = [];
139 if (!isset(self
::$_tabLinks[$cacheKey])) {
140 self
::$_tabLinks[$cacheKey]['settings']
142 'title' => ts('Info and Settings'),
143 'url' => 'civicrm/event/manage/settings',
146 self
::$_tabLinks[$cacheKey]['location']
148 'title' => ts('Location'),
149 'url' => 'civicrm/event/manage/location',
150 'field' => 'loc_block_id',
153 self
::$_tabLinks[$cacheKey]['fee']
155 'title' => ts('Fees'),
156 'url' => 'civicrm/event/manage/fee',
157 'field' => 'is_monetary',
159 self
::$_tabLinks[$cacheKey]['registration']
161 'title' => ts('Online Registration'),
162 'url' => 'civicrm/event/manage/registration',
163 'field' => 'is_online_registration',
166 // @fixme I don't understand the event permissions check here - can we just get rid of it?
167 $permissions = CRM_Event_BAO_Event
::getAllPermissions();
168 if (CRM_Core_Permission
::check('administer CiviCRM data') ||
!empty($permissions[CRM_Core_Permission
::EDIT
])) {
169 self
::$_tabLinks[$cacheKey]['reminder']
171 'title' => ts('Schedule Reminders'),
172 'url' => 'civicrm/event/manage/reminder',
173 'field' => 'reminder',
176 self
::$_tabLinks[$cacheKey]['conference']
178 'title' => ts('Conference Slots'),
179 'url' => 'civicrm/event/manage/conference',
180 'field' => 'slot_label_id',
182 self
::$_tabLinks[$cacheKey]['friend']
184 'title' => ts('Tell a Friend'),
185 'url' => 'civicrm/event/manage/friend',
188 self
::$_tabLinks[$cacheKey]['pcp']
190 'title' => ts('Personal Campaign Pages'),
191 'url' => 'civicrm/event/manage/pcp',
192 'field' => 'is_pcp_enabled',
194 self
::$_tabLinks[$cacheKey]['repeat']
196 'title' => ts('Repeat'),
197 'url' => 'civicrm/event/manage/repeat',
198 'field' => 'is_repeating_event',
203 unset(self
::$_tabLinks[$cacheKey]['conference']);
206 CRM_Utils_Hook
::tabset('civicrm/event/manage', self
::$_tabLinks[$cacheKey], []);
207 return self
::$_tabLinks[$cacheKey];
213 * This method is called after the page is created. It checks for the
214 * type of action and executes that action.
215 * Finally it calls the parent's run method.
219 public function run() {
220 // get the requested action
221 $action = CRM_Utils_Request
::retrieve('action', 'String',
222 // default to 'browse'
223 $this, FALSE, 'browse'
226 // assign vars to templates
227 $this->assign('action', $action);
228 $this->assign('iCal', CRM_Event_BAO_Event
::getICalLinks());
229 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
230 $this, FALSE, 0, 'REQUEST'
233 // figure out whether we’re handling an event or an event template
235 $this->_isTemplate
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $id, 'is_template');
237 elseif ($action & CRM_Core_Action
::ADD
) {
238 $this->_isTemplate
= CRM_Utils_Request
::retrieve('is_template', 'Boolean', $this);
241 if (!$this->_isTemplate
&& $id) {
244 'title' => ts('Manage Events'),
245 'url' => CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'),
248 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
251 // what action to take ?
252 if ($action & CRM_Core_Action
::DELETE
) {
253 $session = CRM_Core_Session
::singleton();
254 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1&action=browse'));
255 $controller = new CRM_Core_Controller_Simple('CRM_Event_Form_ManageEvent_Delete',
259 $controller->set('id', $id);
260 $controller->process();
261 return $controller->run();
263 elseif ($action & CRM_Core_Action
::COPY
) {
267 // finally browse the custom groups
271 return parent
::run();
279 public function browse() {
280 Civi
::resources()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
282 $this->_sortByCharacter
= CRM_Utils_Request
::retrieve('sortByCharacter',
286 $createdId = CRM_Utils_Request
::retrieve('cid', 'Positive', $this, FALSE, 0);
287 if (strtolower($this->_sortByCharacter
) == 'all' ||
290 $this->_sortByCharacter
= '';
291 $this->set('sortByCharacter', '');
294 $this->_force
= $this->_searchResult
= NULL;
299 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean',
302 $this->_searchResult
= CRM_Utils_Request
::retrieve('searchResult', 'Boolean', $this);
304 $whereClause = $this->whereClause($params, FALSE, $this->_force
);
306 if (CRM_Core_Config
::singleton()->includeAlphabeticalPager
) {
307 $this->pagerAToZ($whereClause, $params);
311 $whereClause = $this->whereClause($params, TRUE, $this->_force
);
312 // because is_template != 1 would be to simple
313 $whereClause .= ' AND (is_template = 0 OR is_template IS NULL)';
315 $this->pager($whereClause, $params);
317 list($offset, $rowCount) = $this->_pager
->getOffsetAndRowCount();
319 // get all custom groups sorted by weight
326 ORDER BY start_date desc
327 LIMIT $offset, $rowCount";
329 $dao = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Event_DAO_Event');
330 $permittedEventsByAction = CRM_Event_BAO_Event
::getAllPermissions();
333 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
335 // get the list of active event pcps
338 $pcpDao = new CRM_PCP_DAO_PCPBlock();
339 $pcpDao->entity_table
= 'civicrm_event';
342 while ($pcpDao->fetch()) {
343 $eventPCPS[$pcpDao->entity_id
] = $pcpDao->entity_id
;
345 $mapping = CRM_Utils_Array
::first(CRM_Core_BAO_ActionSchedule
::getMappings([
346 'id' => CRM_Event_ActionMapping
::EVENT_NAME_MAPPING_ID
,
348 $eventType = CRM_Core_OptionGroup
::values('event_type');
349 while ($dao->fetch()) {
350 if (in_array($dao->id
, $permittedEventsByAction[CRM_Core_Permission
::VIEW
])) {
351 $manageEvent[$dao->id
] = [];
352 $repeat = CRM_Core_BAO_RecurringEntity
::getPositionAndCount($dao->id
, 'civicrm_event');
353 $manageEvent[$dao->id
]['repeat'] = '';
355 $manageEvent[$dao->id
]['repeat'] = ts('Repeating (%1 of %2)', [1 => $repeat[0], 2 => $repeat[1]]);
357 CRM_Core_DAO
::storeValues($dao, $manageEvent[$dao->id
]);
359 // form all action links
360 $action = array_sum(array_keys($this->links()));
362 if ($dao->is_active
) {
363 $action -= CRM_Core_Action
::ENABLE
;
366 $action -= CRM_Core_Action
::DISABLE
;
369 if (!in_array($dao->id
, $permittedEventsByAction[CRM_Core_Permission
::DELETE
])) {
370 $action -= CRM_Core_Action
::DELETE
;
372 if (!in_array($dao->id
, $permittedEventsByAction[CRM_Core_Permission
::EDIT
])) {
373 $action -= CRM_Core_Action
::UPDATE
;
376 $eventLinks = self
::eventLinks();
377 if (!CRM_Core_Permission
::check('edit event participants')) {
378 unset($eventLinks['register_participant']);
381 $manageEvent[$dao->id
]['eventlinks'] = CRM_Core_Action
::formLink($eventLinks,
386 'event.manage.eventlinks',
390 $manageEvent[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::links(),
401 'entity_id' => $dao->id
,
402 'entity_table' => 'civicrm_event',
406 $defaults['location'] = CRM_Core_BAO_Location
::getValues($params, TRUE);
408 $manageEvent[$dao->id
]['friend'] = CRM_Friend_BAO_Friend
::getValues($params);
410 if (isset($defaults['location']['address'][1]['city'])) {
411 $manageEvent[$dao->id
]['city'] = $defaults['location']['address'][1]['city'];
413 if (isset($defaults['location']['address'][1]['state_province_id'])) {
414 $manageEvent[$dao->id
]['state_province'] = CRM_Core_PseudoConstant
::stateProvince($defaults['location']['address'][1]['state_province_id']);
417 //show campaigns on selector.
418 $manageEvent[$dao->id
]['campaign'] = $allCampaigns[$dao->campaign_id
] ??
NULL;
419 $manageEvent[$dao->id
]['reminder'] = CRM_Core_BAO_ActionSchedule
::isConfigured($dao->id
, $mapping->getId());
420 $manageEvent[$dao->id
]['is_pcp_enabled'] = $eventPCPS[$dao->id
] ??
NULL;
421 $manageEvent[$dao->id
]['event_type'] = $eventType[$manageEvent[$dao->id
]['event_type_id']] ??
NULL;
422 $manageEvent[$dao->id
]['is_repeating_event'] = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_RecurringEntity', $dao->id
, 'parent_id', 'entity_id');
423 // allow hooks to set 'field' value which allows configuration pop-up to show a tab as enabled/disabled
424 CRM_Utils_Hook
::tabset('civicrm/event/manage/rows', $manageEvent, ['event_id' => $dao->id
]);
428 $manageEvent['tab'] = self
::tabs();
429 $this->assign('rows', $manageEvent);
431 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1', 'label');
432 $statusTypesPending = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0', 'label');
433 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
434 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
435 $this->assign('findParticipants', $findParticipants);
439 * make a copy of a Event, including
440 * all the fields in the event wizard
443 * @throws \CRM_Core_Exception
445 public function copy() {
446 $id = CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE, 0, 'GET');
448 $urlString = 'civicrm/event/manage';
449 $copyEvent = CRM_Event_BAO_Event
::copy($id);
450 $urlParams = 'reset=1';
451 // Redirect to Copied Event Configuration
452 if ($copyEvent->id
) {
453 $urlString = 'civicrm/event/manage/settings';
454 $urlParams .= '&action=update&id=' . $copyEvent->id
;
457 return CRM_Utils_System
::redirect(CRM_Utils_System
::url($urlString, $urlParams));
460 public function search() {
461 if (isset($this->_action
) & (CRM_Core_Action
::ADD |
462 CRM_Core_Action
::UPDATE |
463 CRM_Core_Action
::DELETE
469 $form = new CRM_Core_Controller_Simple('CRM_Event_Form_SearchEvent', ts('Search Events'), CRM_Core_Action
::ADD
);
470 $form->setEmbedded(TRUE);
471 $form->setParent($this);
477 * @param array $params
478 * @param bool $sortBy
483 public function whereClause(&$params, $sortBy, $force) {
486 $title = $this->get('title');
487 $createdId = $this->get('cid');
490 $clauses[] = "(created_id = {$createdId})";
494 $clauses[] = "title LIKE %1";
495 if (strpos($title, '%') !== FALSE) {
496 $params[1] = [trim($title), 'String', FALSE];
499 $params[1] = [trim($title), 'String', TRUE];
503 $value = $this->get('event_type_id');
505 if (is_array($value)) {
506 $type = implode(',', $value);
508 $clauses[] = "event_type_id IN (%2)";
509 $params[2] = [$type, 'String'];
512 $eventsByDates = $this->get('eventsByDates');
513 if ($this->_searchResult
) {
514 if ($eventsByDates) {
516 $from = $this->get('start_date');
517 if (!CRM_Utils_System
::isNull($from)) {
518 $clauses[] = '( end_date >= %3 OR end_date IS NULL )';
519 $params[3] = [$from, 'String'];
522 $to = $this->get('end_date');
523 if (!CRM_Utils_System
::isNull($to)) {
524 $clauses[] = '( start_date <= %4 OR start_date IS NULL )';
525 $params[4] = [$to, 'String'];
529 $curDate = date('YmdHis');
530 $clauses[] = "(end_date >= {$curDate} OR end_date IS NULL)";
534 $curDate = date('YmdHis');
535 $clauses[] = "(end_date >= {$curDate} OR end_date IS NULL)";
539 $this->_sortByCharacter
!== NULL
541 $clauses[] = "title LIKE '" . strtolower(CRM_Core_DAO
::escapeWildCardString($this->_sortByCharacter
)) . "%'";
544 $campaignIds = $this->get('campaign_id');
545 if (!CRM_Utils_System
::isNull($campaignIds)) {
546 if (!is_array($campaignIds)) {
547 $campaignIds = [$campaignIds];
549 $clauses[] = '( campaign_id IN ( ' . implode(' , ', array_values($campaignIds)) . ' ) )';
552 // don't do a the below assignment when doing a
555 if (count($clauses) > 1 ||
$eventsByDates) {
556 $this->assign('isSearch', 1);
559 $this->assign('isSearch', 0);
563 return !empty($clauses) ?
implode(' AND ', $clauses) : '(1)';
567 * @param $whereClause
568 * @param array $whereParams
570 public function pager($whereClause, $whereParams) {
572 $params['status'] = ts('Event %%StatusMessage%%');
573 $params['csvString'] = NULL;
574 $params['buttonTop'] = 'PagerTopButton';
575 $params['buttonBottom'] = 'PagerBottomButton';
576 $params['rowCount'] = $this->get(CRM_Utils_Pager
::PAGE_ROWCOUNT
);
577 if (!$params['rowCount']) {
578 $params['rowCount'] = Civi
::settings()->get('default_pager_size');
586 $params['total'] = CRM_Core_DAO
::singleValueQuery($query, $whereParams);
588 $this->_pager
= new CRM_Utils_Pager($params);
589 $this->assign_by_ref('pager', $this->_pager
);
593 * @param $whereClause
594 * @param array $whereParams
596 public function pagerAtoZ($whereClause, $whereParams) {
599 SELECT DISTINCT UPPER(LEFT(title, 1)) as sort_name
602 ORDER BY UPPER(LEFT(title, 1))
604 $dao = CRM_Core_DAO
::executeQuery($query, $whereParams);
606 $aToZBar = CRM_Utils_PagerAToZ
::getAToZBar($dao, $this->_sortByCharacter
, TRUE);
607 $this->assign('aToZ', $aToZBar);