<?php

namespace KupShop\I18nBundle\Admin\lists;

use Doctrine\DBAL\Query\QueryBuilder;
use KupShop\I18nBundle\Translations\SlidersImagesTranslation;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
use Query\Operator;

class TranslateSlidersImagesList extends TranslateList
{
    protected $template = 'list/translateSlidersImages.tpl';

    protected $listType = 'translateSlidersImages';

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

    public function createQueryBuilder(): QueryBuilder
    {
        $qb = parent::createQueryBuilder();
        $qb->leftJoin($this->translation->getTableAlias(), 'sliders', 'sl', 'sl.id = si.id_slider')
            ->addSelect('sl.name AS slider_name');

        $sliderID = getVal('sliderID', $_GET, false);
        $this->filters['sliderID']['selected'] = $sliderID;
        if ($sliderID) {
            $qb->andWhere(Operator::equals(['si.id_slider' => $sliderID]))
                ->orderBy('si.position');
        }

        return $qb;
    }
}

$main_class = TranslateSlidersImagesList::class;
