Files
kupshop/admin/lists/TemplatesList.php
2025-08-02 16:30:27 +02:00

89 lines
2.9 KiB
PHP

<?php
use KupShop\AdminBundle\AdminList\BaseList;
use KupShop\I18nBundle\Admin\Util\ListTranslationsFigureBadges;
class TemplatesList extends BaseList
{
use AdminListSortable;
use ListTranslationsFigureBadges;
protected $template = 'listSortable.tpl';
protected $showMassEdit = true;
protected $tableName = 'templates';
protected ?string $tableAlias = 't';
protected $orderParam = [
'sort' => 'Šablona',
'direction' => 'DESC',
];
protected $tableDef = [
'id' => 't.id',
'fields' => [
'template' => ['translate' => true, 'field' => 't.name', 'spec' => 'CONCAT_WS(" - ", tc.name, t.name) name', 'fieldType' => BaseList::TYPE_STRING],
// 'Text' => ['field'=>'text', 'renderer'=>'renderHTML'],
'visible' => ['translate' => true, 'render' => 'renderBoolean', 'field' => 't.figure', 'spec' => 't.figure', 'fieldType' => BaseList::TYPE_BOOL],
],
];
public function getQuery()
{
$qb = sqlQueryBuilder()
->select('t.id', 't.position as position')
->from(getTableName('templates'), 't')
->leftJoin('t', getTableName('templates_categories'), 'tc', 't.id_category = tc.id')
->where(1);
if ($name = getVal('name')) {
$qb->andWhere('t.name LIKE :name OR tc.name LIKE :name ')->setParameter('name', '%'.$name.'%');
}
if (getVal('id_category') != null) {
$qb->andWhere(\Query\Operator::equals(['t.id_category' => getVal('id_category')]));
}
return $qb;
}
public function customizeTableDef($tableDef)
{
$tableDef = parent::customizeTableDef($tableDef);
if (getVal('sortable') == true) {
$tableDef['fields'] =
array_merge(['Pořadí' => ['field' => 'position', 'render' => 'renderPosition', 'size' => '70px']], $this->tableDef['fields']);
$this->orderParam = [
'sort' => 'Pořadí',
'direction' => 'ASC',
];
$this->pageDivide = 1000;
}
if (findModule(\Modules::TRANSLATIONS)) {
$tableDef['fields']['translationsFigure'] = $this->getTranslationsFigureField(
translationClass: \KupShop\I18nBundle\Translations\TemplatesTranslation::class,
column: ['translation_section' => 'translations'],
);
}
return $tableDef;
}
public function handle()
{
parent::handle();
$item = getVal('moved_item');
if (!empty($item)) {
$parts = parse_url(getVal('url'));
parse_str($parts['query'], $query);
$idCategory = $query['id_category'] ?? '';
$this->saveList($item, 'templates', extra_where: empty($idCategory) ? '' : " AND id_category = {$idCategory}");
exit('{}');
}
}
}