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