<?php

namespace KupShop\ContentBundle\Sitemap;

use KupShop\I18nBundle\Translations\ProducersTranslation;
use KupShop\KupShopBundle\Util\StringUtil;
use Query\Translation;
use Symfony\Component\Routing\Router;

class ProducerSitemap extends BaseSitemap
{
    protected static $type = 'producers';
    protected static $module = \Modules::PRODUCERS;

    public function getData(): \Generator
    {
        $producerList = sqlQueryBuilder()->select('pr.id as id, pr.name')->from('producers', 'pr')
                    ->where('pr.active = "Y"')->orderBy('pr.name', 'ASC')
                    ->andWhere(Translation::coalesceTranslatedFields(ProducersTranslation::class))
                    ->execute();

        foreach ($producerList as $producer) {
            yield [
                'loc' => path('kupshop_catalog_catalog_producer', ['id_producer' => $producer['id'], 'url_producer' => StringUtil::slugify($producer['name'])], Router::ABSOLUTE_URL),
                'priority' => '0.7',
                'changefreq' => 'monthly',
            ];
        }
    }
}
