_messageTemplates[static::MSG_ADDED] = 'Attendee has been added to Shopping Cart'; $this->_messageTemplates[static::MSG_ADDED_MULTI] = 'Attendees have been added to Shopping Cart'; return parent::_init(); } public function exec() { $this->_doc->addStylesheet('css/modules/event-calendar.css'); return parent::exec(); } protected function _initAction() { $params = $this->getRestParams(); $count = count($params); $obj = $this->_getDataObj(); $blockType = $this->getConfig('type', ConfigForm::TYPE_CALENDAR); $request = array_merge_recursive(\Qs_Request::get('get'), \Qs_Request::get('post')); $requestAction = \Qs_Request::getPostValue('action'); $auth = App_User_Auth::getInstance(); if ($auth->isLoggedIn()) { $this->_getDataObj()->setUserId($auth->getData('id')); } if (ConfigForm::TYPE_CALENDAR === $blockType) { if (0 === $count) { if (empty($request)) { \Qs_Http::redirect(\Qs_Request::getFinalBaseUrl() . '/' . date('Y-m')); } else { $this->_do404(); } } elseif (1 === $count && false !== ($date = \DateTime::createFromFormat('Y-m|', $params[0]))) { $obj->setDate($date); if (empty($request)) { $this->_action = 'list'; } elseif ('renderEvent' === $requestAction) { $this->_action = $requestAction; } else { $this->_do404(); } } elseif (2 === $count && 'print' === $params[0] && false !== ($date = \DateTime::createFromFormat('Y-m|', $params[1]))) { if (empty($request)) { $obj->setDate($date); $this->_action = 'print'; } else { $this->_do404(); } } else { $this->_do404(); } } elseif (ConfigForm::TYPE_DETAILS === $blockType) { if (2 === $count && 'view' === $params[0] && $params[1] && ($data = $obj->setPrimaryKey($params[1])->getData())) { if (empty($request)) { $this->_action = 'view'; } elseif (in_array($requestAction, array('renderAttendee', 'insert'))) { $this->_action = $requestAction; } else { $this->_do404(); } } elseif (2 === $count && 'ical' === $params[0] && ($data = $obj->setPrimaryKey($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 function getDetailsUrl() { $url = static::getPageUrlByType(ConfigForm::TYPE_DETAILS); $date = $this->_getDataObj()->getDate()->format('Y-m-d'); return $url . '/' . $date; } public static function getPageUrlByType($blockType) { return Qs_SiteMap::findFirst( null, array('type' => \Qs_SiteMap::classToType(get_called_class())), array('type' => $blockType), 'url' ); } protected function _getListItem($list = null) { $obj = $this->_getDataObj(); $list = $obj->getList(); $calendar = new Calendar(array( 'date' => $obj->getDate(), 'events' => $list )); $item = array( 'containerId' => \Qs_SiteMap::classToId($this) . '-list', 'detailsUrl' => static::getPageUrlByType(ConfigForm::TYPE_DETAILS), 'finalUrl' => \Qs_Request::getFinalUrl(), 'calendar' => $calendar, 'tpl' => $this->getTemplate('list.tpl') ); $options = array( 'containerId' => $item['containerId'], 'requestUrl' => \Qs_Request::getUrl(), ); $this->_doc->addScript('js/jquery.dynamicTip.js'); $this->_doc->addScript('js/app/event/calendar.js'); $this->_doc->addInitObject('app.event.Calendar', array($options)); return $item; } protected function _doList() { $item = $this->_getListItem(); $this->_addItem($item); $legendItem = array( 'tpl' => $this->getTemplate('list-legend.tpl') ); $this->_addItem($legendItem, 'LEFT_ITEMS'); return $this; } protected function _doPrint() { $this->_doc->setLayoutTemplate(\Qs_SiteMap::getTemplate('PrintDoc/index.tpl')); $this->_doc->setBodyTemplate($this->getTemplate('print.tpl')); $this->_getDataObj()->setListIncludeTimeRanges(true); $item = array( 'date' => $this->_getDataObj()->getDate(), 'list' => $this->_getDataObj()->getList(), ); $this->_doc->clearScripts()->clearInlineScripts()->clearInitFunctions()->clearStylesheets(); $this->_doc->addScript('js/app/print.js'); $this->_doc->addStylesheet('css/print/site-print.css'); $this->_doc->assign('item', new \Qs_Doc_Item($item)); \Qs_Constant::set('DEBUG', false); return $this; } protected function _doView() { $item = $this->_getViewItem(); $item['timeFormatOptions'] = array('timeFormat' => 'g:i a'); $this->_addItem($item); $this->_postView(); return $this; } /** * @param \Qs_Form $form Initialized form from _doInsert action * @return array|null */ protected function _getViewItem(Qs_Form $form = null) { $item = $this->_getDataObj()->getData(); $this->_doc->setTitle($item['title']); $this->_doc->setHeader($item['title']); $item['containerId'] = \Qs_SiteMap::classToId($this) . '-view'; $item['finalUrl'] = static::getPageUrlByType(ConfigForm::TYPE_CALENDAR); $item['detailsUrl'] = static::getPageUrlByType(ConfigForm::TYPE_DETAILS); $item['tpl'] = $this->getTemplate('view.tpl'); $noRanges = true; foreach ($item['timeRanges'] as $ranges) { if ($ranges['startTime'] || $ranges['endTime']) { $noRanges = false; break; } } if ($noRanges) { unset($item['timeRanges']); } if ($item['registrationAllowed']) { if (App_User_Auth::getInstance()->isLoggedIn()) { $this->_initSignupForm($item, $form); } else { if (null === $form) { $this->_initLoginBlock($item); } if ($item['allowNonMembers']) { // register as non-member allowed $this->_initSignupForm($item, $form); } } } return $item; } protected function _initLoginBlock(&$item) { if ('view' === $this->_action) { /** @var \App_User_Login_Form_LoginBlock $loginForm */ $loginView = new App_User_Login_View(); $loginForm = $loginView->getLoginBlockForm(array('redirectAlias' => CURRENT_PAGE)); $loginForm->prependId(); $loginForm->initRender(); $item['loginBlock'] = array( 'containerId' => 'event-login-block', 'formHtml' => $loginForm->render(), 'registerUrl' => Qs_SiteMap::find(null, array('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', array(array('useWrapper' => true))); } return $this; } protected function _doInsert() { /** @var \App\Event\Form\AbstractSignupForm $form */ $form = $this->_getNewForm(); if ($form->validate()) { $data = $form->getValues(); $relatedEventIds = Qs_Array::get($data, 'relatedEventIds'); $this->_getDataObj()->initFromForm($data); if (false === $this->_getDataObj()->insert()) { $this->_setBackErrors($this->_getDataObj()->getErrors()); } else { // insert related events if ($relatedEventIds && ($relatedEventOptions = $form->getRelatedEventOptions())) { foreach ($relatedEventIds as $id) { $eventOptions = Qs_Array::get($relatedEventOptions, $id); /** @var \App\Event\AbstractObj $relatedObj */ $relatedObj = $eventOptions['obj']; $relatedData = $data; $relatedData['id'] = $id; $relatedObj->initFromForm($relatedData); $relatedObj->insert(); } } $this->_postInsert(); } $this->_doBack(); } else { $item = $this->_getViewItem($form); $this->_addItem($item); } return $this; } protected function _postInsert() { parent::_postInsert(); if (!$this->_doc->getAuth()->getIdentity()) { \App_ECommerce_Checkout_LoginBlock_View::setSessionValue('skipLogin', true); } if (($url = Qs_SiteMap::findFirst(null, array('type' => 'ECommerce_Cart_'), null, 'url'))) { Qs_Http::redirect($url); } else { $data = $this->_getDataObj()->getData(); $this->_setBackMessage((1 < count($data['attendees'])) ? static::MSG_ADDED_MULTI : static::MSG_ADDED); } return $this; } protected function _getSignupForm(array $options = array()) { return $this->_getNewForm($options); } protected function _getSignupFormOptions() { $obj = $this->_getDataObj(); $auth = App_User_Auth::getInstance(); $isLoggedIn = $auth->isLoggedIn(); $userId = ($isLoggedIn) ? $auth->getData('id') : null; $userEmail = ($isLoggedIn) ? $auth->getData('email') : null; $options = array( 'allowCurrentUser' => ($isLoggedIn) ? (false == $obj->getAttendeeObj()->getAttendeeRegistered($userId, $userEmail)) : true, 'allowMembers' => $isLoggedIn || $obj->getNonMembersAllowed(), 'currentUserId' => $userId, 'allowGroups' => $obj->getGroupsAllowed(), 'allowNonMembers' => $obj->getNonMembersAllowed(), 'userAutocompleteUrl' => \App_User_View::getAutocompleteNameEmailUrl(), 'showWaiver' => $obj->getShowWaiver(), ); if (($relatedEventIds = $obj->getRelatedEventIds())) { $options['relatedEvents'] = array(); $options['relatedEventOptions'] = array(); $viewUrl = View::getPageUrlByType(ConfigForm::TYPE_DETAILS); foreach ($relatedEventIds as $id) { $relatedObj = new Obj(); $event = $relatedObj->setPrimaryKey($id)->getData(); if ($event && $event['registrationAllowed']) { $event['viewUrl'] = $viewUrl . '/view/' . $event['id']; if ($event['memberPrice'] || $event['regularPrice']) { $titlePrefix = ' ('; $titlePrefix .= $event['regularPrice'] ? '$' . $event['regularPrice'] : '-'; $titlePrefix .= ' / '; $titlePrefix .= $event['memberPrice'] ? '$' . $event['memberPrice'] : '-'; $titlePrefix .= ')'; $event['title'] .= $titlePrefix; } $options['relatedEvents'][$id] = $event; $options['relatedEventOptions'][$id] = array( 'obj' => $relatedObj, 'allowCurrentUser' => ($isLoggedIn) ? (false == $relatedObj->getAttendeeObj()->getAttendeeRegistered($userId, $userEmail)) : true, 'allowMembers' => $isLoggedIn, 'currentUserId' => $userId, 'allowGroups' => $relatedObj->getGroupsAllowed(), 'allowNonMembers' => $relatedObj->getNonMembersAllowed(), ); } } } return $options; } protected function _getNewForm(array $options = array()) { $options = array_merge($this->_getSignupFormOptions(), $options); $form = $this->_getFormInstance('new', $options); $form->setDefaults(); return $form; } protected function _initSignupForm(&$item, Qs_Form $form = null) { if (null === $form) { $options = array(); if (isset($item['loginBlock'])) { $options['loginBlockId'] = $item['loginBlock']['containerId']; } $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(array('isError' => true, 'message' => 'Wrong request params')); } $this->_getDataObj()->setPrimaryKey($eventId); if (null == ($item = $this->_getDataObj()->getData())) { $this->_displayJson(array('isError' => true, 'message' => 'Wrong eventId')); } $item['viewUrl'] = static::getPageUrlByType(ConfigForm::TYPE_DETAILS) . '/view/' . $item['id']; $item['tpl'] = $this->getTemplate('event.tpl'); $this->_doc->assign('view', \Qs_View::getInstance()); $this->_doc->assign('item', $this->_createDocItem($item)); $html = $this->_doc->fetchTemplate($item['tpl']); $response = array( 'eventId' => $eventId, 'eventHtml' => $html ); $this->_displayJson($response); } protected function _getFormOptions() { $options = parent::_getFormOptions(); $options['dataObj'] = $this->_getDataObj(); return $options; } protected function _doICal() { $data = $this->_getDataObj()->getData(); $calendar = new VCalendar(SITE_NAME); $hostSuffix = '@' . SITE_NAME; foreach ($data['timeRanges'] 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(\Qs_Request::getFinalUrl() . '/view/' . $data['id']); $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; } }