Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
19 | * Page for displaying list of events | |
20 | */ | |
21 | class CRM_Event_Page_ManageEvent extends CRM_Core_Page { | |
22 | ||
23 | /** | |
fe482240 | 24 | * The action links that we need to display for the browse screen. |
6a488035 TO |
25 | * |
26 | * @var array | |
6a488035 | 27 | */ |
90b461f1 | 28 | public static $_actionLinks = NULL; |
6a488035 | 29 | |
8e7d26e4 MWMC |
30 | /** |
31 | * The event links to display for the browse screen. | |
32 | * @var array | |
33 | */ | |
90b461f1 | 34 | public static $_eventLinks = NULL; |
8e7d26e4 | 35 | |
90b461f1 | 36 | public static $_links = NULL; |
6a488035 | 37 | |
90b461f1 | 38 | public static $_tabLinks = NULL; |
d7d7d5ab | 39 | |
6a488035 TO |
40 | protected $_pager = NULL; |
41 | ||
42 | protected $_sortByCharacter; | |
43 | ||
44 | protected $_isTemplate = FALSE; | |
45 | ||
46 | /** | |
fe482240 | 47 | * Get action Links. |
6a488035 | 48 | * |
a6c01b45 CW |
49 | * @return array |
50 | * (reference) of action links | |
6a488035 | 51 | */ |
00be9182 | 52 | public function &links() { |
6a488035 TO |
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?'); | |
6a488035 | 56 | |
be2fb01f CW |
57 | self::$_actionLinks = [ |
58 | CRM_Core_Action::DISABLE => [ | |
6a488035 | 59 | 'name' => ts('Disable'), |
4d17a233 | 60 | 'ref' => 'crm-enable-disable', |
6a488035 | 61 | 'title' => ts('Disable Event'), |
be2fb01f CW |
62 | ], |
63 | CRM_Core_Action::ENABLE => [ | |
6a488035 | 64 | 'name' => ts('Enable'), |
4d17a233 | 65 | 'ref' => 'crm-enable-disable', |
6a488035 | 66 | 'title' => ts('Enable Event'), |
be2fb01f CW |
67 | ], |
68 | CRM_Core_Action::DELETE => [ | |
6a488035 TO |
69 | 'name' => ts('Delete'), |
70 | 'url' => CRM_Utils_System::currentPath(), | |
71 | 'qs' => 'action=delete&id=%%id%%', | |
6a488035 | 72 | 'title' => ts('Delete Event'), |
be2fb01f CW |
73 | ], |
74 | CRM_Core_Action::COPY => [ | |
6a488035 TO |
75 | 'name' => ts('Copy'), |
76 | 'url' => CRM_Utils_System::currentPath(), | |
77 | 'qs' => 'reset=1&action=copy&id=%%id%%', | |
78 | 'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"', | |
79 | 'title' => ts('Copy Event'), | |
be2fb01f CW |
80 | ], |
81 | ]; | |
6a488035 TO |
82 | } |
83 | return self::$_actionLinks; | |
84 | } | |
85 | ||
8e7d26e4 MWMC |
86 | public function eventLinks() { |
87 | if (!(self::$_eventLinks)) { | |
88 | self::$_eventLinks = [ | |
89 | 'register_participant' => [ | |
90 | 'name' => ts('Register Participant'), | |
91 | 'title' => ts('Register Participant'), | |
92 | 'url' => 'civicrm/participant/add', | |
93 | 'qs' => 'reset=1&action=add&context=standalone&eid=%%id%%', | |
94 | ], | |
95 | 'event_info' => [ | |
96 | 'name' => ts('Event Info'), | |
97 | 'title' => ts('Event Info'), | |
98 | 'url' => 'civicrm/event/info', | |
99 | 'qs' => 'reset=1&id=%%id%%', | |
100 | 'fe' => TRUE, | |
101 | ], | |
102 | 'online_registration_test' => [ | |
103 | 'name' => ts('Registration (Test-drive)'), | |
104 | 'title' => ts('Online Registration (Test-drive)'), | |
105 | 'url' => 'civicrm/event/register', | |
106 | 'qs' => 'reset=1&action=preview&id=%%id%%', | |
107 | 'fe' => TRUE, | |
108 | ], | |
109 | 'online_registration_live' => [ | |
110 | 'name' => ts('Registration (Live)'), | |
111 | 'title' => ts('Online Registration (Live)'), | |
112 | 'url' => 'civicrm/event/register', | |
113 | 'qs' => 'reset=1&id=%%id%%', | |
114 | 'fe' => TRUE, | |
115 | ], | |
116 | ]; | |
117 | } | |
118 | return self::$_eventLinks; | |
119 | } | |
120 | ||
d7d7d5ab | 121 | /** |
fe482240 | 122 | * Get tab Links for events. |
d7d7d5ab | 123 | * |
a6c01b45 CW |
124 | * @return array |
125 | * (reference) of tab links | |
b8f2a197 | 126 | * @throws \CiviCRM_API3_Exception |
d7d7d5ab | 127 | */ |
7fffa5fa | 128 | public static function &tabs() { |
b8f2a197 MW |
129 | // @todo Move to eventcart extension |
130 | // check if we're in shopping cart mode for events | |
131 | $enableCart = (bool) Civi::settings()->get('enable_cart'); | |
132 | ||
a2ff2331 | 133 | $cacheKey = $enableCart ? 1 : 0; |
d7d7d5ab | 134 | if (!(self::$_tabLinks)) { |
be2fb01f | 135 | self::$_tabLinks = []; |
a2ff2331 TO |
136 | } |
137 | if (!isset(self::$_tabLinks[$cacheKey])) { | |
608e6658 | 138 | self::$_tabLinks[$cacheKey]['settings'] |
be2fb01f | 139 | = [ |
d7d7d5ab | 140 | 'title' => ts('Info and Settings'), |
141 | 'url' => 'civicrm/event/manage/settings', | |
21dfd5f5 | 142 | 'field' => 'id', |
be2fb01f | 143 | ]; |
608e6658 | 144 | self::$_tabLinks[$cacheKey]['location'] |
be2fb01f | 145 | = [ |
d7d7d5ab | 146 | 'title' => ts('Location'), |
147 | 'url' => 'civicrm/event/manage/location', | |
a215a5b0 | 148 | 'field' => 'loc_block_id', |
be2fb01f | 149 | ]; |
209989e3 | 150 | |
608e6658 | 151 | self::$_tabLinks[$cacheKey]['fee'] |
be2fb01f | 152 | = [ |
d7d7d5ab | 153 | 'title' => ts('Fees'), |
154 | 'url' => 'civicrm/event/manage/fee', | |
155 | 'field' => 'is_monetary', | |
be2fb01f | 156 | ]; |
608e6658 | 157 | self::$_tabLinks[$cacheKey]['registration'] |
be2fb01f | 158 | = [ |
d7d7d5ab | 159 | 'title' => ts('Online Registration'), |
160 | 'url' => 'civicrm/event/manage/registration', | |
161 | 'field' => 'is_online_registration', | |
be2fb01f | 162 | ]; |
608e6658 | 163 | |
cfbfd406 MWMC |
164 | // @fixme I don't understand the event permissions check here - can we just get rid of it? |
165 | $permissions = CRM_Event_BAO_Event::getAllPermissions(); | |
755a1835 | 166 | if (CRM_Core_Permission::check('administer CiviCRM data') || !empty($permissions[CRM_Core_Permission::EDIT])) { |
608e6658 | 167 | self::$_tabLinks[$cacheKey]['reminder'] |
be2fb01f | 168 | = [ |
353ffa53 TO |
169 | 'title' => ts('Schedule Reminders'), |
170 | 'url' => 'civicrm/event/manage/reminder', | |
171 | 'field' => 'reminder', | |
be2fb01f | 172 | ]; |
209989e3 | 173 | } |
608e6658 | 174 | self::$_tabLinks[$cacheKey]['conference'] |
be2fb01f | 175 | = [ |
d7d7d5ab | 176 | 'title' => ts('Conference Slots'), |
177 | 'url' => 'civicrm/event/manage/conference', | |
178 | 'field' => 'slot_label_id', | |
be2fb01f | 179 | ]; |
608e6658 | 180 | self::$_tabLinks[$cacheKey]['friend'] |
be2fb01f | 181 | = [ |
d7d7d5ab | 182 | 'title' => ts('Tell a Friend'), |
183 | 'url' => 'civicrm/event/manage/friend', | |
184 | 'field' => 'friend', | |
be2fb01f | 185 | ]; |
608e6658 | 186 | self::$_tabLinks[$cacheKey]['pcp'] |
be2fb01f | 187 | = [ |
d7d7d5ab | 188 | 'title' => ts('Personal Campaign Pages'), |
189 | 'url' => 'civicrm/event/manage/pcp', | |
190 | 'field' => 'is_pcp_enabled', | |
be2fb01f | 191 | ]; |
608e6658 | 192 | self::$_tabLinks[$cacheKey]['repeat'] |
be2fb01f | 193 | = [ |
6063a2f1 | 194 | 'title' => ts('Repeat'), |
195 | 'url' => 'civicrm/event/manage/repeat', | |
72c67af6 | 196 | 'field' => 'is_repeating_event', |
be2fb01f | 197 | ]; |
d7d7d5ab | 198 | } |
199 | ||
200 | if (!$enableCart) { | |
a2ff2331 | 201 | unset(self::$_tabLinks[$cacheKey]['conference']); |
d7d7d5ab | 202 | } |
203 | ||
be2fb01f | 204 | CRM_Utils_Hook::tabset('civicrm/event/manage', self::$_tabLinks[$cacheKey], []); |
a2ff2331 | 205 | return self::$_tabLinks[$cacheKey]; |
d7d7d5ab | 206 | } |
207 | ||
6a488035 TO |
208 | /** |
209 | * Run the page. | |
210 | * | |
211 | * This method is called after the page is created. It checks for the | |
212 | * type of action and executes that action. | |
213 | * Finally it calls the parent's run method. | |
214 | * | |
215 | * @return void | |
6a488035 | 216 | */ |
00be9182 | 217 | public function run() { |
6a488035 TO |
218 | // get the requested action |
219 | $action = CRM_Utils_Request::retrieve('action', 'String', | |
220 | // default to 'browse' | |
221 | $this, FALSE, 'browse' | |
222 | ); | |
223 | ||
224 | // assign vars to templates | |
225 | $this->assign('action', $action); | |
679bd095 | 226 | $this->assign('iCal', CRM_Event_BAO_Event::getICalLinks()); |
6a488035 TO |
227 | $id = CRM_Utils_Request::retrieve('id', 'Positive', |
228 | $this, FALSE, 0, 'REQUEST' | |
229 | ); | |
230 | ||
231 | // figure out whether we’re handling an event or an event template | |
232 | if ($id) { | |
233 | $this->_isTemplate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $id, 'is_template'); | |
234 | } | |
235 | elseif ($action & CRM_Core_Action::ADD) { | |
236 | $this->_isTemplate = CRM_Utils_Request::retrieve('is_template', 'Boolean', $this); | |
237 | } | |
238 | ||
239 | if (!$this->_isTemplate && $id) { | |
be2fb01f CW |
240 | $breadCrumb = [ |
241 | [ | |
6ea503d4 | 242 | 'title' => ts('Manage Events'), |
6a488035 | 243 | 'url' => CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'), |
be2fb01f CW |
244 | ], |
245 | ]; | |
6a488035 TO |
246 | CRM_Utils_System::appendBreadCrumb($breadCrumb); |
247 | } | |
248 | ||
249 | // what action to take ? | |
250 | if ($action & CRM_Core_Action::DELETE) { | |
251 | $session = CRM_Core_Session::singleton(); | |
252 | $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1&action=browse')); | |
253 | $controller = new CRM_Core_Controller_Simple('CRM_Event_Form_ManageEvent_Delete', | |
254 | 'Delete Event', | |
255 | $action | |
256 | ); | |
257 | $controller->set('id', $id); | |
258 | $controller->process(); | |
259 | return $controller->run(); | |
260 | } | |
261 | elseif ($action & CRM_Core_Action::COPY) { | |
262 | $this->copy(); | |
263 | } | |
264 | ||
265 | // finally browse the custom groups | |
266 | $this->browse(); | |
267 | ||
268 | // parent run | |
269 | return parent::run(); | |
270 | } | |
271 | ||
272 | /** | |
fe482240 | 273 | * Browse all events. |
6a488035 TO |
274 | * |
275 | * @return void | |
276 | */ | |
00be9182 | 277 | public function browse() { |
734b09fb CW |
278 | Civi::resources()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header'); |
279 | ||
6a488035 TO |
280 | $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', |
281 | 'String', | |
282 | $this | |
283 | ); | |
284 | $createdId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE, 0); | |
285 | if (strtolower($this->_sortByCharacter) == 'all' || | |
286 | !empty($_POST) | |
287 | ) { | |
288 | $this->_sortByCharacter = ''; | |
289 | $this->set('sortByCharacter', ''); | |
290 | } | |
291 | ||
292 | $this->_force = $this->_searchResult = NULL; | |
293 | ||
294 | $this->search(); | |
295 | ||
be2fb01f | 296 | $params = []; |
6a488035 TO |
297 | $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', |
298 | $this, FALSE | |
299 | ); | |
300 | $this->_searchResult = CRM_Utils_Request::retrieve('searchResult', 'Boolean', $this); | |
301 | ||
302 | $whereClause = $this->whereClause($params, FALSE, $this->_force); | |
14aa9e92 | 303 | |
304 | if (CRM_Core_Config::singleton()->includeAlphabeticalPager) { | |
305 | $this->pagerAToZ($whereClause, $params); | |
306 | } | |
6a488035 | 307 | |
be2fb01f | 308 | $params = []; |
6a488035 TO |
309 | $whereClause = $this->whereClause($params, TRUE, $this->_force); |
310 | // because is_template != 1 would be to simple | |
311 | $whereClause .= ' AND (is_template = 0 OR is_template IS NULL)'; | |
312 | ||
313 | $this->pager($whereClause, $params); | |
314 | ||
315 | list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount(); | |
316 | ||
317 | // get all custom groups sorted by weight | |
be2fb01f | 318 | $manageEvent = []; |
6a488035 TO |
319 | |
320 | $query = " | |
321 | SELECT * | |
322 | FROM civicrm_event | |
323 | WHERE $whereClause | |
324 | ORDER BY start_date desc | |
325 | LIMIT $offset, $rowCount"; | |
326 | ||
327 | $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Event_DAO_Event'); | |
c3ce9c2b | 328 | $permittedEventsByAction = CRM_Event_BAO_Event::getAllPermissions(); |
6a488035 TO |
329 | |
330 | //get all campaigns. | |
331 | $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); | |
332 | ||
333 | // get the list of active event pcps | |
be2fb01f | 334 | $eventPCPS = []; |
6a488035 | 335 | |
a130e045 | 336 | $pcpDao = new CRM_PCP_DAO_PCPBlock(); |
6a488035 TO |
337 | $pcpDao->entity_table = 'civicrm_event'; |
338 | $pcpDao->find(); | |
339 | ||
340 | while ($pcpDao->fetch()) { | |
341 | $eventPCPS[$pcpDao->entity_id] = $pcpDao->entity_id; | |
342 | } | |
be2fb01f | 343 | $mapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings([ |
46f5566c | 344 | 'id' => CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID, |
be2fb01f | 345 | ])); |
14c89ba8 | 346 | $eventType = CRM_Core_OptionGroup::values('event_type'); |
6a488035 | 347 | while ($dao->fetch()) { |
c3ce9c2b | 348 | if (in_array($dao->id, $permittedEventsByAction[CRM_Core_Permission::VIEW])) { |
b03d1057 EM |
349 | $manageEvent[$dao->id] = [ |
350 | // Set defaults to prevent smarty e-notices, will be overwritten if populated. | |
351 | 'city' => '', | |
352 | 'state_province' => '', | |
353 | 'end_date' => '', | |
354 | 'loc_block_id' => '', | |
355 | 'participant_listing_id' => '', | |
356 | ]; | |
04374d9d | 357 | $repeat = CRM_Core_BAO_RecurringEntity::getPositionAndCount($dao->id, 'civicrm_event'); |
62933949 | 358 | $manageEvent[$dao->id]['repeat'] = ''; |
04374d9d | 359 | if ($repeat) { |
be2fb01f | 360 | $manageEvent[$dao->id]['repeat'] = ts('Repeating (%1 of %2)', [1 => $repeat[0], 2 => $repeat[1]]); |
62933949 | 361 | } |
6a488035 TO |
362 | CRM_Core_DAO::storeValues($dao, $manageEvent[$dao->id]); |
363 | ||
364 | // form all action links | |
365 | $action = array_sum(array_keys($this->links())); | |
366 | ||
367 | if ($dao->is_active) { | |
368 | $action -= CRM_Core_Action::ENABLE; | |
369 | } | |
370 | else { | |
371 | $action -= CRM_Core_Action::DISABLE; | |
372 | } | |
373 | ||
c3ce9c2b | 374 | if (!in_array($dao->id, $permittedEventsByAction[CRM_Core_Permission::DELETE])) { |
6a488035 TO |
375 | $action -= CRM_Core_Action::DELETE; |
376 | } | |
c3ce9c2b | 377 | if (!in_array($dao->id, $permittedEventsByAction[CRM_Core_Permission::EDIT])) { |
6a488035 TO |
378 | $action -= CRM_Core_Action::UPDATE; |
379 | } | |
380 | ||
8e7d26e4 MWMC |
381 | $eventLinks = self::eventLinks(); |
382 | if (!CRM_Core_Permission::check('edit event participants')) { | |
383 | unset($eventLinks['register_participant']); | |
384 | } | |
385 | ||
386 | $manageEvent[$dao->id]['eventlinks'] = CRM_Core_Action::formLink($eventLinks, | |
387 | NULL, | |
be2fb01f | 388 | ['id' => $dao->id], |
8e7d26e4 MWMC |
389 | ts('Event Links'), |
390 | TRUE, | |
391 | 'event.manage.eventlinks', | |
392 | 'Event', | |
393 | $dao->id | |
394 | ); | |
6a488035 TO |
395 | $manageEvent[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), |
396 | $action, | |
be2fb01f | 397 | ['id' => $dao->id], |
6a488035 | 398 | ts('more'), |
87dab4a4 AH |
399 | TRUE, |
400 | 'event.manage.list', | |
401 | 'Event', | |
402 | $dao->id | |
6a488035 TO |
403 | ); |
404 | ||
be2fb01f | 405 | $params = [ |
6a488035 TO |
406 | 'entity_id' => $dao->id, |
407 | 'entity_table' => 'civicrm_event', | |
408 | 'is_active' => 1, | |
be2fb01f | 409 | ]; |
6a488035 TO |
410 | |
411 | $defaults['location'] = CRM_Core_BAO_Location::getValues($params, TRUE); | |
412 | ||
413 | $manageEvent[$dao->id]['friend'] = CRM_Friend_BAO_Friend::getValues($params); | |
414 | ||
415 | if (isset($defaults['location']['address'][1]['city'])) { | |
416 | $manageEvent[$dao->id]['city'] = $defaults['location']['address'][1]['city']; | |
417 | } | |
418 | if (isset($defaults['location']['address'][1]['state_province_id'])) { | |
419 | $manageEvent[$dao->id]['state_province'] = CRM_Core_PseudoConstant::stateProvince($defaults['location']['address'][1]['state_province_id']); | |
420 | } | |
421 | ||
422 | //show campaigns on selector. | |
9c1bc317 | 423 | $manageEvent[$dao->id]['campaign'] = $allCampaigns[$dao->campaign_id] ?? NULL; |
9e1bf145 | 424 | $manageEvent[$dao->id]['reminder'] = CRM_Core_BAO_ActionSchedule::isConfigured($dao->id, $mapping->getId()); |
9c1bc317 CW |
425 | $manageEvent[$dao->id]['is_pcp_enabled'] = $eventPCPS[$dao->id] ?? NULL; |
426 | $manageEvent[$dao->id]['event_type'] = $eventType[$manageEvent[$dao->id]['event_type_id']] ?? NULL; | |
985f92a3 | 427 | $manageEvent[$dao->id]['is_repeating_event'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_RecurringEntity', $dao->id, 'parent_id', 'entity_id'); |
a215a5b0 | 428 | // allow hooks to set 'field' value which allows configuration pop-up to show a tab as enabled/disabled |
be2fb01f | 429 | CRM_Utils_Hook::tabset('civicrm/event/manage/rows', $manageEvent, ['event_id' => $dao->id]); |
6a488035 TO |
430 | } |
431 | } | |
14c89ba8 | 432 | |
b8f2a197 | 433 | $manageEvent['tab'] = self::tabs(); |
6a488035 TO |
434 | $this->assign('rows', $manageEvent); |
435 | ||
7218b8a8 | 436 | $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1', 'label'); |
437 | $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0', 'label'); | |
6a488035 TO |
438 | $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes)); |
439 | $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending)); | |
440 | $this->assign('findParticipants', $findParticipants); | |
6a488035 TO |
441 | } |
442 | ||
443 | /** | |
dc195289 | 444 | * make a copy of a Event, including |
6a488035 TO |
445 | * all the fields in the event wizard |
446 | * | |
447 | * @return void | |
ae70f47e | 448 | * @throws \CRM_Core_Exception |
6a488035 | 449 | */ |
00be9182 | 450 | public function copy() { |
6a488035 TO |
451 | $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE, 0, 'GET'); |
452 | ||
453 | $urlString = 'civicrm/event/manage'; | |
454 | $copyEvent = CRM_Event_BAO_Event::copy($id); | |
455 | $urlParams = 'reset=1'; | |
456 | // Redirect to Copied Event Configuration | |
457 | if ($copyEvent->id) { | |
458 | $urlString = 'civicrm/event/manage/settings'; | |
459 | $urlParams .= '&action=update&id=' . $copyEvent->id; | |
460 | } | |
461 | ||
462 | return CRM_Utils_System::redirect(CRM_Utils_System::url($urlString, $urlParams)); | |
463 | } | |
464 | ||
00be9182 | 465 | public function search() { |
608e6658 | 466 | if (isset($this->_action) & (CRM_Core_Action::ADD | |
6a488035 TO |
467 | CRM_Core_Action::UPDATE | |
468 | CRM_Core_Action::DELETE | |
469 | ) | |
470 | ) { | |
471 | return; | |
472 | } | |
473 | ||
474 | $form = new CRM_Core_Controller_Simple('CRM_Event_Form_SearchEvent', ts('Search Events'), CRM_Core_Action::ADD); | |
475 | $form->setEmbedded(TRUE); | |
476 | $form->setParent($this); | |
477 | $form->process(); | |
478 | $form->run(); | |
479 | } | |
480 | ||
0cf587a7 | 481 | /** |
c490a46a | 482 | * @param array $params |
0cf587a7 EM |
483 | * @param bool $sortBy |
484 | * @param $force | |
485 | * | |
486 | * @return string | |
487 | */ | |
b0e06ce4 | 488 | public function whereClause(&$params, $sortBy, $force) { |
be2fb01f CW |
489 | $values = []; |
490 | $clauses = []; | |
353ffa53 | 491 | $title = $this->get('title'); |
6a488035 TO |
492 | $createdId = $this->get('cid'); |
493 | ||
494 | if ($createdId) { | |
495 | $clauses[] = "(created_id = {$createdId})"; | |
496 | } | |
497 | ||
498 | if ($title) { | |
499 | $clauses[] = "title LIKE %1"; | |
500 | if (strpos($title, '%') !== FALSE) { | |
be2fb01f | 501 | $params[1] = [trim($title), 'String', FALSE]; |
6a488035 TO |
502 | } |
503 | else { | |
be2fb01f | 504 | $params[1] = [trim($title), 'String', TRUE]; |
6a488035 TO |
505 | } |
506 | } | |
507 | ||
508 | $value = $this->get('event_type_id'); | |
6a488035 TO |
509 | if ($value) { |
510 | if (is_array($value)) { | |
157e9eb6 | 511 | $type = implode(',', $value); |
6a488035 | 512 | } |
a612c2a8 SL |
513 | $clauses[] = "event_type_id IN (%2)"; |
514 | $params[2] = [$type, 'String']; | |
6a488035 TO |
515 | } |
516 | ||
517 | $eventsByDates = $this->get('eventsByDates'); | |
518 | if ($this->_searchResult) { | |
519 | if ($eventsByDates) { | |
520 | ||
521 | $from = $this->get('start_date'); | |
522 | if (!CRM_Utils_System::isNull($from)) { | |
10d005d9 | 523 | $clauses[] = '( end_date >= %3 OR end_date IS NULL )'; |
be2fb01f | 524 | $params[3] = [$from, 'String']; |
6a488035 TO |
525 | } |
526 | ||
527 | $to = $this->get('end_date'); | |
528 | if (!CRM_Utils_System::isNull($to)) { | |
10d005d9 | 529 | $clauses[] = '( start_date <= %4 OR start_date IS NULL )'; |
be2fb01f | 530 | $params[4] = [$to, 'String']; |
6a488035 TO |
531 | } |
532 | } | |
533 | else { | |
534 | $curDate = date('YmdHis'); | |
5836c35a | 535 | $clauses[] = "(end_date >= {$curDate} OR end_date IS NULL)"; |
6a488035 TO |
536 | } |
537 | } | |
538 | else { | |
539 | $curDate = date('YmdHis'); | |
540 | $clauses[] = "(end_date >= {$curDate} OR end_date IS NULL)"; | |
541 | } | |
542 | ||
543 | if ($sortBy && | |
544 | $this->_sortByCharacter !== NULL | |
545 | ) { | |
546 | $clauses[] = "title LIKE '" . strtolower(CRM_Core_DAO::escapeWildCardString($this->_sortByCharacter)) . "%'"; | |
547 | } | |
548 | ||
e070961b | 549 | $campaignIds = $this->get('campaign_id'); |
550 | if (!CRM_Utils_System::isNull($campaignIds)) { | |
551 | if (!is_array($campaignIds)) { | |
be2fb01f | 552 | $campaignIds = [$campaignIds]; |
6a488035 | 553 | } |
e070961b | 554 | $clauses[] = '( campaign_id IN ( ' . implode(' , ', array_values($campaignIds)) . ' ) )'; |
6a488035 TO |
555 | } |
556 | ||
d7d7d5ab | 557 | // don't do a the below assignment when doing a |
6a488035 TO |
558 | // AtoZ pager clause |
559 | if ($sortBy) { | |
560 | if (count($clauses) > 1 || $eventsByDates) { | |
561 | $this->assign('isSearch', 1); | |
562 | } | |
563 | else { | |
564 | $this->assign('isSearch', 0); | |
565 | } | |
566 | } | |
567 | ||
568 | return !empty($clauses) ? implode(' AND ', $clauses) : '(1)'; | |
569 | } | |
570 | ||
0cf587a7 EM |
571 | /** |
572 | * @param $whereClause | |
100fef9d | 573 | * @param array $whereParams |
0cf587a7 | 574 | */ |
00be9182 | 575 | public function pager($whereClause, $whereParams) { |
6a488035 TO |
576 | |
577 | $params['status'] = ts('Event %%StatusMessage%%'); | |
578 | $params['csvString'] = NULL; | |
579 | $params['buttonTop'] = 'PagerTopButton'; | |
580 | $params['buttonBottom'] = 'PagerBottomButton'; | |
581 | $params['rowCount'] = $this->get(CRM_Utils_Pager::PAGE_ROWCOUNT); | |
582 | if (!$params['rowCount']) { | |
7fa7c084 | 583 | $params['rowCount'] = Civi::settings()->get('default_pager_size'); |
6a488035 TO |
584 | } |
585 | ||
586 | $query = " | |
587 | SELECT count(id) | |
588 | FROM civicrm_event | |
589 | WHERE $whereClause"; | |
590 | ||
591 | $params['total'] = CRM_Core_DAO::singleValueQuery($query, $whereParams); | |
592 | ||
593 | $this->_pager = new CRM_Utils_Pager($params); | |
594 | $this->assign_by_ref('pager', $this->_pager); | |
595 | } | |
596 | ||
0cf587a7 EM |
597 | /** |
598 | * @param $whereClause | |
100fef9d | 599 | * @param array $whereParams |
0cf587a7 | 600 | */ |
00be9182 | 601 | public function pagerAtoZ($whereClause, $whereParams) { |
6a488035 TO |
602 | |
603 | $query = " | |
604 | SELECT DISTINCT UPPER(LEFT(title, 1)) as sort_name | |
605 | FROM civicrm_event | |
606 | WHERE $whereClause | |
bad98dd5 | 607 | ORDER BY UPPER(LEFT(title, 1)) |
6a488035 TO |
608 | "; |
609 | $dao = CRM_Core_DAO::executeQuery($query, $whereParams); | |
610 | ||
611 | $aToZBar = CRM_Utils_PagerAToZ::getAToZBar($dao, $this->_sortByCharacter, TRUE); | |
612 | $this->assign('aToZ', $aToZBar); | |
613 | } | |
96025800 | 614 | |
6a488035 | 615 | } |