Revize 3f8f3bd6
Přidáno uživatelem Filip Jani před téměř 6 roky(ů)
app/AdminModule/component/Transliteration/TransliterationGrid.php | ||
---|---|---|
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 |
} |
app/AdminModule/presenters/TransliterationPresenter.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
|
|
4 |
namespace App\AdminModule\Presenters; |
|
5 |
|
|
6 |
|
|
7 |
use App\AdminModule\Components\ITransliterationGridFactory; |
|
8 |
use App\Model\Repository\TransliterationRepository; |
|
9 |
|
|
10 |
class TransliterationPresenter extends BaseUserPresenter |
|
11 |
{ |
|
12 |
/** |
|
13 |
* @var ITransliterationGridFactory |
|
14 |
*/ |
|
15 |
private $transliterationGridFactory; |
|
16 |
|
|
17 |
public function __construct(ITransliterationGridFactory $transliterationGridFactory, |
|
18 |
TransliterationRepository $transliterationRepository) |
|
19 |
{ |
|
20 |
parent::__construct(); |
|
21 |
$this->transliterationGridFactory = $transliterationGridFactory; |
|
22 |
} |
|
23 |
|
|
24 |
/** |
|
25 |
* Handle používaný v TransliterationGrid pro smazání transliterace |
|
26 |
* |
|
27 |
* @param int $id : ID transliterace |
|
28 |
*/ |
|
29 |
public function handleDeleteTransliteration(int $id) |
|
30 |
{ |
|
31 |
if ($this->isAjax()) |
|
32 |
{ |
|
33 |
$this->transliterationGridFactory->findRow($id)->delete(); |
|
34 |
$this['transliterationGrid']->reload(); |
|
35 |
} |
|
36 |
} |
|
37 |
|
|
38 |
public function createComponentTransliterationGrid() |
|
39 |
{ |
|
40 |
return $this->transliterationGridFactory->create(); |
|
41 |
} |
|
42 |
} |
app/AdminModule/templates/Transliteration/default.latte | ||
---|---|---|
1 |
{block content} |
|
2 |
<div class="row"> |
|
3 |
<div class="col-10"> |
|
4 |
<div class="display-5">Transliteration List</div> |
|
5 |
</div> |
|
6 |
<div class="col-2 text-right"> |
|
7 |
{* <a n:href="Transliteration:addType" class="btn btn-sm btn-success"><span class="fa fa-fw fa-plus"></span> New Surface Type</a>*} |
|
8 |
</div> |
|
9 |
</div> |
|
10 |
<div class="row"> |
|
11 |
<div class="col-10 offset-1"> |
|
12 |
{control transliterationGrid} |
|
13 |
</div> |
|
14 |
</div> |
|
15 |
|
|
16 |
{/block} |
app/config/components.neon | ||
---|---|---|
8 | 8 |
- App\AdminModule\Components\ISurfaceTypeGridFactory |
9 | 9 |
- App\AdminModule\Components\IBookTypeGridFactory |
10 | 10 |
- App\AdminModule\Components\IBookGridFactory |
11 |
- App\AdminModule\Components\ITransliterationGridFactory |
|
11 | 12 |
|
12 | 13 |
# Formuláře |
13 | 14 |
- App\FrontModule\Components\ILoginFormFactory |
app/model/repository/BookRepository.php | ||
---|---|---|
26 | 26 |
const COLUMN_VOLUME = 'volume'; |
27 | 27 |
const COLUMN_VOLUME_NO = 'volume_no'; |
28 | 28 |
const COLUMN_REVISION_HISTORY = 'revision_history'; |
29 |
|
|
30 |
/** |
|
31 |
* Vrací knihy se zkratkou LIKE % $bookName % |
|
32 |
* |
|
33 |
* @param string $bookName |
|
34 |
* @return \Nette\Database\Table\Selection |
|
35 |
*/ |
|
36 |
public function getBooksLikeBookAbbrev(string $bookName) |
|
37 |
{ |
|
38 |
return $this->findAll()->where(self::COLUMN_BOOK_ABREV . ' LIKE', '%' . $bookName . '%'); |
|
39 |
} |
|
29 | 40 |
} |
app/model/repository/BookTypeRepository.php | ||
---|---|---|
38 | 38 |
$types[0] = '- NOT SELECTED -'; |
39 | 39 |
return $types; |
40 | 40 |
} |
41 |
|
|
42 |
/** |
|
43 |
* Vrací typ knihy LIKE % $name % |
|
44 |
* |
|
45 |
* @param string $name |
|
46 |
* @return \Nette\Database\Table\Selection |
|
47 |
*/ |
|
48 |
public function getBookTypesLikeType(string $name) |
|
49 |
{ |
|
50 |
return $this->findAll()->where(self::COLUMN_BOOK_TYPE . ' LIKE', '%' . $name . '%'); |
|
51 |
} |
|
41 | 52 |
} |
app/model/repository/MuseumRepository.php | ||
---|---|---|
28 | 28 |
{ |
29 | 29 |
return $this->findBy([self::COLUMN_NAME => $name]); |
30 | 30 |
} |
31 |
|
|
32 |
/** |
|
33 |
* Vrací muzea podle názvu LIKE % $name % |
|
34 |
* |
|
35 |
* @param string $name |
|
36 |
* @return \Nette\Database\Table\Selection |
|
37 |
*/ |
|
38 |
public function getMuseumsLikeName(string $name) |
|
39 |
{ |
|
40 |
return $this->findAll()->where(self::COLUMN_NAME . ' LIKE', '%' . $name . '%'); |
|
41 |
} |
|
31 | 42 |
} |
app/model/repository/OriginRepository.php | ||
---|---|---|
28 | 28 |
$origins[0] = '- NOT SELECTED -'; |
29 | 29 |
return $origins; |
30 | 30 |
} |
31 |
|
|
32 |
/** Vrací místa původu se názvem LIKE % $name % |
|
33 |
* |
|
34 |
* @param string $name |
|
35 |
* @return \Nette\Database\Table\Selection |
|
36 |
*/ |
|
37 |
public function getOriginsLikeName(string $name) |
|
38 |
{ |
|
39 |
return $this->findAll()->where(self::COLUMN_ORIGIN . ' LIKE', '%' . $name . '%'); |
|
40 |
} |
|
31 | 41 |
} |
app/utils/datagrid/DataGrid.php | ||
---|---|---|
2 | 2 |
|
3 | 3 |
namespace App\Utils\DataGrid; |
4 | 4 |
|
5 |
use App\Model\Repository\BookRepository; |
|
6 |
use Nette\Database\Table\ActiveRow; |
|
5 | 7 |
use Nette\Database\Table\Selection; |
6 | 8 |
use Ublaboo\DataGrid\Column\ColumnDateTime; |
7 | 9 |
use Ublaboo\DataGrid\Column\ColumnNumber; |
... | ... | |
171 | 173 |
return $filterText; |
172 | 174 |
} |
173 | 175 |
|
176 |
/** |
|
177 |
* Umožnění filtrování sloupečků s odkazem |
|
178 |
* |
|
179 |
* @param string $key |
|
180 |
* @param string $name |
|
181 |
* @param null $href |
|
182 |
* @param null $column |
|
183 |
* @param array|null $params |
|
184 |
* @return \Ublaboo\DataGrid\Column\ColumnLink|null |
|
185 |
*/ |
|
186 |
public function addColumnLink($key, $name, $href = null, $column = null, array $params = null) |
|
187 |
{ |
|
188 |
$column = parent::addColumnLink($key, $name, $href, $column, $params); |
|
189 |
$column->setSortable(); |
|
190 |
$column->setTemplateEscaping(FALSE); |
|
191 |
|
|
192 |
return $column; |
|
193 |
} |
|
194 |
|
|
195 |
/** |
|
196 |
* Generování odkazu pro tabulky, které jsou přes cizí klíč |
|
197 |
* |
|
198 |
* @param ActiveRow $activeRow |
|
199 |
* @param string $title |
|
200 |
* @param string $destination |
|
201 |
* @param int $id |
|
202 |
* @return string |
|
203 |
* @throws \Nette\Application\UI\InvalidLinkException |
|
204 |
*/ |
|
205 |
public function getRendererWithLink(ActiveRow $activeRow, string $title, string $destination, int $id): string |
|
206 |
{ |
|
207 |
$link = $this->presenter->link($destination, ['id' => $id]); |
|
208 |
|
|
209 |
$title = !empty($title) ? $title : 'empty'; |
|
210 |
return '<a href="' . $link . '">' . $title . '</a>'; |
|
211 |
} |
|
212 |
|
|
174 | 213 |
/** |
175 | 214 |
* Fixnutí zobrazování všech záznamů v českém překladu gridu |
176 | 215 |
* |
Také k dispozici: Unified diff
Re #7333 Vytvoření gridu pro správu transliterací