/** * @param \ServerGrove\KbBundle\Document\Category $category * @param \Doctrine\Common\Collections\ArrayCollection $articles * @return \Doctrine\Common\Collections\ArrayCollection */ public function getArticlesFromCategoryHierarchy(Category $category, ArrayCollection $articles) { if (is_null($articles)) { $articles = new \Doctrine\Common\Collections\ArrayCollection(); } foreach ($category->getArticles() as $article) { $articles->add($article); } foreach ($category->getChildren() as $child) { $this->getArticlesFromCategoryHierarchy($child, $articles); } return $articles; }
/** * @param \ServerGrove\KbBundle\Document\Category $category * * @return bool */ private function shouldCategoryBeDisplayed(Category $category) { if (0 < $category->getArticles()->count()) { /** @var $article \ServerGrove\KbBundle\Document\Article */ foreach ($category->getArticles() as $article) { // If the category has at least one article active, // it should be displayed if ($article->getIsActive()) { return true; } } } elseif (0 < $category->getChildren()->count()) { /** @var $child \ServerGrove\KbBundle\Document\Category */ foreach ($category->getChildren() as $child) { if ($this->shouldCategoryBeDisplayed($child)) { return true; } } } return false; }
/** * Lists all Article documents. * * @Route("/{path}/articles", name="sgkb_admin_categories_articles", requirements={"path":".+"}) * @Template("ServerGroveKbBundle:Admin/Articles:index.html.twig") * @ParamConverter("category", class="ServerGroveKbBundle:Category") */ public function articlesAction(Category $category) { $documents = $category->getArticles(); return array('documents' => $documents, 'category' => $category); }