public function buildCatalogMenu($options = array()) { $menuCatalogId = 0; $defaultCat = ''; if (isset($options['menu'])) { $oMenu = new MenuObject($options['menu']); $menuCatalog = $oMenu->getMenuItemByPageId(null, 'catalog'); // if ($this->view->currentPageID) // { // $parentPage = Cible_FunctionsPages::findParentPageID($this->view->currentPageID); // while ($parentPage['P_ParentID'] != 0 ) // { // $parentPage = Cible_FunctionsPages::findParentPageID($parentPage['P_ParentID']); // } // // $pageId = $parentPage['P_ID']; // $menuCatalog = $oMenu->getMenuItemByPageId($pageId); // } // else // { // $menuCatalog = $oMenu->getMenuItemByPageId(); $parentPage = Cible_FunctionsPages::findParentPageID($menuCatalog['MII_PageID']); // } } if ($this->view->controller != $parentPage['PI_PageIndex']) { $link = $parentPage['PI_PageIndex'] . "/"; } else { $link = $this->view->selectedPage . "/"; } $tree = array(); $langId = Zend_Registry::get('languageID'); $oCategories = new CatalogCategoriesObject(); if (Zend_Registry::isRegistered('defaultCategory') && !is_null(Zend_Registry::get('defaultCategory'))) { $defaultCatId = Zend_Registry::get('defaultCategory'); $tmpCat = $oCategories->populate($defaultCatId, $langId); if (empty($tmpCat['CI_ValUrl'])) { $tmpCat['CI_ValUrl'] = ""; } $defaultCat = $tmpCat['CI_ValUrl']; } $categories = $oCategories->getAll($langId); $oSubCategories = new SubCategoriesObject(); $catalog = array('ID' => $menuCatalog['MID_ID'], 'Title' => $menuCatalog['MII_Title'], 'PageID' => '', 'Link' => $link . $defaultCat, 'Placeholder' => 0, 'child' => array()); foreach ($categories as $category) { $childs = array(); $id = $category['C_ID']; $name = Cible_FunctionsGeneral::formatValueForUrl($category['CI_Name']); $linkCat = $link . $name; $menu['ID'] = $category['C_ID']; $menu['Title'] = $category['CI_Name']; $menu['PageID'] = ''; $menu['Link'] = $linkCat; $menu['Placeholder'] = '2'; $subCategories = $oSubCategories->getSubCatByCategory($id, true, $langId); if ($options['nesting'] > 1) { foreach ($subCategories as $subCat) { $name = "/" . Cible_FunctionsGeneral::formatValueForUrl($subCat['SCI_Name']); $linkSubCat = $linkCat . $name; $child['ID'] = $subCat['SC_ID']; $child['Title'] = $subCat['SCI_Name']; $child['PageID'] = ''; $child['Link'] = $linkSubCat; $child['Placeholder'] = '2'; $childs[] = $child; $name = ''; } } $menu['child'] = $childs; $catalog['child'][] = $menu; } $oMenu = new MenuObject($options['menu']); $first = $oMenu->populate($menuCatalog['MID_ID']); $childCombined = array(); if (isset($options['merge']) && $options['merge']) { $childCombined = array_merge($catalog['child'], $first); $catalog['child'] = $childCombined; } $tree[] = $catalog; return $tree; }
/** * Set default values and the first level container (ul) * * @param Mixed $menu If String: Fecth menu data according its name.<br/> * If Array: It must contain the menu tree. * * @param array $options Options to manage menu behaviour<br /> * Ex: disable_nesting => true, parentAltId => (string) * * @return string html code to display the menu and is children */ public function subMenu($options = array()) { if (isset($options['addEnclosure'])) { $this->_addEnclosure = $options['addEnclosure']; } if ($this->view->selectedPage) { $this->_selectedPage = $this->view->selectedPage; } elseif (Zend_Registry::isRegistered('selectedPage')) { $this->_selectedPage = Zend_Registry::get('selectedPage'); } else { $params = Zend_Controller_Front::getInstance()->getRequest()->getParams(); $this->_selectedPage = $params['controller']; if ($params['controller'] == 'index') { $this->_selectedPage = Cible_FunctionsPages::getPageNameByID(1); } } $oPages = new PagesObject(); $pageData = $oPages->pageIdByController($this->_selectedPage); $this->_selectedPageId = $pageData['P_ID']; $menuData = $oPages->getRelatedMenu($this->_selectedPageId); $parentId = 0; if (!$menuData) { $parentId = $oPages->getParentRelatedID($this->_selectedPageId); $parentName = $oPages->getParentRelatedName($parentId); $menuData = $oPages->getRelatedMenu($parentId); $this->_selectedPageId = $parentId; $parentId = $menuData['MID_ParentID']; $this->view->assign('selectedPage', $parentName); //echo $parentName; } $_menu = new MenuObject($menuData['MID_MenuId']); if ($menuData['MID_ParentID'] == 0) { $parentId = $menuData['MID_ID']; } else { $menuItem = $_menu->getMenuItemByPageId($this->_selectedPageId); if ($menuItem) { $this->_getParentsMenuId($menuItem, $_menu); } if ($parentId == 0) { $parentId = $this->_parentsMenuId[0]; } } if (!empty($options['parentId'])) { $parentId = $options['parentId']; } if (preg_match('/useCatalog/', $menuData['MID_Style'])) { $menu_item['Placeholder'] = 2; $collections = new SubCategoriesObject(); // $menuCatalog = $this->getMenuItemByPageId( null, 'collections'); $catalogMenu = $collections->buildCatalogMenu($menu_item, array('nesting' => 1)); $tree = $catalogMenu['child']; // $first = $this->populate($menuCatalog['MID_ID']); // $childCombined = array(); // $childCombined = array_merge($catalogMenu['child'], $first); // $catalog['child'] = $childCombined; } elseif (!empty($parentId)) { $tree = $_menu->populate($parentId); } $tree['MID_MenuID'] = $menuData['MID_MenuId']; $tree['MID_ParentId'] = $parentId; return $tree; }