protected function getPages(ContainerInterface $serviceLocator) { if ($this->pages === null) { if (!isset($this->configNavigation)) { throw new Exception\InvalidArgumentException('Could not find navigation configuration key'); } if (!isset($this->configNavigation[$this->getName()])) { throw new Exception\InvalidArgumentException(sprintf('Failed to find a navigation container by the name "%s"', $this->getName())); } $info = array(array('controller' => 'Index', 'action' => 'general', 'rootslug' => CoreSlugs::Root, 'requireslogin' => true)); foreach ($info as $details) { $controller = $details['controller']; $action = $details['action']; $rootslug = $details['rootslug']; $requireslogin = $details['requireslogin']; $cats = $this->wpRepo->fetchChildCategories($rootslug); if ($cats == null) { continue; } foreach ($cats as $rec) { $id = $rec->getSlug() . ".{$controller}.{$action}"; $this->configNavigation[$this->getName()][$id] = array('id' => $id, 'label' => $rec->getName(), 'controller' => $controller, 'action' => $action, 'requireslogin' => $requireslogin, 'params' => array('p1' => $rec->getSlug())); $subCats = $this->wpRepo->fetchChildCategories($rec->getSlug()); foreach ($subCats as $subRec) { $subId = $subRec->getSlug() . ".{$id}"; $this->configNavigation[$this->getName()][$id]['pages'][$subId] = array('id' => $subId, 'label' => $subRec->getName(), 'controller' => $controller, 'action' => $action, 'requireslogin' => $requireslogin, 'params' => array('p1' => $rec->getSlug(), 'p2' => $subRec->getSlug())); } } } $pages = $this->getPagesFromConfig($this->configNavigation[$this->getName()]); $this->pages = $this->preparePages($serviceLocator, $pages); } return $this->pages; }
public function generalAction() { $catSlug = $this->p1; $subCatSlug = $this->p2; $subCats = $this->wpRepo->fetchChildCategories($catSlug); if ($subCatSlug == null && $subCats != null) { $subCatSlug = $subCats[0]->getSlug(); $nodeId = "{$subCatSlug}.{$catSlug}.{$this->controller}.{$this->action}"; $navNode = $this->navService->findOneById($nodeId); if ($navNode != null) { $navNode->setActive(true); } } $posts = $this->wpRepo->fetchCategoryPostsBySlug($subCatSlug); return array('posts' => $posts, 'model' => $this->serializer->serialize(array('cat' => $this->wpRepo->fetchCategoryBySlug($catSlug), 'subCat' => $this->wpRepo->fetchCategoryBySlug($subCatSlug)), 'json')); }