1
|
<?php
|
2
|
|
3
|
|
4
|
namespace App\AdminModule\Components;
|
5
|
|
6
|
|
7
|
use App\Model\Repository\OriginRepository;
|
8
|
use App\Utils\DataGrid\DataGrid;
|
9
|
use Ublaboo\DataGrid\Exception\DataGridException;
|
10
|
|
11
|
class OriginGrid extends DataGrid
|
12
|
{
|
13
|
/**
|
14
|
* @var OriginRepository
|
15
|
*/
|
16
|
private $originRepository;
|
17
|
|
18
|
public function __construct(OriginRepository $originRepository)
|
19
|
{
|
20
|
$this->originRepository = $originRepository;
|
21
|
|
22
|
parent::__construct();
|
23
|
}
|
24
|
|
25
|
/**
|
26
|
* Abstraktní metoda, slouží k nastavení primárního klíče a nastavení datasource
|
27
|
* 1. $this->setPrimaryKey();
|
28
|
* 2. $this->setDataSource();
|
29
|
*
|
30
|
* @throws DataGridException
|
31
|
*/
|
32
|
public function init()
|
33
|
{
|
34
|
$this->setPrimaryKey(OriginRepository::COLUMN_ID);
|
35
|
$this->setDataSource($this->originRepository->findAll());
|
36
|
}
|
37
|
|
38
|
/**
|
39
|
* Definice sloupečků, akcí, vyhledávácích filtrů gridu
|
40
|
*
|
41
|
* @throws DataGridException
|
42
|
*/
|
43
|
public function define()
|
44
|
{
|
45
|
// Definice sloupečků
|
46
|
$this->addColumnNumber(OriginRepository::COLUMN_ID, 'ID')->setDefaultHide(TRUE);
|
47
|
$this->addColumnText(OriginRepository::COLUMN_ORIGIN, 'Origin');
|
48
|
$this->addColumnText(OriginRepository::COLUMN_OLD_NAME, 'Old Name');
|
49
|
|
50
|
// Definice filtrů
|
51
|
$this->addFilterText(OriginRepository::COLUMN_ORIGIN, 'Origin');
|
52
|
$this->addFilterText(OriginRepository::COLUMN_OLD_NAME, 'Old Name');
|
53
|
|
54
|
// Definice akcí
|
55
|
$this->addAction('edit', 'edit', 'Origin:edit', ['id' => OriginRepository::COLUMN_ID])
|
56
|
->setTitle('Edit');
|
57
|
|
58
|
$this->addAction('delete', 'delete', 'deleteOrigin!', ['id' => OriginRepository::COLUMN_ID])
|
59
|
->setConfirm('Do you really want to delete origin %s.', OriginRepository::COLUMN_ORIGIN)
|
60
|
->setTitle('Delete')
|
61
|
->setClass('btn btn-xs btn-danger ajax');
|
62
|
}
|
63
|
}
|
64
|
|
65
|
interface IOriginGridFactory
|
66
|
{
|
67
|
/**
|
68
|
* @return OriginGrid
|
69
|
*/
|
70
|
public function create();
|
71
|
}
|