Revize 1cc8ab3c
Přidáno uživatelem Filip Jani před téměř 6 roky(ů)
app/AdminModule/component/Transliteration/TransliterationGrid.php | ||
---|---|---|
75 | 75 |
{ |
76 | 76 |
$bookRepository = $this->bookRepository; |
77 | 77 |
$museumRepository = $this->museumRepository; |
78 |
$originRepository = $this->originRepository; |
|
79 |
$bookTypeRepository = $this->bookTypeRepository; |
|
80 | 78 |
|
81 | 79 |
// ================== |
82 | 80 |
// Definice sloupečků |
... | ... | |
85 | 83 |
$this->addColumnLink(TransliterationRepository::COLUMN_BOOK_ID, 'Book') |
86 | 84 |
->setRenderer(function (ActiveRow $activeRow) |
87 | 85 |
{ |
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}); |
|
86 |
return $this->getRenderer( |
|
87 |
$activeRow, |
|
88 |
BookRepository::TABLE_NAME, |
|
89 |
BookRepository::COLUMN_ID, |
|
90 |
BookRepository::COLUMN_BOOK_ABREV, |
|
91 |
TransliterationRepository::COLUMN_BOOK_ID |
|
92 |
); |
|
90 | 93 |
}); |
91 | 94 |
$this->addColumnNumber(TransliterationRepository::COLUMN_CHAPTER, 'Chapter'); |
92 | 95 |
$this->addColumnLink(TransliterationRepository::COLUMN_MUSEUM_ID, 'Museum') |
93 | 96 |
->setRenderer(function (ActiveRow $activeRow) |
94 | 97 |
{ |
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}); |
|
98 |
return $this->getRenderer( |
|
99 |
$activeRow, |
|
100 |
MuseumRepository::TABLE_NAME, |
|
101 |
MuseumRepository::COLUMN_ID, |
|
102 |
MuseumRepository::COLUMN_NAME, |
|
103 |
TransliterationRepository::COLUMN_MUSEUM_ID |
|
104 |
); |
|
97 | 105 |
}); |
98 | 106 |
$this->addColumnText(TransliterationRepository::COLUMN_MUSEUM_NO, 'Museum No'); |
99 | 107 |
$this->addColumnLink(TransliterationRepository::COLUMN_ORIGIN_ID, 'Origin') |
100 | 108 |
->setRenderer(function (ActiveRow $activeRow) |
101 | 109 |
{ |
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}); |
|
110 |
return $this->getRenderer( |
|
111 |
$activeRow, |
|
112 |
OriginRepository::TABLE_NAME, |
|
113 |
OriginRepository::COLUMN_ID, |
|
114 |
OriginRepository::COLUMN_ORIGIN, |
|
115 |
TransliterationRepository::COLUMN_ORIGIN_ID |
|
116 |
); |
|
104 | 117 |
}); |
105 | 118 |
$this->addColumnLink(TransliterationRepository::COLUMN_BOOK_TYPE_ID, 'Book Type') |
106 | 119 |
->setRenderer(function (ActiveRow $activeRow) |
107 | 120 |
{ |
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}); |
|
121 |
return $this->getRenderer( |
|
122 |
$activeRow, |
|
123 |
BookTypeRepository::TABLE_NAME, |
|
124 |
BookTypeRepository::COLUMN_ID, |
|
125 |
BookTypeRepository::COLUMN_BOOK_TYPE, |
|
126 |
TransliterationRepository::COLUMN_BOOK_TYPE_ID |
|
127 |
); |
|
110 | 128 |
}); |
111 | 129 |
$this->addColumnText(TransliterationRepository::COLUMN_REG_NO, 'Reg No'); |
112 | 130 |
$this->addColumnText(TransliterationRepository::COLUMN_DATE, 'Date'); |
... | ... | |
132 | 150 |
$selection->where(MuseumRepository::COLUMN_ID, $museumIds); |
133 | 151 |
}); |
134 | 152 |
$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 |
}); |
|
153 |
$this->addFilterSelect(TransliterationRepository::COLUMN_ORIGIN_ID, 'Origin', $this->getOriginFilterArray()); |
|
154 |
$this->addFilterSelect(TransliterationRepository::COLUMN_BOOK_TYPE_ID, 'Book Type', $this->getBookTypeFilterArray()); |
|
151 | 155 |
$this->addFilterText(TransliterationRepository::COLUMN_REG_NO, 'Reg No'); |
152 | 156 |
$this->addFilterText(TransliterationRepository::COLUMN_DATE, 'Date'); |
153 | 157 |
|
158 |
// Zakázání zobrazení všech položek, protože jinak se grid sekne a nelze resetovat |
|
159 |
$this->setItemsPerPageList([10, 20, 50, 100], FALSE); |
|
160 |
|
|
154 | 161 |
// ============= |
155 | 162 |
// Definice akcí |
156 | 163 |
// ============= |
... | ... | |
162 | 169 |
->setTitle('Delete') |
163 | 170 |
->setClass('btn btn-xs btn-danger ajax'); |
164 | 171 |
} |
172 |
|
|
173 |
/** |
|
174 |
* Vrací pole s možnostmi pro combobox filtr místa původu |
|
175 |
* |
|
176 |
* @return array |
|
177 |
*/ |
|
178 |
private function getOriginFilterArray() |
|
179 |
{ |
|
180 |
$array = $this->originRepository->findAll()->fetchPairs(OriginRepository::COLUMN_ID, OriginRepository::COLUMN_ORIGIN); |
|
181 |
sort($array); |
|
182 |
return $array; |
|
183 |
} |
|
184 |
|
|
185 |
/** |
|
186 |
* Vrací pole s možnostmi pro combobox filtr typu knihy |
|
187 |
* |
|
188 |
* @return array |
|
189 |
*/ |
|
190 |
private function getBookTypeFilterArray() |
|
191 |
{ |
|
192 |
$array = $this->bookTypeRepository->findAll()->fetchPairs(BookTypeRepository::COLUMN_ID, BookTypeRepository::COLUMN_BOOK_TYPE); |
|
193 |
sort($array); |
|
194 |
return $array; |
|
195 |
} |
|
196 |
|
|
197 |
/** |
|
198 |
* Vrací renderer pro vlastní zobrazení názvu místo ID cizího klíče v gridu |
|
199 |
* |
|
200 |
* @param ActiveRow $activeRow |
|
201 |
* @param string $key |
|
202 |
* @param string $throughColumn |
|
203 |
* @param string $titleColumn |
|
204 |
* @param string $idColumn |
|
205 |
* @return string |
|
206 |
* @throws \Nette\Application\UI\InvalidLinkException |
|
207 |
*/ |
|
208 |
private function getRenderer(ActiveRow $activeRow, string $key, string $throughColumn, string $titleColumn, string $idColumn) |
|
209 |
{ |
|
210 |
$ref = $activeRow->ref($key, $throughColumn); |
|
211 |
|
|
212 |
if ($ref) |
|
213 |
{ |
|
214 |
$title = $ref->{$titleColumn}; |
|
215 |
return $this->getRendererWithLink($activeRow, $title, 'Book:edit', $activeRow->{$idColumn}); |
|
216 |
} else |
|
217 |
{ |
|
218 |
return ""; |
|
219 |
} |
|
220 |
} |
|
165 | 221 |
} |
166 | 222 |
|
167 | 223 |
interface ITransliterationGridFactory |
Také k dispozici: Unified diff
Re #7333 úprava filtrování