<?php

/**
 * Created by PhpStorm.
 * User: ondra
 * Date: 13.12.17
 * Time: 14:00.
 */

namespace KupShop\I18nBundle\Admin\lists;

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

class TranslateArticlesList extends TranslateList
{
    protected $template = 'list/translateArticles.tpl';

    protected $listType = 'translateArticles';

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

    public function createQueryBuilder(): QueryBuilder
    {
        $qb = parent::createQueryBuilder();

        $photos = sqlQueryBuilder()
            ->select('GROUP_CONCAT(par.id_photo)')
            ->from('photos_articles_relation', 'par')
            ->where('a.id = par.id_art');
        $qb->addSubselect($photos, 'articlePhotos');

        $branches = sqlQueryBuilder()
            ->select('GROUP_CONCAT(par.id_branch)')
            ->from('articles_relation', 'par')
            ->where('a.id = par.id_art');
        $qb->addSubselect($branches, 'articleBranches');

        return $qb;
    }
}

$main_class = TranslateArticlesList::class;
