<?php

namespace KupShop\I18nBundle\Admin\lists;

use Doctrine\DBAL\Query\QueryBuilder;
use KupShop\CatalogBundle\Section\SectionTree;
use KupShop\CatalogBundle\Util\ProductsFilterSpecs;
use KupShop\I18nBundle\Translations\ProductsTranslation;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;

class TranslateProductsList extends TranslateList
{
    protected $template = 'list/translateProducts.tpl';

    protected $listType = 'translateProducts';

    public function __construct()
    {
        parent::__construct();
        $this->translation = ServiceContainer::getService(ProductsTranslation::class);

        $this->filters['productsFilter'] = getVal('filter', $_GET, []);
    }

    public function get_vars()
    {
        $vars = parent::get_vars();

        $vars['categories'] = ServiceContainer::getService(SectionTree::class)->getTree();

        return $vars;
    }

    protected function applyFilters(QueryBuilder $qb)
    {
        $qb = parent::applyFilters($qb);

        $productsFilterSpecs = ServiceContainer::getService(ProductsFilterSpecs::class);
        $qb->andWhere(
            $productsFilterSpecs->getSpecs($this->filters['productsFilter'])
        );

        return $qb;
    }
}

$main_class = TranslateProductsList::class;
