_messageTemplates[self::MSG_SET_ALL_ATTENDED] = 'All Attendance has been set to Attended'; $this->_pageHeaderTemplates[self::HEADER_LIST] = 'Manage "%eventName%" Event Attendees'; $this->_pageHeaderTemplates[self::HEADER_SELECT_EVENT] = 'Add "%attendeeName%" to Event'; return parent::_init(); } protected function _initAction() { $this->_initApplication(); return parent::_initAction(); } /** * /?action={action} * /{eventId} * /{eventId}?action={action} */ protected function _initApplication() { $obj = $this->_getDataObj(); $params = $this->getRestParams(); $paramCount = count($params); if (0 === $paramCount) { $action = Qs_Request::getRequestValue('action'); $userId = (int) Qs_Request::getRequestValue('userId'); if (('selectEvent' === $action || 'useEvent' === $action) && $userId) { $this->_action = $action; $obj->setUserId($userId); $this->_messagePlaceholders['attendeeName'] = UserObj::getAutocompleteItemTitle($userId); } else { $this->_do404(); } } elseif (1 === $paramCount) { $obj->setEventId($params[0]); if ($userId = (int) Qs_Request::getRequestValue('userId')) { $obj->setUserId($userId); } if (!$obj->getEventData('id') || EventEntity::TYPE_REGISTRATION !== $obj->getEventData('type')) { $this->_do404(); } $this->_messagePlaceholders['eventName'] = $obj->getEventData('title'); } else { $this->_do404(); } return $this; } protected function _getDefaultLinks() { $links = parent::_getDefaultLinks(); array_unshift( $links, [ 'title' => 'Back to ' . Qs_Application::getConfig('Event\\Admin\\')->get('itemsName'), 'url' => EventView::getPage('url'), ] ); $links[] = [ 'title' => 'Set All Attendance to Attended', 'attribs' => [ 'onclick' => "return confirm('Do you really want to set all Attendance to Attended?')", ], 'url' => $this->url(['action' => 'setAllAttended']) ]; $reportDropdown = new ReportDropdown(); $reportDropdown->setPlaceholders(['eventId' => $this->_getDataObj()->getEventId()]); array_unshift($links, $reportDropdown); return $links; } protected function _getNewForm(array $options = []) { $options = array_merge($this->_getSignupFormOptions(), $options); return parent::_getNewForm($options); } protected function _getEditForm(array $options = []) { $options = array_merge($this->_getSignupFormOptions(), $options); $type = $this->_getDataObj()->getData('type'); $options['allowMembers'] = (AttendeeForm::TYPE_MEMBER === $type); $options['allowNonMembers'] = (AttendeeForm::TYPE_NONMEMBER === $type); return parent::_getEditForm($options); } protected function _getSignupFormOptions() { $options = [ 'attendeeObj' => $this->_getDataObj(), 'eventObj' => $this->_getDataObj()->getEventObj(), 'allowCurrentUser' => false, 'allowMembers' => true, 'currentUserId' => null, 'allowNonMembers' => true, 'userAutocompleteUrl' => UserView::getUserAutocompleteUrl(), ]; return $options; } protected function _getSelectEventForm(array $options = []) { $options['dataObj'] = $this->_getDataObj(); $options['defaults']['userId'] = $this->_getDataObj()->getUserId(); return $this->_getFormInstance('selectEvent', $options); } /** * Select event for attendee * @return $this */ protected function _doSelectEvent() { $options = []; if (($ref = Qs_Array::get($_SERVER, 'HTTP_REFERER'))) { $options['cancelUrl'] = $ref; } $form = $this->_getSelectEventForm($options); $form->setDefaults(); $this->_addFormItem($form); return $this; } /** * Add attendee to specified event * @return $this */ protected function _doUseEvent() { $form = $this->_getSelectEventForm(); if ($form->validate()) { $data = array_intersect_key($form->getValues(), ['userId' => null, 'eventId' => null]); $data['action'] = 'new'; $url = Qs_Request::getFinalUrl() . '/' . $data['eventId'] . '?' . http_build_query($data); Qs_Http::redirect($url); } else { $this->_addFormItem($form); } return $this; } protected function _doUseEventAjax() { $form = $this->_getSelectEventForm(); $this->_displayJson($form->validateAjax()); } protected function _getListOptions() { $options = parent::_getListOptions(); $options['eventId'] = $this->_getDataObj()->getEventId(); return $options; } protected function _doSetStatus() { exit; } protected function _doSetStatusAjax() { $status = Qs_Request::getPostValue('status'); if (false === $this->_getDataObj()->setStatus($status)) { $this->_displayJson(['isError' => true, 'message' => implode(PHP_EOL, $this->_getDataObj()->getErrors())]); } $this->_displayJson(['isError' => false, 'status' => $status]); } protected function _doSetAllAttended() { $this->_getDataObj()->setAllAttended(); $this->_setBackMessage(static::MSG_SET_ALL_ATTENDED); $this->_doBack(); } protected function _doExportCsv() { $stmt = $this->_getDataObj()->getExportCsvStatement(); $rowCallback = function () use ($stmt) { return $stmt->fetch(); }; $helper = new ExportCsv([ 'fileName' => 'event-attendees {date}.csv', 'columns' => $this->getConfigArray('csvColumns'), 'rowCallback' => $rowCallback, ]); $helper->export(); exit; } protected function _doRegistrationList() { $this->_doc->setHeader(null); $item = [ 'event' => $this->_getDataObj()->getEventData(), 'userTypes' => $this->getRegistrationList(), 'tpl' => $this->getTemplate('registration-list.tpl') ]; $item = array_merge($this->getConfigArray('registrationList'), $item); $this->_addItem($item); } protected function _doSignInSheet() { $this->_doc->setHeader(null); $item = [ 'event' => $this->_getDataObj()->getEventData(), 'list' => $this->_getDataObj()->getSignInList(), 'tpl' => $this->getTemplate('sign-in-sheet.tpl') ]; $this->_debugMultiplyItems($item); $item = array_merge($this->getConfigArray('signInSheet'), $item); $this->_addItem($item); } protected function _debugMultiplyItems(&$item) { // Special option for test purposes if (constant('DEBUG') && ($multiply = Qs_Request::getGetValue('multiply')) && is_numeric($multiply)) { $items = $item['list']; for ($i = 0; $i < $multiply; $i++) { $item['list'] = array_merge($item['list'], $items); } } return $this; } protected function _doNameBadges() { $this->_doc->setHeader(null); $item = [ 'list' => $this->_getDataObj()->getAttendees4NameBadges(), 'tpl' => $this->getTemplate('name-badges.tpl') ]; $this->_debugMultiplyItems($item); $item = array_merge($this->getConfigArray('nameBadges'), $item); $this->_addItem($item); } protected function getRegistrationList() { $list = $this->_getDataObj()->getRegistrationList(); return Qs_Array::group($list, ['userType', 'company', Qs_Array::AUTOINCREMENT], []); } protected function _doRenderAttendee() { exit; } /** * post param: int $lastIndex */ protected function _doRenderAttendeeAjax() { if (null === ($lastIndex = Qs_Request::getPostValue('lastIndex'))) { $this->_displayJson(['isError' => 'true', 'message' => 'Wrong request']); exit; } $this->_doc ->clearInlineScripts() ->clearInitFunctions() ->clearScripts() ->clearStylesheets(); $formIndex = (int) $lastIndex + 1; $form = $this->_getNewForm([ 'renderMode' => Form\NewForm::RENDER_MODE_ATTENDEE, 'attendeeIndex' => $formIndex, ]); $response = [ 'formHtml' => $form->render(), 'formIndex' => $formIndex, 'evalData' => $this->_doc->getResources() ]; $this->_displayJson($response); exit; } }