/**
  * @inheritdoc
  */
 public function populateSitemap(SitemapPopulateEvent $event)
 {
     $event->getGenerator()->addUrl(new UrlConcrete($this->router->generate('harentius_blog_homepage', [], true), $this->homepage->getUpdatedAt(), UrlConcrete::CHANGEFREQ_WEEKLY, 1.0), 'pages');
     // Pages
     $pages = $this->pageRepository->findPublishedNotSlugOrdered($this->homepageSlug);
     foreach ($pages as $page) {
         $event->getGenerator()->addUrl(new UrlConcrete($this->router->generate('harentius_blog_show', ['slug' => $page->getSlug()], true), $page->getUpdatedAt(), UrlConcrete::CHANGEFREQ_MONTHLY, 0.5), 'pages');
     }
     // Articles
     /** @var Article[] $articles */
     $articles = $this->articleRepository->findBy(['isPublished' => true], ['publishedAt' => 'DESC']);
     foreach ($articles as $article) {
         $event->getGenerator()->addUrl(new UrlConcrete($this->router->generate('harentius_blog_show', ['slug' => $article->getSlug()], true), $article->getUpdatedAt(), UrlConcrete::CHANGEFREQ_MONTHLY, 0.9), 'articles');
     }
     // Categories
     $addCategoriesRoutes = function ($categories) use($event, &$addCategoriesRoutes) {
         foreach ($categories as $category) {
             $event->getGenerator()->addUrl(new UrlConcrete($this->router->generate("harentius_blog_category_{$category['id']}", [], true), null, UrlConcrete::CHANGEFREQ_MONTHLY, 0.8), 'categories');
             $addCategoriesRoutes($category['__children']);
         }
     };
     $addCategoriesRoutes($this->categoryRepository->notEmptyChildrenHierarchy());
     // Archives
     foreach ($this->archive->getList() as $year => $months) {
         foreach ($months as $number => $name) {
             $event->getGenerator()->addUrl(new UrlConcrete($this->router->generate('harentius_blog_archive_month', ['year' => $year, 'month' => $number], true), null, UrlConcrete::CHANGEFREQ_MONTHLY, 0.6), 'archive');
         }
         $event->getGenerator()->addUrl(new UrlConcrete($this->router->generate('harentius_blog_archive_year', ['year' => $year], true), null, UrlConcrete::CHANGEFREQ_MONTHLY, 0.6), 'archive');
     }
 }
 /**
  * @return array
  */
 public function getAll()
 {
     $key = 'categories_slug';
     if ($this->cache->contains($key)) {
         return $this->cache->fetch($key);
     }
     /** @var Category[] $categories */
     $categories = $this->categoryRepository->findWithPublishedArticles();
     $categoriesSlugs = [];
     foreach ($categories as $category) {
         $slug = "/{$category->getSlug()}/";
         $parent = $category;
         /** @var Category|null $parent */
         while ($parent = $parent->getParent()) {
             $slug = "/{$parent->getSlug()}{$slug}";
         }
         $categoriesSlugs[$category->getId()] = $slug;
     }
     $this->cache->save($key, $categoriesSlugs);
     return $categoriesSlugs;
 }
Exemple #3
0
 /**
  * @param array $options
  * @return array
  */
 public function getList(array $options = [])
 {
     return $this->categoryRepository->notEmptyChildrenHierarchy($options);
 }