1
|
<?php
|
2
|
|
3
|
|
4
|
namespace App\AdminModule\Components;
|
5
|
|
6
|
|
7
|
use App\Model\Repository\BookRepository;
|
8
|
use App\Model\Repository\BookTypeRepository;
|
9
|
use App\Model\Repository\MuseumRepository;
|
10
|
use App\Model\Repository\OriginRepository;
|
11
|
use App\Model\Repository\TransliterationRepository;
|
12
|
use App\Utils\DataGrid\DataGrid;
|
13
|
use Nette\Database\Table\ActiveRow;
|
14
|
use Nette\Database\Table\Selection;
|
15
|
use Ublaboo\DataGrid\Exception\DataGridException;
|
16
|
|
17
|
class TransliterationGrid extends DataGrid
|
18
|
{
|
19
|
/**
|
20
|
* @var TransliterationRepository
|
21
|
*/
|
22
|
private $transliterationRepository;
|
23
|
/**
|
24
|
* @var BookRepository
|
25
|
*/
|
26
|
private $bookRepository;
|
27
|
/**
|
28
|
* @var MuseumRepository
|
29
|
*/
|
30
|
private $museumRepository;
|
31
|
/**
|
32
|
* @var OriginRepository
|
33
|
*/
|
34
|
private $originRepository;
|
35
|
/**
|
36
|
* @var BookTypeRepository
|
37
|
*/
|
38
|
private $bookTypeRepository;
|
39
|
|
40
|
public function __construct(TransliterationRepository $transliterationRepository,
|
41
|
BookRepository $bookRepository,
|
42
|
MuseumRepository $museumRepository,
|
43
|
OriginRepository $originRepository,
|
44
|
BookTypeRepository $bookTypeRepository
|
45
|
)
|
46
|
{
|
47
|
$this->transliterationRepository = $transliterationRepository;
|
48
|
$this->bookRepository = $bookRepository;
|
49
|
$this->museumRepository = $museumRepository;
|
50
|
$this->originRepository = $originRepository;
|
51
|
$this->bookTypeRepository = $bookTypeRepository;
|
52
|
|
53
|
parent::__construct(FALSE);
|
54
|
}
|
55
|
|
56
|
/**
|
57
|
* Abstraktní metoda, slouží k nastavení primárního klíče a nastavení datasource
|
58
|
* 1. $this->setPrimaryKey();
|
59
|
* 2. $this->setDataSource();
|
60
|
*
|
61
|
* @throws DataGridException
|
62
|
*/
|
63
|
public function init()
|
64
|
{
|
65
|
$this->setPrimaryKey(TransliterationRepository::COLUMN_ID);
|
66
|
$this->setDataSource($this->transliterationRepository->findAll());
|
67
|
}
|
68
|
|
69
|
/**
|
70
|
* Definice sloupečků, akcí, vyhledávácích filtrů gridu
|
71
|
*
|
72
|
* @throws DataGridException
|
73
|
*/
|
74
|
public function define()
|
75
|
{
|
76
|
$bookRepository = $this->bookRepository;
|
77
|
$museumRepository = $this->museumRepository;
|
78
|
$originRepository = $this->originRepository;
|
79
|
$bookTypeRepository = $this->bookTypeRepository;
|
80
|
|
81
|
// ==================
|
82
|
// Definice sloupečků
|
83
|
// ==================
|
84
|
$this->addColumnNumber(TransliterationRepository::COLUMN_ID, 'ID')->setDefaultHide(TRUE);
|
85
|
$this->addColumnLink(TransliterationRepository::COLUMN_BOOK_ID, 'Book')
|
86
|
->setRenderer(function (ActiveRow $activeRow)
|
87
|
{
|
88
|
$title = $activeRow->ref(BookRepository::TABLE_NAME, BookRepository::COLUMN_ID)->{BookRepository::COLUMN_BOOK_ABREV};
|
89
|
return $this->getRendererWithLink($activeRow, $title, 'Book:edit', $activeRow->{TransliterationRepository::COLUMN_BOOK_ID});
|
90
|
});
|
91
|
$this->addColumnNumber(TransliterationRepository::COLUMN_CHAPTER, 'Chapter');
|
92
|
$this->addColumnLink(TransliterationRepository::COLUMN_MUSEUM_ID, 'Museum')
|
93
|
->setRenderer(function (ActiveRow $activeRow)
|
94
|
{
|
95
|
$title = $activeRow->ref(MuseumRepository::TABLE_NAME, MuseumRepository::COLUMN_ID)->{MuseumRepository::COLUMN_NAME};
|
96
|
return $this->getRendererWithLink($activeRow, $title, 'Museum:edit', $activeRow->{TransliterationRepository::COLUMN_MUSEUM_ID});
|
97
|
});
|
98
|
$this->addColumnText(TransliterationRepository::COLUMN_MUSEUM_NO, 'Museum No');
|
99
|
$this->addColumnLink(TransliterationRepository::COLUMN_ORIGIN_ID, 'Origin')
|
100
|
->setRenderer(function (ActiveRow $activeRow)
|
101
|
{
|
102
|
$title = $activeRow->ref(OriginRepository::TABLE_NAME, OriginRepository::COLUMN_ID)->{OriginRepository::COLUMN_ORIGIN};
|
103
|
return $this->getRendererWithLink($activeRow, $title, 'Origin:edit', $activeRow->{TransliterationRepository::COLUMN_ORIGIN_ID});
|
104
|
});
|
105
|
$this->addColumnLink(TransliterationRepository::COLUMN_BOOK_TYPE_ID, 'Book Type')
|
106
|
->setRenderer(function (ActiveRow $activeRow)
|
107
|
{
|
108
|
$title = $activeRow->ref(BookTypeRepository::TABLE_NAME, BookTypeRepository::COLUMN_ID)->{BookTypeRepository::COLUMN_BOOK_TYPE};
|
109
|
return $this->getRendererWithLink($activeRow, $title, 'BookType:edit', $activeRow->{TransliterationRepository::COLUMN_BOOK_TYPE_ID});
|
110
|
});
|
111
|
$this->addColumnText(TransliterationRepository::COLUMN_REG_NO, 'Reg No');
|
112
|
$this->addColumnText(TransliterationRepository::COLUMN_DATE, 'Date');
|
113
|
|
114
|
// ===============
|
115
|
// Definice filtrů
|
116
|
// ===============
|
117
|
$this->addFilterText(TransliterationRepository::COLUMN_BOOK_ID, 'Book')
|
118
|
->setCondition(function (Selection $selection, $value) use ($bookRepository)
|
119
|
{
|
120
|
$bookIds = $bookRepository->getBooksLikeBookAbbrev($value)->fetchField(BookRepository::COLUMN_ID);
|
121
|
$bookIds = $bookIds ? $bookIds : NULL;
|
122
|
|
123
|
$selection->where(BookRepository::COLUMN_ID, $bookIds);
|
124
|
});
|
125
|
$this->addFilterText(TransliterationRepository::COLUMN_CHAPTER, 'Chapter');
|
126
|
$this->addFilterText(TransliterationRepository::COLUMN_MUSEUM_ID, 'Museum')
|
127
|
->setCondition(function (Selection $selection, $value) use ($museumRepository)
|
128
|
{
|
129
|
$museumIds = $museumRepository->getMuseumsLikeName($value)->fetchField(MuseumRepository::COLUMN_ID);
|
130
|
$museumIds = $museumIds ? $museumIds : NULL;
|
131
|
|
132
|
$selection->where(MuseumRepository::COLUMN_ID, $museumIds);
|
133
|
});
|
134
|
$this->addFilterText(TransliterationRepository::COLUMN_MUSEUM_NO, 'Museum No');
|
135
|
$this->addFilterText(TransliterationRepository::COLUMN_ORIGIN_ID, 'Origin')
|
136
|
->setCondition(function (Selection $selection, $value) use ($originRepository)
|
137
|
{
|
138
|
$originIds = $originRepository->getOriginsLikeName($value)->fetchField(OriginRepository::COLUMN_ID);
|
139
|
$originIds = $originIds ? $originIds : NULL;
|
140
|
|
141
|
$selection->where(OriginRepository::COLUMN_ID, $originIds);
|
142
|
});
|
143
|
$this->addFilterText(TransliterationRepository::COLUMN_BOOK_TYPE_ID, 'Book Type')
|
144
|
->setCondition(function (Selection $selection, $value) use ($bookTypeRepository)
|
145
|
{
|
146
|
$bookTypeIds = $bookTypeRepository->getBookTypesLikeType($value)->fetchField(BookTypeRepository::COLUMN_ID);
|
147
|
$bookTypeIds = $bookTypeIds ? $bookTypeIds : NULL;
|
148
|
|
149
|
$selection->where(BookTypeRepository::COLUMN_ID, $bookTypeIds);
|
150
|
});
|
151
|
$this->addFilterText(TransliterationRepository::COLUMN_REG_NO, 'Reg No');
|
152
|
$this->addFilterText(TransliterationRepository::COLUMN_DATE, 'Date');
|
153
|
|
154
|
// =============
|
155
|
// Definice akcí
|
156
|
// =============
|
157
|
// $this->addAction('edit', 'edit', 'Transliteration:edit', ['id' => TransliterationRepository::COLUMN_ID])
|
158
|
// ->setTitle('Edit');
|
159
|
|
160
|
$this->addAction('delete', 'delete', 'deleteTransliteration!', ['id' => TransliterationRepository::COLUMN_ID])
|
161
|
->setConfirm('Do you really want to delete transliteration?')
|
162
|
->setTitle('Delete')
|
163
|
->setClass('btn btn-xs btn-danger ajax');
|
164
|
}
|
165
|
}
|
166
|
|
167
|
interface ITransliterationGridFactory
|
168
|
{
|
169
|
/**
|
170
|
* @return TransliterationGrid
|
171
|
*/
|
172
|
public function create();
|
173
|
}
|