1
|
<?php
|
2
|
|
3
|
|
4
|
namespace App\AdminModule\Components;
|
5
|
|
6
|
|
7
|
use App\Model\Repository\UserRepository;
|
8
|
use App\Utils\DataGrid\DataGrid;
|
9
|
use Ublaboo\DataGrid\Exception\DataGridException;
|
10
|
|
11
|
class UserGrid extends DataGrid
|
12
|
{
|
13
|
/**
|
14
|
* @var UserRepository
|
15
|
*/
|
16
|
private $userRepository;
|
17
|
|
18
|
public function __construct(UserRepository $userRepository)
|
19
|
{
|
20
|
$this->userRepository = $userRepository;
|
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(UserRepository::COLUMN_ID);
|
35
|
$this->setDataSource($this->userRepository->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(UserRepository::COLUMN_ID, 'ID')->setDefaultHide(TRUE);
|
47
|
$this->addColumnText(UserRepository::COLUMN_USERNAME, 'Uživatel');
|
48
|
$this->addColumnText(UserRepository::COLUMN_LOGIN, 'Login');
|
49
|
$this->addColumnText(UserRepository::COLUMN_EMAIL, 'Email');
|
50
|
|
51
|
// Definice filtrů
|
52
|
$this->addFilterText(UserRepository::COLUMN_USERNAME, 'Uživatel');
|
53
|
$this->addFilterText(UserRepository::COLUMN_LOGIN, 'Login');
|
54
|
$this->addFilterText(UserRepository::COLUMN_EMAIL, 'Email');
|
55
|
|
56
|
// Akce
|
57
|
$this->addAction('edit', 'upravit', 'User:edit', ['id' => UserRepository::COLUMN_ID])
|
58
|
->setTitle('Editovat');
|
59
|
|
60
|
$this->addAction('delete', 'smazat', 'deleteUser!', ['id' => UserRepository::COLUMN_ID])
|
61
|
->setConfirm('Opravdu chcete uživatele "%s" odstranit?', UserRepository::COLUMN_LOGIN)
|
62
|
->setTitle('Odstranit')
|
63
|
->setClass('btn btn-xs btn-danger ajax');
|
64
|
}
|
65
|
}
|
66
|
|
67
|
interface IUserGridFactory
|
68
|
{
|
69
|
/**
|
70
|
* @return UserGrid
|
71
|
*/
|
72
|
public function create();
|
73
|
}
|