Revize 3ea90ef0
Přidáno uživatelem Jan Palcút před téměř 6 roky(ů)
app/AdminModule/component/Transliteration/TransliterationEditForm.latte | ||
---|---|---|
1 |
<div class="row"> |
|
2 |
<div class="col-4"> |
|
3 |
{control form} |
|
1 |
{form form} |
|
2 |
<div class="row"> |
|
3 |
<div class="col-4"> |
|
4 |
<div class="row mb-2"> |
|
5 |
<div class="col-4"> |
|
6 |
{label \App\Model\Repository\TransliterationRepository::COLUMN_BOOK_ID} |
|
7 |
</div> |
|
8 |
<div class="col-8"> |
|
9 |
{input \App\Model\Repository\TransliterationRepository::COLUMN_BOOK_ID} |
|
10 |
</div> |
|
11 |
</div> |
|
12 |
|
|
13 |
<div class="row mb-2"> |
|
14 |
<div class="col-4"> |
|
15 |
{label \App\Model\Repository\TransliterationRepository::COLUMN_CHAPTER} |
|
16 |
</div> |
|
17 |
<div class="col-8"> |
|
18 |
{input \App\Model\Repository\TransliterationRepository::COLUMN_CHAPTER} |
|
19 |
</div> |
|
20 |
</div> |
|
21 |
|
|
22 |
<div class="row mb-2"> |
|
23 |
<div class="col-4"> |
|
24 |
{label \App\Model\Repository\TransliterationRepository::COLUMN_MUSEUM_ID} |
|
25 |
</div> |
|
26 |
<div class="col-8"> |
|
27 |
{input \App\Model\Repository\TransliterationRepository::COLUMN_MUSEUM_ID} |
|
28 |
</div> |
|
29 |
</div> |
|
30 |
|
|
31 |
<div class="row mb-2"> |
|
32 |
<div class="col-4"> |
|
33 |
{label \App\Model\Repository\TransliterationRepository::COLUMN_MUSEUM_NO} |
|
34 |
</div> |
|
35 |
<div class="col-8"> |
|
36 |
{input \App\Model\Repository\TransliterationRepository::COLUMN_MUSEUM_NO} |
|
37 |
</div> |
|
38 |
</div> |
|
39 |
|
|
40 |
<div class="row mb-2"> |
|
41 |
<div class="col-4"> |
|
42 |
{label \App\Model\Repository\TransliterationRepository::COLUMN_REG_NO} |
|
43 |
</div> |
|
44 |
<div class="col-8"> |
|
45 |
{input \App\Model\Repository\TransliterationRepository::COLUMN_REG_NO} |
|
46 |
</div> |
|
47 |
</div> |
|
48 |
|
|
49 |
<div class="row mb-2"> |
|
50 |
<div class="col-4"> |
|
51 |
{label \App\Model\Repository\TransliterationRepository::COLUMN_ORIGIN_ID} |
|
52 |
</div> |
|
53 |
<div class="col-8"> |
|
54 |
{input \App\Model\Repository\TransliterationRepository::COLUMN_ORIGIN_ID} |
|
55 |
</div> |
|
56 |
</div> |
|
57 |
|
|
58 |
<div class="row mb-2"> |
|
59 |
<div class="col-4"> |
|
60 |
{label \App\Model\Repository\TransliterationRepository::COLUMN_BOOK_TYPE_ID} |
|
61 |
</div> |
|
62 |
<div class="col-8"> |
|
63 |
{input \App\Model\Repository\TransliterationRepository::COLUMN_BOOK_TYPE_ID} |
|
64 |
</div> |
|
65 |
</div> |
|
66 |
|
|
67 |
<div class="row mb-2"> |
|
68 |
<div class="col-4"> |
|
69 |
{label \App\Model\Repository\TransliterationRepository::COLUMN_DATE} |
|
70 |
</div> |
|
71 |
<div class="col-8"> |
|
72 |
{input \App\Model\Repository\TransliterationRepository::COLUMN_DATE} |
|
73 |
</div> |
|
74 |
</div> |
|
75 |
|
|
76 |
<div class="row mb-2"> |
|
77 |
<div class="col-4"> |
|
78 |
{label \App\Model\Repository\TransliterationRepository::COLUMN_NOTE} |
|
79 |
</div> |
|
80 |
<div class="col-8"> |
|
81 |
{input \App\Model\Repository\TransliterationRepository::COLUMN_NOTE} |
|
82 |
</div> |
|
83 |
</div> |
|
84 |
</div> |
|
4 | 85 |
</div> |
5 |
</div> |
|
86 |
|
|
87 |
<div class="row"> |
|
88 |
<div class="col-12"> |
|
89 |
<h5>References</h5> |
|
90 |
<div n:multiplier="references"> |
|
91 |
<div class="row mb-2"> |
|
92 |
|
|
93 |
<div class="col-2"> |
|
94 |
<input n:name="\App\Model\Repository\LitReferenceRepository::COLUMN_SERIES" n:class="form-control" |
|
95 |
required></div> |
|
96 |
|
|
97 |
<div class="col-2"> |
|
98 |
<input n:name="\App\Model\Repository\LitReferenceRepository::COLUMN_NUMBER" n:class="form-control"> |
|
99 |
</div> |
|
100 |
|
|
101 |
<div class="col-2"> |
|
102 |
<input n:name="\App\Model\Repository\LitReferenceRepository::COLUMN_PLATE" n:class="form-control"> |
|
103 |
</div> |
|
104 |
<div class="col-2">{btnRemove 'class' => 'btn btn-danger'}</div> |
|
105 |
</div> |
|
106 |
</div> |
|
107 |
|
|
108 |
{btnCreate references class => 'btn btn-info'} |
|
109 |
</div> |
|
110 |
</div> |
|
111 |
|
|
112 |
<div class="row mt-2"> |
|
113 |
<div class="col-4"> |
|
114 |
{input submit} |
|
115 |
</div> |
|
116 |
</div> |
|
117 |
|
|
118 |
{/form} |
|
119 |
|
app/AdminModule/component/Transliteration/TransliterationEditForm.php | ||
---|---|---|
3 | 3 |
|
4 | 4 |
namespace App\AdminModule\Components; |
5 | 5 |
|
6 |
use App\Enum\EFlashMessage; |
|
7 |
use App\Model\Repository\BookRepository; |
|
8 |
use App\Model\Repository\BookTypeRepository; |
|
9 |
use App\Model\Repository\LitReferenceRepository; |
|
10 |
use App\Model\Repository\MuseumRepository; |
|
11 |
use App\Model\Repository\OriginRepository; |
|
6 | 12 |
use App\Model\Repository\TransliterationRepository; |
7 | 13 |
use App\Utils\Form; |
8 | 14 |
use Nette\Application\UI\Control; |
15 |
use Nette\Forms\Container; |
|
9 | 16 |
|
10 | 17 |
/** |
11 | 18 |
* Class TransliterationEditForm |
... | ... | |
28 | 35 |
*/ |
29 | 36 |
private $transliterationRepository; |
30 | 37 |
|
38 |
/** |
|
39 |
* @var BookRepository |
|
40 |
*/ |
|
41 |
private $bookRepository; |
|
42 |
|
|
43 |
/** |
|
44 |
* @var MuseumRepository |
|
45 |
*/ |
|
46 |
private $museumRepository; |
|
47 |
/** |
|
48 |
* @var OriginRepository |
|
49 |
*/ |
|
50 |
private $originRepository; |
|
51 |
/** |
|
52 |
* @var BookTypeRepository |
|
53 |
*/ |
|
54 |
private $bookTypeRepository; |
|
55 |
/** |
|
56 |
* @var LitReferenceRepository |
|
57 |
*/ |
|
58 |
private $litReferenceRepository; |
|
59 |
|
|
31 | 60 |
/** |
32 | 61 |
* TransliterationEditForm constructor. |
33 | 62 |
* @param TransliterationRepository $transliterationRepository |
34 | 63 |
*/ |
35 |
public function __construct(TransliterationRepository $transliterationRepository) |
|
64 |
public function __construct(TransliterationRepository $transliterationRepository, BookRepository $bookRepository, |
|
65 |
MuseumRepository $museumRepository, OriginRepository $originRepository, |
|
66 |
BookTypeRepository $bookTypeRepository, LitReferenceRepository $litReferenceRepository) |
|
36 | 67 |
{ |
37 | 68 |
parent::__construct(); |
38 | 69 |
|
39 | 70 |
$this->transliterationRepository = $transliterationRepository; |
71 |
$this->bookRepository = $bookRepository; |
|
72 |
$this->museumRepository = $museumRepository; |
|
73 |
|
|
40 | 74 |
$this->transliterationId = NULL; |
41 | 75 |
$this->form = new Form; |
76 |
$this->originRepository = $originRepository; |
|
77 |
$this->bookTypeRepository = $bookTypeRepository; |
|
78 |
$this->litReferenceRepository = $litReferenceRepository; |
|
42 | 79 |
} |
43 | 80 |
|
44 | 81 |
public function render() |
... | ... | |
49 | 86 |
|
50 | 87 |
public function createComponentForm() |
51 | 88 |
{ |
52 |
$this->form->addText(TransliterationRepository::COLUMN_ID, 'Book Type') |
|
53 |
->addRule(Form::REQUIRED, 'Field %label is required.'); |
|
89 |
$this->form->addSelect(TransliterationRepository::COLUMN_BOOK_ID, 'Book', $this->bookRepository->getBookAbbrevForSelect()); |
|
90 |
$this->form->addText(TransliterationRepository::COLUMN_CHAPTER, 'Chapter'); |
|
91 |
$this->form->addSelect(TransliterationRepository::COLUMN_MUSEUM_ID, 'Museum', $this->museumRepository->getMuseumNameForSelect()); |
|
92 |
$this->form->addText(TransliterationRepository::COLUMN_MUSEUM_NO, 'Museum No'); |
|
93 |
$this->form->addText(TransliterationRepository::COLUMN_REG_NO, 'Reg No'); |
|
94 |
$this->form->addSelect(TransliterationRepository::COLUMN_ORIGIN_ID, 'Origin', $this->originRepository->getOriginsForSelect()); |
|
95 |
$this->form->addSelect(TransliterationRepository::COLUMN_BOOK_TYPE_ID, 'Book Type', $this->bookTypeRepository->getTypesForSelect()); |
|
96 |
$this->form->addText(TransliterationRepository::COLUMN_DATE, 'Date'); |
|
97 |
$this->form->addText(TransliterationRepository::COLUMN_NOTE, 'Note'); |
|
98 |
|
|
99 |
// Definice dynamických prvků |
|
100 |
$multiplier = $this->form->addMultiplier('references', function (Container $container) |
|
101 |
{ |
|
102 |
$container->addHidden(LitReferenceRepository::COLUMN_ID); |
|
103 |
$container->addText(LitReferenceRepository::COLUMN_SERIES, 'Series'); |
|
104 |
$container->addText(LitReferenceRepository::COLUMN_NUMBER, 'Number'); |
|
105 |
$container->addText(LitReferenceRepository::COLUMN_PLATE, 'Page'); |
|
106 |
}, 0); |
|
107 |
|
|
108 |
// Definice tlačítek pro přidání / odebrání řádku |
|
109 |
$multiplier->addCreateButton('Add')->addClass('btn btn-primary'); |
|
110 |
$multiplier->addRemoveButton('Remove')->addClass('btn btn-danger'); |
|
111 |
|
|
112 |
$this->form->setDefaults($this->getDefaults()); |
|
113 |
|
|
114 |
$this->form->addSubmit('submit', 'Save'); |
|
115 |
|
|
116 |
$this->form->onSuccess[] = [$this, 'formSuccess']; |
|
117 |
|
|
54 | 118 |
return $this->form; |
55 | 119 |
} |
56 | 120 |
|
121 |
/** |
|
122 |
* Zpracování editace informací o transliteraci |
|
123 |
* |
|
124 |
* @param Form $form |
|
125 |
*/ |
|
126 |
public function formSuccess(Form $form) |
|
127 |
{ |
|
128 |
|
|
129 |
$values = $form->getValues(true); |
|
130 |
$references = $values['references']; |
|
131 |
|
|
132 |
if ($this->isAnyReferenceEmpty($references)) |
|
133 |
{ |
|
134 |
$this->presenter->flashMessage('Transliteration could not be saved.', EFlashMessage::ERROR); |
|
135 |
return; |
|
136 |
} |
|
137 |
|
|
138 |
unset($values['references']); |
|
139 |
|
|
140 |
$this->transliterationRepository->save($values, $this->transliterationId); |
|
141 |
|
|
142 |
$this->deleteRemovedReferences($references); |
|
143 |
|
|
144 |
foreach ($references as $item) |
|
145 |
{ |
|
146 |
$item[LitReferenceRepository::COLUMN_TRANSLITERATION_ID] = $this->transliterationId; |
|
147 |
$this->litReferenceRepository->save($item, (int)$item[LitReferenceRepository::COLUMN_ID]); |
|
148 |
} |
|
149 |
|
|
150 |
$this->presenter->flashMessage('Transliteration was successfully saved.', EFlashMessage::SUCCESS); |
|
151 |
|
|
152 |
} |
|
153 |
|
|
154 |
/** |
|
155 |
* Zkontroluje jestli není nějaká refence prázná |
|
156 |
* |
|
157 |
* @param $references pole referencí |
|
158 |
* @return bool |
|
159 |
*/ |
|
160 |
public function isAnyReferenceEmpty($references) |
|
161 |
{ |
|
162 |
foreach ($references as $r) |
|
163 |
{ |
|
164 |
if (empty($r[LitReferenceRepository::COLUMN_SERIES]) && empty($r[LitReferenceRepository::COLUMN_NUMBER]) |
|
165 |
&& empty($r[LitReferenceRepository::COLUMN_PLATE])) |
|
166 |
{ |
|
167 |
return true; |
|
168 |
} |
|
169 |
} |
|
170 |
return false; |
|
171 |
} |
|
172 |
|
|
173 |
/** |
|
174 |
* Odstraní odebrané reference transliterace |
|
175 |
* |
|
176 |
* @param $newReferences pole nových transliterací |
|
177 |
*/ |
|
178 |
public function deleteRemovedReferences($newReferences) |
|
179 |
{ |
|
180 |
$references = $this->litReferenceRepository->findByTransliterationId($this->transliterationId); |
|
181 |
|
|
182 |
foreach ($references as $ref) |
|
183 |
{ |
|
184 |
if ($this->isRemovedReference($ref, $newReferences)) |
|
185 |
{ |
|
186 |
$this->litReferenceRepository->delete($ref[LitReferenceRepository::COLUMN_ID]); |
|
187 |
} |
|
188 |
} |
|
189 |
|
|
190 |
} |
|
191 |
|
|
192 |
/** |
|
193 |
* Zkontroluje jestli je refence v poli referencí |
|
194 |
* |
|
195 |
* @param $reference reference ke kontrole |
|
196 |
* @param $newReferences pole referencí |
|
197 |
* @return bool |
|
198 |
*/ |
|
199 |
public function isRemovedReference($reference, $newReferences) |
|
200 |
{ |
|
201 |
foreach ($newReferences as $ref) |
|
202 |
{ |
|
203 |
if ($ref[LitReferenceRepository::COLUMN_ID] == $reference[LitReferenceRepository::COLUMN_ID]) |
|
204 |
{ |
|
205 |
return false; |
|
206 |
} |
|
207 |
} |
|
208 |
return true; |
|
209 |
} |
|
210 |
|
|
57 | 211 |
/** |
58 | 212 |
* Nastavení ID transliterace při editaci |
59 | 213 |
* |
... | ... | |
64 | 218 |
$this->transliterationId = $transliterationId; |
65 | 219 |
} |
66 | 220 |
|
221 |
/** |
|
222 |
* Vrátí výchozí informace o transliteraci |
|
223 |
* |
|
224 |
* @return array |
|
225 |
*/ |
|
226 |
private function getDefaults() |
|
227 |
{ |
|
228 |
$array = $this->transliterationRepository->findRow($this->transliterationId)->toArray(); |
|
229 |
$references = $this->litReferenceRepository->findByTransliterationId($this->transliterationId)->fetchAll(); |
|
230 |
|
|
231 |
foreach ($references as $activeRow) |
|
232 |
{ |
|
233 |
$array['references'][] = $activeRow->toArray(); |
|
234 |
} |
|
235 |
|
|
236 |
return $array; |
|
237 |
} |
|
238 |
|
|
67 | 239 |
} |
68 | 240 |
|
69 |
interface ITransliterationEditFormFactory{ |
|
241 |
interface ITransliterationEditFormFactory |
|
242 |
{ |
|
70 | 243 |
|
71 | 244 |
/** |
72 | 245 |
* @return TransliterationEditForm |
app/AdminModule/templates/Transliteration/edit.latte | ||
---|---|---|
1 | 1 |
{block content} |
2 |
<div class="row"> |
|
3 |
<div class="col-12"> |
|
4 |
<div class="display-5">Edit Transliteration</div> |
|
5 |
</div> |
|
6 |
</div> |
|
2 | 7 |
{control transliterationEditForm} |
3 | 8 |
{/block} |
app/model/repository/BookRepository.php | ||
---|---|---|
37 | 37 |
{ |
38 | 38 |
return $this->findAll()->where(self::COLUMN_BOOK_ABREV . ' LIKE', '%' . $bookName . '%'); |
39 | 39 |
} |
40 |
|
|
41 |
/** |
|
42 |
* Vrátí všechny abbrev |
|
43 |
* |
|
44 |
* @return array |
|
45 |
*/ |
|
46 |
public function getBookAbbrevForSelect(){ |
|
47 |
return $this->findAll()->fetchPairs(BookRepository::COLUMN_ID,BookRepository::COLUMN_BOOK_ABREV); |
|
48 |
} |
|
49 |
|
|
40 | 50 |
} |
app/model/repository/LitReferenceRepository.php | ||
---|---|---|
19 | 19 |
const COLUMN_NUMBER = 'number'; |
20 | 20 |
const COLUMN_PLATE = 'plate'; |
21 | 21 |
const COLUMN_TRANSLITERATION_ID = 'id_transliteration'; |
22 |
|
|
23 |
/** |
|
24 |
* Vrátí reference podle id transliterace |
|
25 |
* |
|
26 |
* @param int $transliterationId |
|
27 |
* @return \Nette\Database\Table\Selection |
|
28 |
*/ |
|
29 |
public function findByTransliterationId(int $transliterationId) |
|
30 |
{ |
|
31 |
return $this->findBy([self::COLUMN_TRANSLITERATION_ID => $transliterationId]); |
|
32 |
} |
|
33 |
|
|
22 | 34 |
} |
app/model/repository/MuseumRepository.php | ||
---|---|---|
39 | 39 |
{ |
40 | 40 |
return $this->findAll()->where(self::COLUMN_NAME . ' LIKE', '%' . $name . '%'); |
41 | 41 |
} |
42 |
|
|
43 |
/** |
|
44 |
* Vrátí názvy muzeí |
|
45 |
* |
|
46 |
* @return array |
|
47 |
*/ |
|
48 |
public function getMuseumNameForSelect() |
|
49 |
{ |
|
50 |
return $this->findAll()->fetchPairs(MuseumRepository::COLUMN_ID,MuseumRepository::COLUMN_NAME); |
|
51 |
} |
|
42 | 52 |
} |
Také k dispozici: Unified diff
Re #7504 úprava informací o transliteraci