_initApplication(); $this->_initAction(); if ($this->_action == 'view') { $htmlBlockIndex = null; foreach ($items as $index => $item) { if ($item['type'] == 'HtmlBlock_') { $htmlBlockIndex = $index; break; } } if (null !== $htmlBlockIndex) { unset($items[$htmlBlockIndex]); } } return $this; } public function exec() { $this->_initApplication(); return parent::exec(); } protected function _initApplication() { switch ($this->getConfig('type')) { case App_Volunteer_Form_Config::TYPE_SMALL: $this->_listTemplate = 'small-list.tpl'; $this->_listTitle = 'Volunteer Opportunities'; $this->_listIpp = self::SMALL_LIST_IPP; $this->_getDataObj()->getListSelect()->limit(self::SMALL_LIST_IPP); $this->_getList()->setIsDisabledLimit(true); break; default: $params = $this->getRestParams(); $paramsCount = count($params); if ('0' != $this->_restAlias && 0 === $paramsCount) { $this->_defaultAction = reset($this->_actions); } elseif (1 === $paramsCount) { if (is_numeric($params[0])) { $this->_getDataObj()->setPrimaryKey($params[0]); $this->_defaultAction = 'view'; } else { $this->_doc->display404(); } } else { $this->_doc->display404(); } break; } return $this; } protected function _addListItem($list = null) { if (!empty($this->_listIpp)) { if (null == $list) { $list = $this->_getList(); } $list->setIpp($this->_listIpp); } $item = $this->_getListItem($list); $item['viewAlias'] = $this->_getViewAlias(); $item['title'] = $this->_listTitle; $this->_addLinksItem(); $item['tpl'] = $this->getTemplate($this->_listTemplate); $this->_addItem($item); return $this; } protected function _doView() { $item = $this->_getDataObj()->getData(); if (empty($item) || !$this->_isActualDate($item)) { $this->_doc->display404(); } $this->_doc->setKeywords($item['metaKeywords']); $this->_doc->setDescription($item['metaDescription']); $item['tpl'] = $this->getTemplate('view.tpl'); $item['backUrl'] = $this->_getBackUrl(CURRENT_PAGE_FINAL); if ($item['backUrl'] == '') { $item['backUrl'] = CURRENT_PAGE_FINAL; } $item['imageConfig'] = $this->_getImageConfig(); $this->_addItem($item); Qs_Navigation::append(array('title' => $item['title'], 'url' => $item['backUrl'] . '/' . $item['id'])); $this->_postView(); return $this; } protected function _isActualDate($item) { $actualDate = strtotime($item['date']) < time(); if ($actualDate && !empty($item['expiredDate'])) { $actualDate = strtotime($item['expiredDate']) > time(); } return $actualDate; } protected function _getImageConfig() { $config = (array) $this->getConfig('image')->toArray(); if (empty($config['width'])) { $config['width'] = self::DEFAULT_IMAGE_WIDTH; } if (empty($config['height'])) { $config['height'] = self::DEFAULT_IMAGE_HEIGHT; } if (empty($config['resizeMethodAlias'])) { $config['resizeMethodAlias'] = self::DEFAULT_IMAGE_RESIZE_METHOD_ALIAS; } $config['resizeMethod'] = Qs_ImageFs::getResizeMethod($config['resizeMethodAlias']); return $config; } protected function _getBackUrl($sessionName = null) { if (is_null($sessionName)){ $sessionName = CURRENT_PAGE; } $session = new Qs_Session_Namespace($sessionName); if (isset($session->backUrl)) { return $session->backUrl; } return ''; } public function writeXmlSitemap(App_Sitemap_Xml_Writer $xml) { if (App_Volunteer_Form_Config::TYPE_DEFAULT != $this->getConfig('type', App_Volunteer_Form_Config::TYPE_DEFAULT)) { return $this; } $stmt = $this->_getDataObj()->getListStatement4XmlSitemap(); $pageUrl = ('y' == $this->_doc->getOption('isSecure')) ? BASE_URL_HTTPS : BASE_URL_HTTP; $pageUrl .= '/' . $this->_doc->getOption('fullAlias'); while ($item = $stmt->fetch()) { $xml->writeUrl($pageUrl . '/' . $item['id']); } return $this; } protected function _getViewAlias() { if (null == $this->_viewAlias) { $this->_viewAlias = Qs_SiteMap::find( null, array('type' => 'Volunteer_'), array('type' => 'default'), 'fullAlias' ); } return $this->_viewAlias; } public function getSideBlockItem(array $blockData = array()) { $this->_initApplication(); $item = $this->_getListItem(); $item['viewAlias'] = $this->_getViewAlias(); if (!empty($item['list'])) { $item['tpl'] = $this->getTemplate($this->_listTemplate); return $item; } return null; } }