_pageHeaderTemplates['headerList'] = '"%eventTitle%" %itemsName%'; return parent::_init(); } public function exec() { if (isset($this->_restParams[0]) && 1 === count($this->_restParams)) { $eventId = (int) $this->_restParams[0]; $this->_getDataObj()->setEventId($eventId); $eventObj = new EventObj(array('primaryKey' => $eventId)); if (false == ($event = $eventObj->getData()) || !in_array($event['type'], array(EventObj::TYPE_REGULAR, EventObj::TYPE_GROUP)) ) { $this->_do404(); } $this->_event = $event; $this->_messageVariables['eventTitle'] = 'eventTitle'; $this->setConfig(array('eventTitle' => $event['title'])); } else { $this->_do404(); } return parent::exec(); } protected function _getDefaultLinks() { $links = parent::_getDefaultLinks(); $links[] = array('title' => 'Export to .csv', 'url' => $this->_getExportCsvUrl()); if ($this->_event['registrationAllowed']) { $links[] = array('title' => 'Add Attendee', 'url' => $this->_addAttendeeUrl()); } return $links; } protected function _getListOptions() { $options = parent::_getListOptions(); $options['eventType'] = $this->_event['type']; $options['showWaiver'] = 'y' === $this->_event['showWaiver']; return $options; } protected function _getListItem($list = null) { $item = parent::_getListItem($list); $params = array( 'listId' => $item['attribs']['id'], 'requestUrl' => Qs_Request::url(), 'switchDialog' => $this->_getSwitchDialogHtml(), ); $this->_doc->addStylesheet('css/thirdpart/jquery.fancybox.css'); $this->_doc->addScript('js/jquery.fancybox.js'); $this->_doc->addScript('js/app/event/attendee/admin/list.js'); $this->_doc->addInitObject('app.event.attendee.admin.List', array($params)); return $item; } protected function _getSwitchDialogHtml() { $item = array( 'tpl' => $this->getTemplate('paid-switch-dialog.tpl') ); $this->_doc->assign('item', new Qs_Doc_Item($item)); return $this->_doc->fetchTemplate($item['tpl']); } protected function _getExportCsvUrl() { $filter = $this->_getDataObj()->getFilter(); $params = array_filter($filter); if (($orderBy = Qs_Request::getGetValue('orderBy'))) { $params['orderBy'] = $orderBy; } $params['action'] = 'exportCsv'; return $this->url($params); } protected function _addAttendeeUrl() { if (($url = \App\Event\Admin\View::getPage('url'))) { $eventId = (int) $this->_getDataObj()->getEventId(); $url .= '?action=newAttendee&id=' . $eventId; } return $url; } protected function _doExportCsv() { if ($this->_getDataObj()->hasFilter()) { $form = $this->_getFilterForm(); if ($form->validate()) { $this->_getDataObj()->addFilter($form->getValues()); } } $options = array(); $options['order'] = array($this->_getList()->getOrderBy()); $this->_getDataObj()->setSelectOptions($options); $stmt = $this->_getDataObj()->getListStatement($options); $fp = fopen('php://output', 'w'); $dateFormat = 'D, d M Y H:i:s'; header('Expires: ' . gmdate($dateFormat, 0) . ' GMT'); header('Last-Modified: ' . gmdate($dateFormat) . ' GMT'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); header('Content-type: text/comma-separated-values'); header('Content-Disposition: attachment; filename="' . $this->_getExportFileName() . '"'); $columns = $this->_getColumns4ExportCsv(); fputcsv($fp, $columns); $blankRow = array_fill_keys(array_keys($columns), ''); while (($row = $stmt->fetch())) { $row = $this->_getRow4ExportCsv($row); $row = array_intersect_key($row, $columns); $row = array_merge($blankRow, $row); fputcsv($fp, $row); } fclose($fp); exit; } protected function _getExportFileName() { return $this->getConfig('itemName') . ' ' . date('M d Y g:i A') . '.csv'; } protected function _getColumns4ExportCsv() { $columns = array( 'added' => 'Date Registered', 'attendeeName' => 'Name', 'attendeeEmail' => 'Email', 'userMemberId' => 'Member ID', 'teamName' => 'Team', 'amount' => 'Amount', 'paid' => 'Paid', 'paymentTypeTitle' => 'Payment Type', ); if ('y' === $this->_event['showWaiver']) { $columns['waiverAgreed'] = 'Waiver Agreed'; } return $columns; } protected function _getRow4ExportCsv($data) { $row = str_replace(array("\n", "\r"), ' ', $data); $row['added'] = date('M d Y g:i A', strtotime($row['added'])); return $row; } protected function _doPaidSwitch() { exit; } /** * post param: bool $paid * post param: string $paymentMethod */ protected function _doPaidSwitchAjax() { $paid = (bool) Qs_Request::getPostValue('paid'); $paymentMethod = Qs_Request::getPostValue('paymentMethod'); $error = null; if (null === ($data = $this->_getDataObj()->getData())) { $error = $this->_createMessage(static::MSG_DATA_UNAVAILABLE); } elseif ($this->_isLocked()) { $error = $this->_createMessage(static::MSG_LOCKED, $this->_getLocker()); } elseif (null === $paid || (true == $paid && null == $paymentMethod)) { $error = 'Wrong request'; } else { if (false == $this->_getDataObj()->switchPaid($paid, $paymentMethod)) { $error = implode(PHP_EOL, $this->_getDataObj()->getErrors()); } } $response = ($error) ? array('isError' => true, 'message' => $error) : array(); $this->_displayJson($response); exit; } }