<?php

class CountriesList extends \KupShop\AdminBundle\AdminList\BaseList
{
    use AdminListSortable;

    protected $template = 'listSortable.tpl';
    protected $tableDef = [
        'id' => 'id',
        'fields' => [
            'Pořadí' => ['field' => 'position', 'render' => 'renderPosition', 'size' => '70px'],
            'Název' => ['field' => 'name'],
            'Zkratka' => ['field' => 'id'],
        ],
    ];
    protected $pageDivide = 999;

    public function getQuery()
    {
        return sqlQueryBuilder()->select('*')->from('countries');
    }

    public function handleDrag()
    {
        $item = getVal('moved_item');

        if (!empty($item)) {
            $item['id'] = '"'.$item['id'].'"';
            $this->saveList($item, 'countries');
            exit;
        }
    }
}
