3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * Page for displaying list of events
39 class CRM_Event_Page_ManageEvent
extends CRM_Core_Page
{
42 * The action links that we need to display for the browse screen
46 static $_actionLinks = NULL;
48 static $_links = NULL;
50 static $_tabLinks = NULL;
52 protected $_pager = NULL;
54 protected $_sortByCharacter;
56 protected $_isTemplate = FALSE;
62 * (reference) of action links
64 public function &links() {
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?');
70 self
::$_actionLinks = array(
71 CRM_Core_Action
::DISABLE
=> array(
72 'name' => ts('Disable'),
73 'ref' => 'crm-enable-disable',
74 'title' => ts('Disable Event'),
76 CRM_Core_Action
::ENABLE
=> array(
77 'name' => ts('Enable'),
78 'ref' => 'crm-enable-disable',
79 'title' => ts('Enable Event'),
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'),
88 CRM_Core_Action
::COPY
=> array(
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'),
97 return self
::$_actionLinks;
101 * Get tab Links for events
106 * (reference) of tab links
108 public static function &tabs($enableCart) {
109 $cacheKey = $enableCart ?
1 : 0;
110 if (!(self
::$_tabLinks)) {
111 self
::$_tabLinks = array();
113 if (!isset(self
::$_tabLinks[$cacheKey])) {
114 self
::$_tabLinks[$cacheKey]['settings'] =
116 'title' => ts('Info and Settings'),
117 'url' => 'civicrm/event/manage/settings',
120 self
::$_tabLinks[$cacheKey]['location'] =
122 'title' => ts('Location'),
123 'url' => 'civicrm/event/manage/location',
124 'field' => 'loc_block_id',
127 self
::$_tabLinks[$cacheKey]['fee'] =
129 'title' => ts('Fees'),
130 'url' => 'civicrm/event/manage/fee',
131 'field' => 'is_monetary',
133 self
::$_tabLinks[$cacheKey]['registration'] =
135 'title' => ts('Online Registration'),
136 'url' => 'civicrm/event/manage/registration',
137 'field' => 'is_online_registration',
139 if (CRM_Core_Permission
::check('administer CiviCRM')) {
140 self
::$_tabLinks[$cacheKey]['reminder'] =
142 'title' => ts('Schedule Reminders'),
143 'url' => 'civicrm/event/manage/reminder',
144 'field' => 'reminder',
147 self
::$_tabLinks[$cacheKey]['conference'] =
149 'title' => ts('Conference Slots'),
150 'url' => 'civicrm/event/manage/conference',
151 'field' => 'slot_label_id',
153 self
::$_tabLinks[$cacheKey]['friend'] =
155 'title' => ts('Tell a Friend'),
156 'url' => 'civicrm/event/manage/friend',
159 self
::$_tabLinks[$cacheKey]['pcp'] =
161 'title' => ts('Personal Campaign Pages'),
162 'url' => 'civicrm/event/manage/pcp',
163 'field' => 'is_pcp_enabled',
165 self
::$_tabLinks[$cacheKey]['repeat'] =
167 'title' => ts('Repeat'),
168 'url' => 'civicrm/event/manage/repeat',
169 'field' => 'is_repeating_event',
175 unset(self
::$_tabLinks[$cacheKey]['conference']);
178 CRM_Utils_Hook
::tabset('civicrm/event/manage', self
::$_tabLinks[$cacheKey], array());
179 return self
::$_tabLinks[$cacheKey];
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.
191 public function run() {
192 // get the requested action
193 $action = CRM_Utils_Request
::retrieve('action', 'String',
194 // default to 'browse'
195 $this, FALSE, 'browse'
198 // assign vars to templates
199 $this->assign('action', $action);
200 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
201 $this, FALSE, 0, 'REQUEST'
204 // figure out whether we’re handling an event or an event template
206 $this->_isTemplate
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $id, 'is_template');
208 elseif ($action & CRM_Core_Action
::ADD
) {
209 $this->_isTemplate
= CRM_Utils_Request
::retrieve('is_template', 'Boolean', $this);
212 if (!$this->_isTemplate
&& $id) {
215 'title' => ts('Manage Events'),
216 'url' => CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'),
219 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
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',
230 $controller->set('id', $id);
231 $controller->process();
232 return $controller->run();
234 elseif ($action & CRM_Core_Action
::COPY
) {
238 // finally browse the custom groups
242 return parent
::run();
250 public function browse() {
251 $this->assign('includeWysiwygEditor', TRUE);
252 $this->_sortByCharacter
= CRM_Utils_Request
::retrieve('sortByCharacter',
256 $createdId = CRM_Utils_Request
::retrieve('cid', 'Positive', $this, FALSE, 0);
257 if (strtolower($this->_sortByCharacter
) == 'all' ||
260 $this->_sortByCharacter
= '';
261 $this->set('sortByCharacter', '');
264 $this->_force
= $this->_searchResult
= NULL;
269 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean',
272 $this->_searchResult
= CRM_Utils_Request
::retrieve('searchResult', 'Boolean', $this);
274 $whereClause = $this->whereClause($params, FALSE, $this->_force
);
275 $this->pagerAToZ($whereClause, $params);
278 $whereClause = $this->whereClause($params, TRUE, $this->_force
);
279 // because is_template != 1 would be to simple
280 $whereClause .= ' AND (is_template = 0 OR is_template IS NULL)';
282 $this->pager($whereClause, $params);
284 list($offset, $rowCount) = $this->_pager
->getOffsetAndRowCount();
286 // get all custom groups sorted by weight
287 $manageEvent = array();
293 ORDER BY start_date desc
294 LIMIT $offset, $rowCount";
296 $dao = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Event_DAO_Event');
297 $permissions = CRM_Event_BAO_Event
::checkPermission();
300 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
302 // get the list of active event pcps
303 $eventPCPS = array();
305 $pcpDao = new CRM_PCP_DAO_PCPBlock();
306 $pcpDao->entity_table
= 'civicrm_event';
309 while ($pcpDao->fetch()) {
310 $eventPCPS[$pcpDao->entity_id
] = $pcpDao->entity_id
;
312 // check if we're in shopping cart mode for events
313 $enableCart = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::EVENT_PREFERENCES_NAME
,
316 $this->assign('eventCartEnabled', $enableCart);
317 $mappingID = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_ActionMapping', 'civicrm_event', 'id', 'entity_value');
318 $eventType = CRM_Core_OptionGroup
::values('event_type');
319 while ($dao->fetch()) {
320 if (in_array($dao->id
, $permissions[CRM_Core_Permission
::VIEW
])) {
321 $manageEvent[$dao->id
] = array();
322 $isRecurringEvent = CRM_Core_BAO_RecurringEntity
::getParentFor($dao->id
, 'civicrm_event');
323 $manageEvent[$dao->id
]['repeat'] = '';
324 if ($isRecurringEvent) {
325 if ($dao->id
== $isRecurringEvent) {
326 $manageEvent[$dao->id
]['repeat'] = 'Recurring Event - (Parent)';
329 $manageEvent[$dao->id
]['repeat'] = 'Recurring Event - (Child)';
332 CRM_Core_DAO
::storeValues($dao, $manageEvent[$dao->id
]);
334 // form all action links
335 $action = array_sum(array_keys($this->links()));
337 if ($dao->is_active
) {
338 $action -= CRM_Core_Action
::ENABLE
;
341 $action -= CRM_Core_Action
::DISABLE
;
344 if (!in_array($dao->id
, $permissions[CRM_Core_Permission
::DELETE
])) {
345 $action -= CRM_Core_Action
::DELETE
;
347 if (!in_array($dao->id
, $permissions[CRM_Core_Permission
::EDIT
])) {
348 $action -= CRM_Core_Action
::UPDATE
;
351 $manageEvent[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::links(),
353 array('id' => $dao->id
),
362 'entity_id' => $dao->id
,
363 'entity_table' => 'civicrm_event',
367 $defaults['location'] = CRM_Core_BAO_Location
::getValues($params, TRUE);
369 $manageEvent[$dao->id
]['friend'] = CRM_Friend_BAO_Friend
::getValues($params);
371 if (isset($defaults['location']['address'][1]['city'])) {
372 $manageEvent[$dao->id
]['city'] = $defaults['location']['address'][1]['city'];
374 if (isset($defaults['location']['address'][1]['state_province_id'])) {
375 $manageEvent[$dao->id
]['state_province'] = CRM_Core_PseudoConstant
::stateProvince($defaults['location']['address'][1]['state_province_id']);
378 //show campaigns on selector.
379 $manageEvent[$dao->id
]['campaign'] = CRM_Utils_Array
::value($dao->campaign_id
, $allCampaigns);
380 $manageEvent[$dao->id
]['reminder'] = CRM_Core_BAO_ActionSchedule
::isConfigured($dao->id
, $mappingID);
381 $manageEvent[$dao->id
]['is_pcp_enabled'] = CRM_Utils_Array
::value($dao->id
, $eventPCPS);
382 $manageEvent[$dao->id
]['event_type'] = CRM_Utils_Array
::value($manageEvent[$dao->id
]['event_type_id'], $eventType);
383 $manageEvent[$dao->id
]['is_repeating_event'] = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_RecurringEntity', $dao->id
, 'parent_id', 'entity_id');
384 // allow hooks to set 'field' value which allows configuration pop-up to show a tab as enabled/disabled
385 CRM_Utils_Hook
::tabset('civicrm/event/manage/rows', $manageEvent, array('event_id' => $dao->id
));
389 $manageEvent['tab'] = self
::tabs($enableCart);
390 $this->assign('rows', $manageEvent);
392 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
393 $statusTypesPending = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0');
394 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
395 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
396 $this->assign('findParticipants', $findParticipants);
400 * make a copy of a Event, including
401 * all the fields in the event wizard
405 public function copy() {
406 $id = CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE, 0, 'GET');
408 $urlString = 'civicrm/event/manage';
409 $copyEvent = CRM_Event_BAO_Event
::copy($id);
410 $urlParams = 'reset=1';
411 // Redirect to Copied Event Configuration
412 if ($copyEvent->id
) {
413 $urlString = 'civicrm/event/manage/settings';
414 $urlParams .= '&action=update&id=' . $copyEvent->id
;
417 return CRM_Utils_System
::redirect(CRM_Utils_System
::url($urlString, $urlParams));
420 public function search() {
421 if (isset($this->_action
) &
422 (CRM_Core_Action
::ADD |
423 CRM_Core_Action
::UPDATE |
424 CRM_Core_Action
::DELETE
430 $form = new CRM_Core_Controller_Simple('CRM_Event_Form_SearchEvent', ts('Search Events'), CRM_Core_Action
::ADD
);
431 $form->setEmbedded(TRUE);
432 $form->setParent($this);
438 * @param array $params
439 * @param bool $sortBy
444 public function whereClause(&$params, $sortBy = TRUE, $force) {
447 $title = $this->get('title');
448 $createdId = $this->get('cid');
451 $clauses[] = "(created_id = {$createdId})";
455 $clauses[] = "title LIKE %1";
456 if (strpos($title, '%') !== FALSE) {
457 $params[1] = array(trim($title), 'String', FALSE);
460 $params[1] = array(trim($title), 'String', TRUE);
464 $value = $this->get('event_type_id');
467 if (is_array($value)) {
468 foreach ($value as $k => $v) {
473 $type = implode(',', $val);
475 $clauses[] = "event_type_id IN ({$type})";
478 $eventsByDates = $this->get('eventsByDates');
479 if ($this->_searchResult
) {
480 if ($eventsByDates) {
482 $from = $this->get('start_date');
483 if (!CRM_Utils_System
::isNull($from)) {
484 $clauses[] = '( start_date >= %3 OR start_date IS NULL )';
485 $params[3] = array($from, 'String');
488 $to = $this->get('end_date');
489 if (!CRM_Utils_System
::isNull($to)) {
490 $clauses[] = '( end_date <= %4 OR end_date IS NULL )';
491 $params[4] = array($to, 'String');
495 $curDate = date('YmdHis');
496 $clauses[5] = "(end_date >= {$curDate} OR end_date IS NULL)";
500 $curDate = date('YmdHis');
501 $clauses[] = "(end_date >= {$curDate} OR end_date IS NULL)";
505 $this->_sortByCharacter
!== NULL
507 $clauses[] = "title LIKE '" . strtolower(CRM_Core_DAO
::escapeWildCardString($this->_sortByCharacter
)) . "%'";
510 $campaignIds = $this->get('campaign_id');
511 if (!CRM_Utils_System
::isNull($campaignIds)) {
512 if (!is_array($campaignIds)) {
513 $campaignIds = array($campaignIds);
515 $clauses[] = '( campaign_id IN ( ' . implode(' , ', array_values($campaignIds)) . ' ) )';
518 // don't do a the below assignment when doing a
521 if (count($clauses) > 1 ||
$eventsByDates) {
522 $this->assign('isSearch', 1);
525 $this->assign('isSearch', 0);
529 return !empty($clauses) ?
implode(' AND ', $clauses) : '(1)';
533 * @param $whereClause
534 * @param array $whereParams
536 public function pager($whereClause, $whereParams) {
538 $params['status'] = ts('Event %%StatusMessage%%');
539 $params['csvString'] = NULL;
540 $params['buttonTop'] = 'PagerTopButton';
541 $params['buttonBottom'] = 'PagerBottomButton';
542 $params['rowCount'] = $this->get(CRM_Utils_Pager
::PAGE_ROWCOUNT
);
543 if (!$params['rowCount']) {
544 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
552 $params['total'] = CRM_Core_DAO
::singleValueQuery($query, $whereParams);
554 $this->_pager
= new CRM_Utils_Pager($params);
555 $this->assign_by_ref('pager', $this->_pager
);
559 * @param $whereClause
560 * @param array $whereParams
562 public function pagerAtoZ($whereClause, $whereParams) {
565 SELECT DISTINCT UPPER(LEFT(title, 1)) as sort_name
568 ORDER BY LEFT(title, 1)
570 $dao = CRM_Core_DAO
::executeQuery($query, $whereParams);
572 $aToZBar = CRM_Utils_PagerAToZ
::getAToZBar($dao, $this->_sortByCharacter
, TRUE);
573 $this->assign('aToZ', $aToZBar);