<?php
namespace Whater\Infrastructure\ZonesBundle\Subscriber;
use Whater\Infrastructure\CommonBundle\Subscriber\AbstractBusSitemapSubscriber;
use Presta\SitemapBundle\Event\SitemapPopulateEvent;
use Presta\SitemapBundle\Sitemap\Url\UrlConcrete;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Whater\Application\UseCase\Zones\CommandRequest\ListCountryAreaCommand;
class SitemapCountryAreasPagesSubscriber extends AbstractBusSitemapSubscriber
{
/**
* @var UrlGeneratorInterface
*/
private $urlGenerator;
/**
* @param UrlGeneratorInterface $urlGenerator
*/
public function __construct(
UrlGeneratorInterface $urlGenerator
) {
$this->urlGenerator = $urlGenerator;
}
/**
* @inheritdoc
*/
public static function getSubscribedEvents()
{
return [
SitemapPopulateEvent::class => 'registerCountryAreasPages',
];
}
/**
* @param SitemapPopulateEvent $event
*/
public function registerCountryAreasPages(SitemapPopulateEvent $event)
{
$countryAreasPage = $this->handle(new ListCountryAreaCommand(1, 500000, "name", "asc"));
$countryAreasPage->setMaxPerPage(500000);
$countryAreas = $countryAreasPage->getCurrentPageResults();
foreach ($countryAreas as $countryArea) {
$countryAreaUrl = new UrlConcrete(
$this->urlGenerator->generate(
'web_public_country_area_show_by_slug',
[
'countryAreaSlug' => $countryArea->slug()
],
UrlGeneratorInterface::ABSOLUTE_URL
),
null,
UrlConcrete::CHANGEFREQ_WEEKLY
);
$event->getUrlContainer()->addUrl(
$countryAreaUrl,
$countryArea->country()->isoCode() . '_country_areas'
);
}
}
}