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