<?php

use KupShop\AdminBundle\AdminList\BaseList;
use Query\QueryBuilder;

class ConvertingTableList extends BaseList
{
    protected $tableDef = [
        'id' => 'id',
        'fields' => [
            'Název' => ['field' => 'convertor_name'],
        ],
    ];

    public function customizeTableDef($tableDef)
    {
        $table = parent::customizeTableDef($tableDef);

        $table['fields']['Počet produktů'] = [
            'field' => 'products',
            'spec' => function (QueryBuilder $qb) {
                $qb->addSelect('(select count(*) from convertors_table_cache where id_table=ct.id) products');
            },
        ];

        return $table;
    }

    public function getQuery()
    {
        return sqlQueryBuilder()->select('ct.id id,ct.name convertor_name')->from('convertors_table', 'ct');
    }
}
