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