<commit_before><?php

namespace Viteloge\FrontendBundle\EventListener {

    use Symfony\Component\Routing\Route;
    use Symfony\Component\Routing\RouterInterface;
    use Doctrine\ORM\EntityManager;
    use Presta\SitemapBundle\Service\SitemapListenerInterface;
    use Presta\SitemapBundle\Event\SitemapPopulateEvent;
    use Presta\SitemapBundle\EventListener\RouteAnnotationEventListener;
    use Presta\SitemapBundle\Sitemap\Url\UrlConcrete;
    use Viteloge\FrontendBundle\Component\Helper\AdHelper;

    class SitemapListener extends RouteAnnotationEventListener {

        const URL_LIMIT = 1000;

        /**
         *
         */
        protected $router;

        /**
         *
         */
        protected $entityManager;

        /**
         *
         */
        protected $helper;

        /**
         *
         */
        public function __construct(RouterInterface $router, EntityManager $entityManager, AdHelper $helper) {
            $this->router = $router;
            $this->entityManager = $entityManager;
            $this->helper = $helper;
        }

        /**
         * Should check $event->getSection() and then populate the sitemap
         * using $event->getGenerator()->addUrl(\Presta\SitemapBundle\Sitemap\Url\Url $url, $section)
         * if $event->getSection() is null or matches the listener's section
         *
         * @param SitemapPopulateEvent $event
         *
         * @throws \InvalidArgumentException
         * @return void
         */
        public function populateSitemap(SitemapPopulateEvent $event) {
            $section = $event->getSection();
            switch ($section) {
                case 'cities':
                    $this->addUrlsFromCities($event);
                    break;
                case 'queries':
                    $this->addUrlsFromQueries($event);
                    break;
                case 'ads':
                    $this->addUrlsFromAds($event);
                    break;
                case 'default':
                    $this->addUrlsFromRoutes($event);
                    break;
                default:
                    $this->addUrlsFromRoutes($event);
                   // $this->addUrlsFromCities($event);
                   // $this->addUrlsFromQueries($event);
                   // $this->addUrlsFromAds($event);
                    break;
            }
        }

        /**
         * @param SitemapPopulateEvent $event
         * @throws \InvalidArgumentException
         */
        private function addUrlsFromRoutes(SitemapPopulateEvent $event) {
            $collection = $this->router->getOriginalRouteCollection();
            foreach ($collection->all() as $name => $route) {
                $options = $this->getOptions($name, $route);
                if ($options) {
                    $event->getGenerator()->addUrl(
                        $this->getUrlConcrete($name, array(), $options),
                        $event->getSection() ? $event->getSection() : 'default'
                    );
                }
            }
        }

        /**
         * http://doctrine-orm.readthedocs.org/en/latest/reference/batch-processing.html
         */
        private function addUrlsFromCities(SitemapPopulateEvent $event) {
            $q = $this->entityManager->createQuery('select ic from AcreatInseeBundle:InseeCity ic');
            $iterableResult = $q->iterate();<commit_msg>fix: default should dump all sections<commit_after><?php

namespace Viteloge\FrontendBundle\EventListener {

    use Symfony\Component\Routing\Route;
    use Symfony\Component\Routing\RouterInterface;
    use Doctrine\ORM\EntityManager;
    use Presta\SitemapBundle\Service\SitemapListenerInterface;
    use Presta\SitemapBundle\Event\SitemapPopulateEvent;
    use Presta\SitemapBundle\EventListener\RouteAnnotationEventListener;
    use Presta\SitemapBundle\Sitemap\Url\UrlConcrete;
    use Viteloge\FrontendBundle\Component\Helper\AdHelper;

    class SitemapListener extends RouteAnnotationEventListener {

        const URL_LIMIT = 1000;

        /**
         *
         */
        protected $router;

        /**
         *
         */
        protected $entityManager;

        /**
         *
         */
        protected $helper;

        /**
         *
         */
        public function __construct(RouterInterface $router, EntityManager $entityManager, AdHelper $helper) {
            $this->router = $router;
            $this->entityManager = $entityManager;
            $this->helper = $helper;
        }

        /**
         * Should check $event->getSection() and then populate the sitemap
         * using $event->getGenerator()->addUrl(\Presta\SitemapBundle\Sitemap\Url\Url $url, $section)
         * if $event->getSection() is null or matches the listener's section
         *
         * @param SitemapPopulateEvent $event
         *
         * @throws \InvalidArgumentException
         * @return void
         */
        public function populateSitemap(SitemapPopulateEvent $event) {
            $section = $event->getSection();
            switch ($section) {
                case 'cities':
                    $this->addUrlsFromCities($event);
                    break;
                case 'queries':
                    $this->addUrlsFromQueries($event);
                    break;
                case 'ads':
                    $this->addUrlsFromAds($event);
                    break;
                case 'default':
                    $this->addUrlsFromRoutes($event);
                    break;
                default:
                    $this->addUrlsFromRoutes($event);
                    $this->addUrlsFromCities($event);
                    $this->addUrlsFromQueries($event);
                    $this->addUrlsFromAds($event);
                    break;
            }
        }

        /**
         * @param SitemapPopulateEvent $event
         * @throws \InvalidArgumentException
         */
        private function addUrlsFromRoutes(SitemapPopulateEvent $event) {
            $collection = $this->router->getOriginalRouteCollection();
            foreach ($collection->all() as $name => $route) {
                $options = $this->getOptions($name, $route);
                if ($options) {
                    $event->getGenerator()->addUrl(
                        $this->getUrlConcrete($name, array(), $options),
                        $event->getSection() ? $event->getSection() : 'default'
                    );
                }
            }
        }

        /**
         * http://doctrine-orm.readthedocs.org/en/latest/reference/batch-processing.html
         */
        private function addUrlsFromCities(SitemapPopulateEvent $event) {
            $q = $this->entityManager->createQuery('select ic from AcreatInseeBundle:InseeCity ic');
            $iterableResult = $q->iterate();
{'fraction_non_alphanumeric': 0.10979877515310586, 'fraction_numerical': 0.0011665208515602217, 'mean_word_length': 1.6564678543764524, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '136646', 'n_tokens_mistral': 1820, 'n_tokens_neox': 1735, 'n_words': 294}