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