diff --git a/application/modules/default/controllers/ExploreController.php b/application/modules/default/controllers/ExploreController.php index 3197f2720..20ef73f1d 100644 --- a/application/modules/default/controllers/ExploreController.php +++ b/application/modules/default/controllers/ExploreController.php @@ -1,385 +1,378 @@ . **/ class ExploreController extends Local_Controller_Action_DomainSwitch { const DEFAULT_ORDER = 'latest'; const TAG_ISORIGINAL = 'original-product'; + /** @var string */ protected $_browserTitlePrepend; public function init() { parent::init(); $this->_auth = Zend_Auth::getInstance(); } public function categoriesAction() { // Filter-Parameter $inputFilterParams['category'] = (int)$this->getParam('cat', null); $inputFilterParams['filter'] = (int)$this->getParam('fil', null); $inputFilterParams['order'] = preg_replace('/[^-a-zA-Z0-9_]/', '', $this->getParam('ord', self::DEFAULT_ORDER)); $inputFilterParams['selected'] = (int)$this->getParam('sel', $inputFilterParams['category']); $modelCategories = new Default_Model_DbTable_ProjectCategory(); $children = $modelCategories->fetchImmediateChildren($inputFilterParams['selected']); $selChild = $modelCategories->fetchElement($inputFilterParams['filter']); $response = $this->generateResponseMsg($children, $inputFilterParams, $selChild); $this->_helper->json($response); } private function generateResponseMsg($children, $inputParams, $selChild) { $result = array(); if (count($children) == 0) { return $result; } $helperBuildExploreUrl = new Default_View_Helper_BuildExploreUrl(); foreach ($children as $child) { $nodeSelectedState = ($inputParams['filter'] == $child['project_category_id']) ? true : false; if (1 == ($child['rgt'] - $child['lft'])) { $result[] = array( 'title' => $child['title'], 'key' => $child['project_category_id'], 'href' => $helperBuildExploreUrl->buildExploreUrl($inputParams['category'], $child['project_category_id'], $inputParams['order']), 'target' => '_top', 'selected' => $nodeSelectedState ); } else { $nodeHasChildren = (1 == ($child['rgt'] - $child['lft'])) ? false : true; $nodeIsSelectedSubCat = (($selChild['lft'] > $child['lft']) AND ($selChild['rgt'] < $child['rgt'])) ? true : false; $nodeExpandedState = false; $nodeChildren = null; if ($nodeHasChildren AND $nodeIsSelectedSubCat) { $nodeExpandedState = true; $modelCategories = new Default_Model_DbTable_ProjectCategory(); $immChildren = $modelCategories->fetchImmediateChildren($child['project_category_id']); $nodeChildren = $this->generateResponseMsg($immChildren, $inputParams, $selChild); } $result[] = array( 'title' => $child['title'], 'key' => $child['project_category_id'], 'folder' => true, 'lazy' => true, 'selected' => $nodeSelectedState, 'expanded' => $nodeExpandedState, 'href' => $helperBuildExploreUrl->buildExploreUrl($inputParams['category'], $child['project_category_id'], $inputParams['order']), 'target' => '_top', 'children' => $nodeChildren ); } } return $result; } - /** * @throws Zend_Cache_Exception * @throws Zend_Db_Select_Exception * @throws Zend_Exception * @throws Zend_Loader_PluginLoader_Exception * @throws Zend_Paginator_Exception */ public function indexAction() - { - + { $filter = array(); $storeCatIds = Zend_Registry::isRegistered('store_category_list') ? Zend_Registry::get('store_category_list') : null; $this->view->categories = $storeCatIds; $storeConfig = Zend_Registry::isRegistered('store_config') ? Zend_Registry::get('store_config') : null; $storePackageTypeIds = null; if ($storeConfig) { $this->view->package_type = $filter['package_type'] = $storeConfig->package_type; } // Filter-Parameter $inputCatId = (int)$this->getParam('cat', null); + $inputFilterOriginal = $this->getParam('filteroriginal', null); - $inputFilterOriginal =$this->getParam('filteroriginal', null); - - if(isset($inputFilterOriginal)) - { + if (isset($inputFilterOriginal)) { //set to cookie session $config = Zend_Registry::get('config'); $cookieName = $config->settings->session->filter_browse_original; $remember_me_seconds = $config->settings->session->remember_me->cookie_lifetime; $domain = Local_Tools_ParseDomain::get_domain($this->getRequest()->getHttpHost()); - $cookieExpire = time() + $remember_me_seconds; + $cookieExpire = time() + $remember_me_seconds; setcookie($cookieName, $inputFilterOriginal, $cookieExpire, '/'); - } - else - { + } else { $config = Zend_Registry::get('config'); $cookieName = $config->settings->session->filter_browse_original; if (isset($_COOKIE[$cookieName])) { $inputFilterOriginal = $_COOKIE[$cookieName]; } } $this->view->inputFilterOriginal = $inputFilterOriginal; if ($inputCatId) { $this->view->isFilterCat = true; $this->view->filterCat = $inputCatId; $this->view->catabout = $this->getCategoryAbout($inputCatId); $helperFetchCategory = new Default_View_Helper_CatTitle(); $catTitle = $helperFetchCategory->catTitle($inputCatId); $this->view->headTitle($catTitle . ' - ' . $_SERVER['HTTP_HOST'], 'SET'); } $this->view->cat_id = $inputCatId; $filter['category'] = $inputCatId ? $inputCatId : $storeCatIds; $filter['order'] = preg_replace('/[^-a-zA-Z0-9_]/', '', $this->getParam('ord', self::DEFAULT_ORDER)); - if($inputFilterOriginal==1) - { - $filter['original'] = self::TAG_ISORIGINAL; + if ($inputFilterOriginal == 1) { + $filter['original'] = self::TAG_ISORIGINAL; } $page = (int)$this->getParam('page', 1); - + $storeConfig = Zend_Registry::isRegistered('store_config') ? Zend_Registry::get('store_config') : null; - if($storeConfig->layout_explore && $storeConfig->isRenderReact()){ - $pageLimit = 50; - $requestedElements = $this->fetchRequestedElements($filter, $pageLimit, ($page - 1) * $pageLimit); - $this->view->productsJson =Zend_Json::encode($requestedElements['elements']); + if ($storeConfig->layout_explore && $storeConfig->isRenderReact()) { + $pageLimit = 50; + $requestedElements = $this->fetchRequestedElements($filter, $pageLimit, ($page - 1) * $pageLimit); + $this->view->productsJson = Zend_Json::encode($requestedElements['elements']); $this->view->filtersJson = Zend_Json::encode($filter); $this->view->cat_idJson = Zend_Json::encode($inputCatId); $modelInfo = new Default_Model_Info(); - $topprods = $modelInfo->getMostDownloaded(100, $inputCatId,$this->view->package_type); + $topprods = $modelInfo->getMostDownloaded(100, $inputCatId, $this->view->package_type); $this->view->topprodsJson = Zend_Json::encode($topprods); - $comments = $modelInfo->getLatestComments(5, $inputCatId,$this->view->package_type); + $comments = $modelInfo->getLatestComments(5, $inputCatId, $this->view->package_type); $this->view->commentsJson = Zend_Json::encode($comments); - $modelCategory = new Default_Model_ProjectCategory(); - $this->view->categoriesJson = Zend_Json::encode($modelCategory->fetchTreeForView()); - $this->_helper->viewRenderer('index-react'); - }else{ - $pageLimit = 10; - $requestedElements = $this->fetchRequestedElements($filter, $pageLimit, ($page - 1) * $pageLimit); + $modelCategory = new Default_Model_ProjectCategory(); + $this->view->categoriesJson = Zend_Json::encode($modelCategory->fetchTreeForView()); + $this->_helper->viewRenderer('index-react'); + } else { + $pageLimit = 10; + $requestedElements = $this->fetchRequestedElements($filter, $pageLimit, ($page - 1) * $pageLimit); } - + $paginator = Local_Paginator::factory($requestedElements['elements']); $paginator->setItemCountPerPage($pageLimit); $paginator->setCurrentPageNumber($page); $paginator->setTotalItemCount($requestedElements['total_count']); $this->view->products = $paginator; $this->view->totalcount = $requestedElements['total_count']; $this->view->filters = $filter; $this->view->page = $page; - } /** * @param $inputCatId * * @return string|null * @throws Zend_Exception */ protected function getCategoryAbout($inputCatId) { $config = Zend_Registry::get('config'); $static_config = $config->settings->static; $include_path_cat = $static_config->include_path . 'category_about/' . $inputCatId . '.phtml'; if (file_exists($include_path_cat)) { return $include_path_cat; } return null; } /** * @param array $inputFilterParams * @param int $limit * @param int $offset * * @return array * @throws Zend_Cache_Exception * @throws Zend_Db_Select_Exception * @throws Zend_Exception */ private function fetchRequestedElements($inputFilterParams, $limit = null, $offset = null) { $modelProject = new Default_Model_Project(); $requestedElements = $modelProject->fetchProjectsByFilter($inputFilterParams, $limit, $offset); return $requestedElements; } /** * @throws Zend_Exception * @throws Zend_Paginator_Exception */ public function searchAction() { ini_set('memory_limit', '3072M'); $allDomainCatIds = Zend_Registry::isRegistered('store_category_list') ? Zend_Registry::get('store_category_list') : null; if (count($allDomainCatIds) == 0) { $allDomainCatIds = null; } if (isset($allDomainCatIds)) { $this->view->categories = $allDomainCatIds; } else { $modelCategories = new Default_Model_DbTable_ProjectCategory(); $this->view->categories = $modelCategories->fetchMainCatIdsOrdered(); } // Filter-Parameter $filterInput = new Zend_Filter_Input(array('*' => 'StringTrim', 'projectSearchText' => 'StripTags', 'page' => 'digits'), array( 'projectSearchText' => array( new Zend_Validate_StringLength(array('min' => 3, 'max' => 100)), 'presence' => 'required' ), 'page' => 'digits' ), $this->getAllParams()); if ($filterInput->hasInvalid()) { $this->_helper->viewRenderer('searchError'); $this->view->messages = $filterInput->getMessages(); return; } $inputFilterParams['projectSearchText'] = $filterInput->getUnescaped('projectSearchText'); $page = (int)$filterInput->getEscaped('page'); $config = Zend_Registry::get('config'); Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8'); Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive()); $dataPath = $config->settings->search->path; $dataPath .= $this->getNameForStoreClient() . DIRECTORY_SEPARATOR; $index = Zend_Search_Lucene::open($dataPath); try { $hits = $index->find($inputFilterParams['projectSearchText'] . '*'); } catch (Zend_Search_Lucene_Exception $e) { Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . $e->getMessage() . PHP_EOL . $e->getTraceAsString()); $hits = array(); } if (count($hits) == 0) { $this->_helper->viewRenderer('searchError'); $this->view->inputFilter = $inputFilterParams; $this->view->searchText = $inputFilterParams['projectSearchText']; return; } $results = $this->copyToArray($hits); $paginator = Zend_Paginator::factory($results); $paginator->setDefaultItemCountPerPage(10); $paginator->setCurrentPageNumber($page); $this->view->hitsCount = count($hits); $this->view->hits = $paginator; $this->view->page = $page; $this->view->inputFilter = $inputFilterParams; $this->view->searchText = $inputFilterParams['projectSearchText']; } /** * @param array $hits * * @return array */ protected function copyToArray($hits) { $returnArray = array(); /** @var $hit Zend_Search_Lucene_Search_QueryHit */ foreach ($hits as $hit) { $returnArray[] = $hit->getDocument(); } return $returnArray; } protected function _initResponseHeader() { $duration = 1800; // in seconds $expires = gmdate("D, d M Y H:i:s", time() + $duration) . " GMT"; $this->getResponse() ->setHeader('X-FRAME-OPTIONS', 'ALLOWALL', true) // ->setHeader('Last-Modified', $modifiedTime, true) ->setHeader('Expires', $expires, true)->setHeader('Pragma', 'no-cache', true) ->setHeader('Cache-Control', 'private, no-cache, must-revalidate', true) ; } /** * @param Zend_Config $static_config * @return string|null */ protected function getStoreAbout($static_config) { $include_path = $static_config->include_path . 'store_about/' . $this->view->filterStore . '.phtml'; if (file_exists($include_path)) { return $include_path; } return null; } /** * @param array $elements * * @return array with additional info's * @deprecated */ private function fetchAdditionalData($elements) { $modelProject = new Default_Model_Project(); $requestedElements = Array(); foreach ($elements as $project) { $info = $modelProject->fetchProductInfo($project['project_id']); $requestedElements[] = $info; } return $requestedElements; } protected function setLayout() { $layoutName = 'flat_ui_template'; $storeConfig = Zend_Registry::isRegistered('store_config') ? Zend_Registry::get('store_config') : null; if($storeConfig && $storeConfig->layout_explore) { $this->_helper->layout()->setLayout($storeConfig->layout_explore); }else{ $this->_helper->layout()->setLayout($layoutName); } } } \ No newline at end of file diff --git a/application/modules/default/models/ProjectCategory.php b/application/modules/default/models/ProjectCategory.php index b3c28b464..eb5b1e47e 100644 --- a/application/modules/default/models/ProjectCategory.php +++ b/application/modules/default/models/ProjectCategory.php @@ -1,355 +1,355 @@ . **/ class Default_Model_ProjectCategory { const CACHE_TREE_STORE = 'store_cat_tree'; /** @var string */ protected $_dataTableName; /** @var Default_Model_DbTable_ProjectCategory */ protected $_dataTable; /** * PHP 5 allows developers to declare constructor methods for classes. * Classes which have a constructor method call this method on each newly-created object, * so it is suitable for any initialization that the object may need before it is used. * * Note: Parent constructors are not called implicitly if the child class defines a constructor. * In order to run a parent constructor, a call to parent::__construct() within the child constructor is required. * * param [ mixed $args [, $... ]] * * @param string $_dataTableName * * @link http://php.net/manual/en/language.oop5.decon.php */ public function __construct($_dataTableName = 'Default_Model_DbTable_ProjectCategory') { $this->_dataTableName = $_dataTableName; $this->_dataTable = new $this->_dataTableName; } /** * @param null $store_id * * @return array * @throws Zend_Cache_Exception * @throws Zend_Exception */ public function fetchTreeForView($store_id = null) { $package_type = null; if (empty($store_id)) { $store_config = Zend_Registry::get('store_config'); $store_id = $store_config->store_id; $package_type = $store_config->package_type; } /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cache_id = __CLASS__ . '_' . __FUNCTION__ . "_{$store_id}"; $tree = $cache->load($cache_id); if (false === $tree OR empty($tree)) { try { $rows = $this->fetchCategoryTreeWithPackageType($store_id, $package_type); } catch (Zend_Exception $e) { Zend_Registry::get('logger')->err(__METHOD__ . ' - can not fetch categories : ' . $e->getMessage()); $modelCategories = new Default_Model_DbTable_ConfigStore(); $defaultStore = $modelCategories->fetchDefaultStoreId(); - $rows = $this->fetchCategoryTreeWithPackageType($defaultStore->store_id, $defaultStore->package_type); + $rows = $this->fetchCategoryTreeWithPackageType($defaultStore->store_id, $package_type); } list($rows, $tree) = $this->buildTreeForView($rows); $cache->save($tree, $cache_id, array(), 600); } return $tree; } /** * @param int|null $store_id * @param string|null $package_type * * @return array * @throws Zend_Exception */ protected function fetchCategoryTreeWithPackageType($store_id = null, $package_type = null) { if (empty($store_id)) { return array(); } if (empty($package_type)) { $statement = $this->_dataTable->getAdapter()->query("CALL fetchCatTreeForStore(:store_id)", array("store_id" => $store_id)); } else { $statement = $this->_dataTable->getAdapter()->query("CALL fetchCatTreeWithPackage(:store_id,:package_type)", array("store_id"=>$store_id, "package_type" => $package_type)); } $result = $statement->fetchAll(); if (count($result) == 0) { throw new Zend_Exception('no categories could be found for store id: ' . $store_id); } return $result; } /** * @param array $rows * @param int|null $parent_id * * @return array */ protected function buildTreeForView($rows, $parent_id = null) { $result = array(); $rememberParent = null; while (false === empty($rows)) { $row = array_shift($rows); $result_element = array( 'id' => $row['id'], 'title' => $row['title'], 'product_count' => $row['product_count'], 'xdg_type' => $row['xdg_type'], 'name_legacy' => $row['name_legacy'], 'has_children' => $row['has_children'], 'parent_id' => $row['parent_id'] ); //has children? if ($row['has_children'] == 1) { $result_element['has_children'] = true; $rememberParent = $row['id']; list($rows, $children) = $this->buildTreeForView($rows, $rememberParent); uasort($children, function ($a, $b) {return strcasecmp($a['title'], $b['title']);}); $result_element['children'] = $children; $rememberParent = null; } $result[] = $result_element; if (isset($parent_id) AND isset($rows[0]['parent_id']) AND $parent_id != $rows[0]['parent_id']) { break; } } return array($rows, $result); } /** * @param int|null $store_id If not set, the tree for the current store will be returned * @param bool $clearCache * * @return array * @throws Zend_Cache_Exception * @throws Zend_Exception * @deprecated use fetchTreeForView */ public function fetchCategoryTreeForStore($store_id = null, $clearCache = false) { if (empty($store_id)) { $store_config = Zend_Registry::get('store_config'); $store_id = $store_config->store_id; } /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cache_id = self::CACHE_TREE_STORE . "_{$store_id}"; if ($clearCache) { $cache->remove($cache_id); } if (false === ($tree = $cache->load($cache_id))) { $modelCategoryStore = new Default_Model_DbTable_ConfigStoreCategory(); $rows = $modelCategoryStore->fetchCatIdsForStore((int)$store_id); if (count($rows) < 1) { $modelCategories = new Default_Model_DbTable_ProjectCategory(); $root = $modelCategories->fetchRoot(); $rows = $modelCategories->fetchImmediateChildrenIds($root['project_category_id'], $modelCategories::ORDERED_TITLE); $tree = $this->buildTree($rows, null, null); } else { $tree = $this->buildTree($rows, null, (int)$store_id); } $cache->save($tree, $cache_id, array(), 600); } return $tree; } private function buildTree($list, $parent_id = null, $store_id = null) { if (false === is_array($list)) { $list = array($list); } $modelCategories = new Default_Model_DbTable_ProjectCategory(); $result = array(); foreach ($list as $cat_id) { $currentCategory = $modelCategories->fetchElement($cat_id); $countProduct = $this->fetchProductCount($cat_id, $store_id); $result_element = array( 'id' => $cat_id, 'title' => $currentCategory['title'], 'product_count' => $countProduct, 'xdg_type' => $currentCategory['xdg_type'], 'name_legacy' => $currentCategory['name_legacy'], 'has_children' => false ); if (isset($parent_id)) { $result_element['parent_id'] = $parent_id; } //has children? if (($currentCategory['rgt'] - $currentCategory['lft']) > 1) { $result_element['has_children'] = true; $ids = $modelCategories->fetchImmediateChildrenIds($currentCategory['project_category_id'], $modelCategories::ORDERED_TITLE); $result_element['children'] = $this->buildTree($ids, $currentCategory['project_category_id'], $store_id); } $result[] = $result_element; } return $result; } private function fetchProductCount($cat_id, $store_id = null) { $store_config = Zend_Registry::isRegistered('store_config') ? Zend_Registry::get('store_config') : null; if($store_config) { $storePackageTypeIds = (false === empty($store_config->package_type)) ? $store_config->package_type : null; }else { $storePackageTypeIds = null; } if ($storePackageTypeIds) { $sql = "SELECT count_product FROM stat_cat_prod_count WHERE project_category_id = :cat_id AND package_type_id = :package_id"; $bind = array('cat_id' => $cat_id, 'package_id' => $storePackageTypeIds); } else { $sql = "SELECT count_product FROM stat_cat_prod_count WHERE project_category_id = :cat_id AND package_type_id IS NULL"; $bind = array('cat_id' => $cat_id); } $result = $this->_dataTable->getAdapter()->fetchRow($sql, $bind); return (int)$result['count_product']; } /** * @param bool $clearCache * * @return array|false|mixed * @throws Zend_Cache_Exception * @throws Zend_Exception * * @deprecated use fetchTreeForView */ public function fetchCategoryTreeCurrentStore($clearCache = false) { $store_config = Zend_Registry::get('store_config'); $store_id = $store_config->store_id; /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cache_id = self::CACHE_TREE_STORE . "_{$store_id}"; if ($clearCache) { $cache->remove($cache_id); } if (false === ($tree = $cache->load($cache_id))) { $list_cat_id = self::fetchCatIdsForCurrentStore(); $tree = $this->buildTree($list_cat_id); $cache->save($tree, $cache_id, array(), 600); } return $tree; } /** * @return mixed|null * @throws Zend_Exception */ public static function fetchCatIdsForCurrentStore() { return Zend_Registry::isRegistered('store_category_list') ? Zend_Registry::get('store_category_list') : null; } /** * @return array * @throws Zend_Exception */ public function fetchCatNamesForCurrentStore() { $list_cat_id = self::fetchCatIdsForCurrentStore(); $sql = "SELECT project_category_id, title FROM project_category WHERE project_category_id IN (" . implode(',', $list_cat_id) . ")"; $result = $this->_dataTable->getAdapter()->fetchPairs($sql); return $result; } /** * @return array * @throws Zend_Exception */ public function fetchCatNamesForID($list_cat_id) { $sql = "SELECT title FROM project_category WHERE project_category_id IN (" . implode(',', $list_cat_id) . ") order by title " ; $results = $this->_dataTable->getAdapter()->fetchAll($sql); $values = array_map(function($row) { return $row['title']; }, $results); return $values; } /** * @return array */ public function fetchCatNames() { $sql = "SELECT project_category_id, title FROM project_category"; $result = $this->_dataTable->getAdapter()->fetchPairs($sql); return $result; } } \ No newline at end of file diff --git a/application/modules/default/views/scripts/explore/partials/filter.phtml b/application/modules/default/views/scripts/explore/partials/filter.phtml index f478185e2..62dcbf090 100644 --- a/application/modules/default/views/scripts/explore/partials/filter.phtml +++ b/application/modules/default/views/scripts/explore/partials/filter.phtml @@ -1,195 +1,104 @@ . **/ $modelCategory = new Default_Model_ProjectCategory(); -//$this->categories = $modelCategory->fetchCategoryTreeCurrentStore(); $this->categories = $modelCategory->fetchTreeForView(); $jsonTree = json_encode($this->categories); -$this->navBackgroundColorActive = $this->template['header-nav-tabs']['background-color-active']; -$this->navBackgroundColor = $this->template['header-nav-tabs']['background-color']; -$this->navColorActive = $this->template['header-nav-tabs']['link']['color']; ?> - - -
-
- "; - - $result .= ($addAllItem) ? addRoot($selectedOrder) : ''; - - foreach ($rows as $row) { - - $urlExplore = $helperBuildExploreUrl->buildExploreUrl($row['id'], null, $selectedOrder); - $product_count = empty($row['product_count']) ? '' : $row['product_count']; - - $result .= ""; - } - $result .= ""; - - return $result; - } - - /** - * @param string $selectedOrder - * @return string - * - function addRoot($selectedOrder) - { - $helpExploreUrl = new Default_View_Helper_BuildExploreUrl(); - $urlExplore = $helpExploreUrl->buildExploreUrl(null, null, $selectedOrder); - return ""; - } - - - $selectedOrder = isset($this->filters['order']) ? $this->filters['order'] : null; - echo build_tree($this->categories, $selectedOrder, true); - ?> -
-
- -*/ ?> - -
-
+