'month', Entity::CALENDAR_BASICWEEK => 'week', Entity::CALENDAR_BASICDAY => 'day', Entity::CALENDAR_AGENDAWEEK => 'agenda-week', Entity::CALENDAR_AGENDADAY => 'agenda-day', ]; protected $_viewName; protected $_actions = ['list', 'view', 'insert', 'back', 'load', 'renderEvent', 'renderAttendee', 'iCal']; protected function _init() { $this->_messageTemplates[static::MSG_ADDED] = 'Attendee has been added'; $this->_messageTemplates[static::MSG_ADDED_MULTI] = 'Attendees have been added'; $this->_messageTemplates[static::MSG_ADDED_CART] = 'Attendee has been added to Shopping Cart'; $this->_messageTemplates[static::MSG_ADDED_CART_MULTI] = 'Attendees have been added to Shopping Cart'; return parent::_init(); } protected function _initAction() { $obj = $this->_getDataObj(); $blockType = $this->getConfig('type', ConfigForm::TYPE_CALENDAR); $params = $this->getRestParams(); $count = count($params); $request = array_merge_recursive(Qs_Request::get('get'), Qs_Request::get('post')); $requestAction = Qs_Request::getPostValue('action'); $auth = UserAuth::getInstance(); if ($auth->isLoggedIn()) { $this->_getDataObj()->setUserId($auth->getData('id')); } if (ConfigForm::TYPE_CALENDAR === $blockType) { if (0 === $count) { if (empty($request)) { $obj->setDate(new DateTime()); $this->_action = 'list'; } elseif (in_array($requestAction, ['load', 'renderEvent', true])) { $this->_action = $requestAction; } else { $this->_do404(); } } elseif (2 === $count && in_array($params[0], self::$calendarAlias) && false !== ($date = DateTime::createFromFormat('Y-m-d|', $params[1])) ) { $this->_viewName = array_search($params[0], self::$calendarAlias); $obj->setDate($date); if (empty($request)) { $this->_action = 'list'; } else { $this->_do404(); } } else { $this->_do404(); } } elseif (ConfigForm::TYPE_DETAILS === $blockType) { if (1 === $count && $params[0] && ($data = $obj->setPrimaryKeyByAlias($params[0])->getData())) { if (empty($request)) { $this->_action = 'view'; } elseif (in_array($requestAction, ['renderAttendee', 'insert'])) { $this->_action = $requestAction; } else { $this->_do404(); } } elseif (2 === $count && 'ical' === $params[0] && ($data = $obj->setPrimaryKeyByAlias($params[1])->getData()) ) { if (empty($request)) { $this->_action = 'iCal'; } else { $this->_do404(); } } else { $this->_do404(); } } else { throw new Exception('Unknown block type "' . $blockType . '"'); } return parent::_initAction(); } public static function getPageUrlByType($blockType) { return Qs_SiteMap::findFirst( null, ['type' => Qs_SiteMap::classToType(get_called_class())], ['type' => $blockType], 'url' ); } public static function getViewUrl($alias = null) { if (!$alias) { $alias = '%s'; } return Qs_SiteMap::findFirst(null, ['type' => 'Event\\'], ['type' => EventConfigForm::TYPE_DETAILS], 'url') . '/' . $alias; } protected function _getListItem() { $obj = $this->_getDataObj(); $list = $obj->getList(); $baseId = Qs_SiteMap::classToId($this); $item = [ 'containerId' => $baseId . '-block', 'calendarId' => $baseId . '-calendar', 'eventListId' => $baseId . '-list', 'eventTypes' => Model::getEventTypes4Select(), 'finalUrl' => Qs_Request::getFinalUrl(), 'detailsUrl' => static::getPageUrlByType(ConfigForm::TYPE_DETAILS), 'date' => $obj->getDate(), 'listHtml' => $this->_renderEventList($list), 'tpl' => $this->getTemplate('list.tpl') ]; $this->_doc->addScript('js/moment.js'); $this->_doc->addStylesheet('css/thirdpart/fullcalendar/fullcalendar.css'); $this->_doc->addScript('js/fullcalendar/fullcalendar.js'); $this->_doc->addScript('js/fullcalendar/lang/en-gb.js'); $this->_doc->addStylesheet('css/thirdpart/qtip/jquery.qtip.css'); $this->_doc->addScript('js/qtip/jquery.qtip.js'); $this->_doc->addScript('js/jquery.required.js'); $this->_doc->addScript('js/app/event/calendar.js'); $options = [ 'containerId' => $item['containerId'], 'calendarId' => $item['calendarId'], 'eventListId' => $item['eventListId'], 'finalUrl' => $item['finalUrl'], 'detailsUrl' => $item['detailsUrl'], 'calendarAlias' => self::$calendarAlias, 'defaultDate' => $obj->getDate()->format('Y-m-d'), 'defaultView' => $this->_viewName, 'list' => $this->_prepareCalendarList($list), ]; $this->_doc->addInitObject('app.event.Calendar', [$options]); return $item; } protected function _prepareCalendarList($list) { $newList = []; foreach ($list as $item) { if (array_key_exists('dateRanges', $item)) { foreach ($item['dateRanges'] as $range) { $_item = $item; $_item['start'] = Model::getStartDateTime($range); $_item['end'] = Model::getEndDateTime($range);; $newList[] = $_item; } } else { $newList[] = $item; } } return $newList; } protected function _doLoad() { exit; } /** * Return list of events for specified period * POST param: start 'YYY-MM-DD' * POST param: end 'YYY-MM-DD' * POST param: timezone */ protected function _doLoadAjax() { $obj = $this->_getDataObj(); $obj->setDate(Qs_Request::getPostValue('date')); $range = new Range(Qs_Request::getPostValue('start'), Qs_Request::getPostValue('end')); $obj->setRange($range); $list = $obj->getList(); $this->_displayJson(['list' => $this->_prepareCalendarList($list), 'listHtml' => $this->_renderEventList($list)]); } protected function _renderEventList(array $list) { $date = $this->_getDataObj()->getDate(); $prev = clone $date; $prev->modify('first day of this month -1 month'); $next = clone $date; $next->modify('first day of this month +1 month'); $monthStart = clone $date; $monthStart = $monthStart->modify('first day of this month')->format('Y-m-d H:i:s'); $monthEnd = clone $date; $monthEnd = $monthEnd->modify('last day of this month')->format('Y-m-d H:i:s'); // unset non month events foreach ($list as $idx => $row) { if (!($row['start'] <= $monthEnd && $row['end'] >= $monthStart)) { unset($list[$idx]); } } $today = new DateTime(); $maxDate = clone $today; $maxDate->modify('+1 year'); $minDate = clone $today; $minDate->modify('-1 year'); $finalUrl = Qs_Request::getFinalUrl(); $item = [ 'title' => $date->format('F Y'), 'prevUrl' => ($prev->format('Y-m') < $minDate->format('Y-m')) ? null : $finalUrl . '/month/' . $prev->format('Y-m-d'), 'nextUrl' => ($next->format('Y-m') > $maxDate->format('Y-m')) ? null : $finalUrl . '/month/' . $next->format('Y-m-d'), 'todayUrl' => ($date->format('Y-m') === date('Y-m')) ? null : $finalUrl . '/month/' . date('Y-m-01'), 'list' => $list, 'detailsUrl' => static::getPageUrlByType(ConfigForm::TYPE_DETAILS), 'tpl' => $this->getTemplate('eventList.tpl') ]; $this->_doc->assign('item', new Qs_Doc_Item($item)); return $this->_doc->fetchTemplate($item['tpl']); } /** * @param \Qs_Form $form Initialized form from _doInsert action * @return array|null */ protected function _getViewItem(Qs_Form $form = null) { $item = $this->_getDataObj()->getData(); $typeRule = new TypeRule($item['type']); if ($typeRule->featureTradeShows && $item['tradeShowAlias'] && ($url = TradeShowView::getPage('url'))) { $item['tradeShowUrl'] = $url . '/' . $item['tradeShowAlias']; } else { $item['tradeShowUrl'] = null; } $item['typeRule'] = $typeRule; $item['dateRanges'] = Model::prepareDateRanges($item['eventTime']); $item['userLoggedIn'] = false; $item['containerId'] = Qs_SiteMap::classToId($this) . '-view'; $item['calendarUrl'] = static::getPageUrlByType(ConfigForm::TYPE_CALENDAR); $item['detailsUrl'] = static::getPageUrlByType(ConfigForm::TYPE_DETAILS); $item['tpl'] = $this->getTemplate('view.tpl'); if ($item['registrationAllowed']) { if (UserAuth::getInstance()->isLoggedIn()) { $item['userLoggedIn'] = true; $this->_initSignupForm($item, $form); } else { if (null === $form) { $this->_initLoginBlock($item); } if ($typeRule->featureRegister) { $this->_initSignupForm($item, $form); } } } return $item; } protected function _doView() { $item = $this->_getViewItem(); $this->_initPageSeo($item); $this->_addItem($item); $this->_postView(); return $this; } protected function _initLoginBlock(&$item) { if ('view' === $this->_action) { /** @var \App\User\Login\Form\LoginBlockForm $loginForm */ LoginView::setSessionRedirectPageAlias(CURRENT_PAGE); $loginView = new LoginView(); $loginForm = $loginView->getLoginBlockForm(); $loginForm->prependId(); $loginForm->initRender(); $item['loginBlock'] = [ 'containerId' => 'event-login-block', 'memberButtonsBlockId' => 'member-buttons-block', 'loginUrl' => $loginForm->getAction(), 'becomeMemberUrl' => $loginForm->getBecomeMemberUrl(), 'formHtml' => $loginForm->render(), 'registerUrl' => Qs_SiteMap::find(null, ['type' => 'User\\Register\\'], null, 'url') ]; /** @var $doc \Qs_Doc */ $doc = Zend_Registry::get('doc'); $doc->addScript('js/jquery.defaultHint.js'); $doc->addInitFunction('$("#' . $loginForm->getId() . '").defaultHint', [['useWrapper' => true]]); } return $this; } protected function _doInsert() { $attendeeObj = $this->_getDataObj()->getAttendeeObj(); $form = $this->_getSignupForm(); if ($form->validate()) { $data = $form->getValues(); $attendeeObj->initFromForm($data); if (false === $attendeeObj->insert()) { $this->_setBackErrors($attendeeObj->getErrors()); } else { $this->_postInsert(); } $this->_doBack(); } else { $item = $this->_getViewItem($form); $this->_addItem($item); } return $this; } protected function _postInsert() { parent::_postInsert(); $data = $this->_getDataObj()->getAttendeeObj()->getData(); if (empty($data['total'])) { $this->_setBackMessage(1 < count($data['attendee']) ? self::MSG_ADDED_MULTI : self::MSG_ADDED); $this->_doBack(); } else { if (!$this->_doc->getAuth()->getIdentity()) { App_ECommerce_Checkout_LoginBlock_View::setSessionValue('skipLogin', true); } if (($page = Qs_SiteMap::findFirst(null, ['type' => 'ECommerce_Cart_'], null))) { $session = new Qs_Session_Namespace($page['fullAlias']); $session->eventBackUrl = $this->url(); $session->eventName = $this->_getDataObj()->getData('title'); Qs_Http::redirect($page['url']); } else { $this->_setBackMessage(1 < count($data['attendee']) ? self::MSG_ADDED_CART_MULTI : self::MSG_ADDED_CART); } } return $this; } protected function _getSignupForm(array $options = []) { $options = array_merge($this->_getSignupFormOptions(), $options); $form = $this->_getFormInstance('new', $options); $form->setDefaults(); return $form; } protected function _getSignupFormOptions() { $obj = $this->_getDataObj(); $type = $obj->getData('type'); $typeRule = new TypeRule($type); $attendeeObj = $obj->getAttendeeObj(); $auth = UserAuth::getInstance(); $isLoggedIn = $auth->isLoggedIn(); $currentUserId = $currentUserName = null; if ($typeRule->featureRegisterMember && $isLoggedIn) { $currentUserId = $auth->getData('id'); $currentUserName = ($auth->getData('nickname') ?: $auth->getData('firstName')) . ' ' . $auth->getData('lastName'); } if ($type == Entity::TYPE_WORKSHOP) { $allowedAttendeeType = $obj->getData('allowedAttendeeType'); $allowNonMembers = ($allowedAttendeeType == Entity::REGISTRATION_ALLOWED_ALL) ? $typeRule->featureRegisterNonmember : false; } else { $allowNonMembers = $typeRule->featureRegisterNonmember; } $options = [ 'allowCurrentUser' => ($typeRule->featureRegisterMember && $isLoggedIn && (false == $attendeeObj->getAttendeeRegistered($auth->getData('id'), $auth->getData('email')))), 'allowMembers' => $typeRule->featureRegisterMember && $this->_doc->getAuth()->isLoggedIn(), 'currentUserId' => $currentUserId, 'currentUserName' => $currentUserName, 'allowNonMembers' => $allowNonMembers && !$isLoggedIn, 'userAutocompleteUrl' => UserAutocompleteView::getUserAutocompleteUrl4Event(), ]; return $options; } protected function _getNewForm(array $options = []) { return $this->_getSignupForm($options); } protected function _initSignupForm(&$item, Qs_Form $form = null) { if (null === $form) { $options = []; if (isset($item['loginBlock'])) { $options['loginBlockId'] = $item['loginBlock']['containerId']; $options['memberButtonsBlockId'] = $item['loginBlock']['memberButtonsBlockId']; } $form = $this->_getNewForm($options); } $item['signupFormHtml'] = $form->render(); return $this; } protected function doRenderEvent() { exit; } /** * request POST: * int $eventId * * response JSON: * int eventId * string eventHtml */ protected function _doRenderEventAjax() { if (null == ($eventId = Qs_Request::getPostValue('eventId'))) { $this->_displayJson(['isError' => true, 'message' => 'Wrong request']); } $this->_getDataObj()->setPrimaryKey($eventId); if (null == ($item = $this->_getDataObj()->getData())) { $this->_displayJson(['isError' => true, 'message' => 'Wrong eventId']); } $item['dateRanges'] = Model::prepareDateRanges($item['eventTime']); $item['viewUrl'] = static::getPageUrlByType(ConfigForm::TYPE_DETAILS) . '/' . $item['alias']; $item['tpl'] = $this->getTemplate('event.tpl'); $item['config'] = $this->getConfig()->toArray(); $this->_doc->assign('item', new Qs_Doc_Item($item)); $html = $this->_doc->fetchTemplate($item['tpl']); $response = [ 'eventId' => $eventId, 'eventHtml' => $html ]; $this->_displayJson($response); } protected function _getFormOptions($type = null) { $options = parent::_getFormOptions($type); $options['eventObj'] = $this->_getDataObj(); $options['attendeeObj'] = $this->_getDataObj()->getAttendeeObj(); return $options; } protected function _doICal() { $data = $this->_getDataObj()->getData(); $calendar = new VCalendar(SITE_NAME); $hostSuffix = '@' . SITE_NAME; $detailsUrl = static::getPageUrlByType(ConfigForm::TYPE_DETAILS) . '/'; foreach ($data['eventTime'] as $idx => $range) { $event = new VEvent(); $event->setUniqueId($data['id'] . '-' . $idx . $hostSuffix); $event->setDtStart(new DateTime($data['startDate'] . ' ' . $range['startTime'])); $event->setDtEnd(new DateTime($data['endDate'] . ' ' . $range['endTime'])); $event->setLocation($data['location']); $event->setUrl($detailsUrl . $data['alias']); $event->setSummary($data['title']); $calendar->addEvent($event); } $filename = preg_replace('/\W+/', '_', $data['title']); header('Content-Type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename="' . $filename . '.ics"'); echo $calendar->render(); exit; } 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->_getSignupForm([ 'renderMode' => Form\NewForm::RENDER_MODE_ATTENDEE, 'attendeeIndex' => $formIndex, ]); $response = [ 'formHtml' => $form->render(), 'formIndex' => $formIndex, 'evalData' => $this->_doc->getResources() ]; $this->_displayJson($response); exit; } }