_restAlias) { foreach (array_keys($list) as $idx) { if ('HtmlBlock_' == $list[$idx]['type']) { unset($list[$idx]); break; } } } return $this; } public function exec() { $this->_initAction(); if (null === $this->_action) { $this->_doc->display404(); } return parent::exec(); } protected function _initAction() { if (null === $this->_action) { $params = $this->getRestParams(); if (empty($params)) { $this->_action = reset($this->_actions); } else if (1 == count($params)) { $this->_action = 'view'; $this->_getDataObj()->setPrimaryKeyByAlias($params[0]); } } return $this; } protected function _getListItem($list = null) { $item = []; $item['list'] = $this->_getDataObj()->getAlbums(); $item['tpl'] = $this->getTemplate('list.tpl'); return $item; } protected function _doView() { $this->_addViewItem(); $this->_addImagesItem(); $this->_postView(); return $this; } protected function _prepareViewItem(array &$item) { $item['backUrl'] = $this->finalUrl(); // @TODO: під питанням чи так правильно return parent::_prepareViewItem($item); } protected function _initDetailsPage(array $item) { Qs_Navigation::append(['title' => $item['title']]); return parent::_initDetailsPage($item); } protected function _addImagesItem() { if (!($list = $this->_getDataObj()->getAlbumItems())) { $this->_do404(); exit; } $type = $this->getConfig('type'); if (!$type) { $type = Entity::VIEW_TYPE_LIST; } $item = [ 'containerId' => 'gallery-items', 'list' => $list, 'config' => $this->getPhotoConfig()->toArray() ]; switch ($type) { case Entity::VIEW_TYPE_LIST: $item['tpl'] = $this->getTemplate('view-images-list.tpl'); $this->_addItem($item); $this->_initImagesListItem(); break; case Entity::VIEW_TYPE_SLIDER: $item['tpl'] = $this->getTemplate('view-images-slider.tpl'); $this->_prepareImages($item['list']); $this->_addItem($item, Qs_Doc::ITEM_GROUP_BOTTOM); $this->_initImagesSliderItem(); break; default: throw new Exception('Unknown gallery type.'); } $this->_doc->addScript('js/app/gallery/view.js'); $this->_doc->addInitObject('app.gallery.View', [['containerId' => $item['containerId'], 'type' => $type]]); return $this; } protected function _initImagesSliderItem() { $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'); return $this; } protected function _initImagesListItem() { $this->_doc->addStyleSheet('css/thirdpart/fancybox/jquery.fancybox.css'); $this->_doc->addScript('js/jquery.mousewheel.js'); $this->_doc->addScript('js/fancybox/jquery.fancybox.js'); 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, [ '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; } 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); } }