_initAction(); if ('view' == $this->_action) { foreach ($list as $key => $item) { if ('HtmlBlock_' == $item['type']) { unset($list[$key]); break; } } } return $this; } protected function _initAction() { if (null === $this->_action) { $params = $this->getRestParams(); if (empty($params)) { $this->_action = reset($this->_actions); } else if (1 == count($params) && is_numeric($params[0])) { $this->_action = 'view'; $this->_getDataObj()->setPrimaryKey(intval($params[0])); } } return $this; } public function exec() { $this->_initAction(); if (null === $this->_action) { $this->_doc->display404(); } return parent::exec(); } protected function _doList() { $item = array(); $item['viewAlias'] = $this->_getViewUrl(); $item['list'] = $this->_getDataObj()->getList(); $item['tpl'] = $this->getTemplate('list.tpl'); $item['image'] = $this->getConfig('image')->toArray(); $this->_addItem($item); $this->_postList(); return $this; } protected function _doView() { $item = array(); $item['data'] = $this->_getDataObj()->getData(); if (empty($item['data']) || $item['data']['show'] === 'n') { $this->_doc->display404(); return $this; } $this->_doc->setHeader($item['data']['title']); \Qs_Navigation::append(array('title' => $item['data']['title'], 'url' => $this->url())); $item['containerId'] = 'gallery-items'; $item['list'] = $this->_getDataObj()->getCategoryItems(); $this->_prepareImages($item['list']); $item['backUrl'] = $this->finalUrl(); $item['config'] = $this->getPhotoConfig()->toArray(); $item['tpl'] = $this->getTemplate('view.tpl'); $this->_addItem($item); $this->_doc->addStyleSheet('css/thirdpart/royalslider.css'); $this->_doc->addStyleSheet('css/thirdpart/royalslider-default.css'); $this->_doc->addScript('js/royalslider/jquery.royalslider.js'); $this->_doc->addScript('js/royalslider/jquery.rs.visible-nearby.js'); $this->_doc->addScript('js/royalslider/jquery.rs.global-caption.js'); $this->_doc->addScript('js/royalslider/jquery.rs.active-class.js'); $this->_doc->addScript('js/royalslider/jquery.rs.hashchange.js'); $this->_doc->addScript('js/app/gallery.js'); $this->_doc->addInitObject('app.Gallery', [['containerId' => $item['containerId']]]); $this->_postView(); return $this; } protected function _prepareImages(array &$images) { $imageConfig = $this->getPhotoConfig('image'); foreach ($images as &$image) { $source = Qs_ImageFs::WEB_PATH . '/' . $image['image']; $destination = Qs_ImageFs::getIconName( $source, $imageConfig->width, $imageConfig->height, $imageConfig->method ); $destination = Qs_ImageFs::THUMBNAIL_PATH . '/' . $destination; if (!file_exists($destination)) { $destination = Qs_ImageFs::resize( $source, array( 'width' => $imageConfig->width, 'height' => $imageConfig->height, 'force' => false, 'method' => $imageConfig->method, 'sizeCheck' => true ) ); } $realWidth = $realHeight = 0; if ($destination) { $fileInfo = Qs_ImageFs::getInfo($destination); $realWidth = $fileInfo['width']; $realHeight = $fileInfo['height']; } $image['realWidth'] = $realWidth; $image['realHeight'] = $realHeight; } return $this; } protected function _getViewUrl() { return \Qs_SiteMap::find(null, array('type' => 'Gallery\\Category\\'), null, 'url'); } public function getPhotoConfig($field = null, $default = null) { if (null === $this->_photoConfig) { $this->_photoConfig = \Qs_Config::get($this->_photoConfigName, \Qs_Config::APP_TYPE); } if (null === $field) { return $this->_photoConfig; } return $this->_photoConfig->get($field, $default); } }