/** * @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 getList() { /** @var Article[] $articles */ $articles = $this->articleRepository->findBy(['isPublished' => true], ['publishedAt' => 'DESC']); $list = []; foreach ($articles as $article) { $publishedAt = $article->getPublishedAt(); $list[$publishedAt->format('Y')][$publishedAt->format('m')] = $publishedAt->format('F'); } return $list; }
/** * @return string */ public function get() { $key = 'feed'; if ($this->cache->contains($key)) { return $this->cache->fetch($key); } $articles = $this->articleRepository->findPublishedOrderedByPublishDate(); $feed = $this->feedManager->get('article'); $feed->addFromArray($articles); $renderedFeed = $feed->render('rss'); $this->cache->save($key, $renderedFeed); return $renderedFeed; }
/** * @return array */ public function getAll() { $key = 'statistics'; if ($this->cache->contains($key)) { return $this->cache->fetch($key); } $statistics = $this->articleRepository->findStatistics(); $mostPopularArticle = $this->articleRepository->findMostPopular(); if ($mostPopularArticle) { $statistics['mostPopularArticleData'] = ['slug' => $mostPopularArticle->getSlug(), 'title' => $mostPopularArticle->getTitle(), 'viewsCount' => $mostPopularArticle->getViewsCount()]; } $this->cache->save($key, $statistics, $this->cacheLifetime); return $statistics; }
/** * @return Query */ public function getFeed() { return $this->articleRepository->findPublishedByCategorySlugLimitedQuery($this->category); }