src/Infrastructure/ZonesBundle/Subscriber/SitemapCountryAreasPagesSubscriber.php line 42

Open in your IDE?
  1. <?php
  2. namespace Whater\Infrastructure\ZonesBundle\Subscriber;
  3. use Whater\Infrastructure\CommonBundle\Subscriber\AbstractBusSitemapSubscriber;
  4. use Presta\SitemapBundle\Event\SitemapPopulateEvent;
  5. use Presta\SitemapBundle\Sitemap\Url\UrlConcrete;
  6. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  7. use Whater\Application\UseCase\Zones\CommandRequest\ListCountryAreaCommand;
  8. class SitemapCountryAreasPagesSubscriber extends AbstractBusSitemapSubscriber
  9. {
  10. /**
  11. * @var UrlGeneratorInterface
  12. */
  13. private $urlGenerator;
  14. /**
  15. * @param UrlGeneratorInterface $urlGenerator
  16. */
  17. public function __construct(
  18. UrlGeneratorInterface $urlGenerator
  19. ) {
  20. $this->urlGenerator = $urlGenerator;
  21. }
  22. /**
  23. * @inheritdoc
  24. */
  25. public static function getSubscribedEvents()
  26. {
  27. return [
  28. SitemapPopulateEvent::class => 'registerCountryAreasPages',
  29. ];
  30. }
  31. /**
  32. * @param SitemapPopulateEvent $event
  33. */
  34. public function registerCountryAreasPages(SitemapPopulateEvent $event)
  35. {
  36. $countryAreasPage = $this->handle(new ListCountryAreaCommand(1, 500000, "name", "asc"));
  37. $countryAreasPage->setMaxPerPage(500000);
  38. $countryAreas = $countryAreasPage->getCurrentPageResults();
  39. foreach ($countryAreas as $countryArea) {
  40. $countryAreaUrl = new UrlConcrete(
  41. $this->urlGenerator->generate(
  42. 'web_public_country_area_show_by_slug',
  43. [
  44. 'countryAreaSlug' => $countryArea->slug()
  45. ],
  46. UrlGeneratorInterface::ABSOLUTE_URL
  47. ),
  48. null,
  49. UrlConcrete::CHANGEFREQ_WEEKLY
  50. );
  51. $event->getUrlContainer()->addUrl(
  52. $countryAreaUrl,
  53. $countryArea->country()->isoCode() . '_country_areas'
  54. );
  55. }
  56. }
  57. }