Revize b8fae4af
Přidáno uživatelem Filip Jani před téměř 6 roky(ů)
app/model/facade/TransliterationFacade.php | ||
---|---|---|
5 | 5 |
|
6 | 6 |
|
7 | 7 |
use App\Enum\EFlashMessage; |
8 |
use App\Model\Repository\BookRepository; |
|
8 | 9 |
use App\Model\Repository\LineRepository; |
9 | 10 |
use App\Model\Repository\LitReferenceRepository; |
10 | 11 |
use App\Model\Repository\ObjectTypeRepository; |
... | ... | |
47 | 48 |
* @var LitReferenceRepository |
48 | 49 |
*/ |
49 | 50 |
private $litReferenceRepository; |
51 |
/** |
|
52 |
* @var BookFacade |
|
53 |
*/ |
|
54 |
private $bookFacade; |
|
50 | 55 |
|
51 | 56 |
public function __construct(SurfaceRepository $surfaceRepository, |
52 | 57 |
LineRepository $lineRepository, |
... | ... | |
54 | 59 |
SurfaceTypeRepository $surfaceTypeRepository, |
55 | 60 |
TransliterationRepository $transliterationRepository, |
56 | 61 |
LitReferenceRepository $litReferenceRepository, |
57 |
Context $context |
|
62 |
Context $context, |
|
63 |
BookFacade $bookFacade |
|
58 | 64 |
) |
59 | 65 |
{ |
60 | 66 |
$this->surfaceRepository = $surfaceRepository; |
... | ... | |
64 | 70 |
$this->context = $context; |
65 | 71 |
$this->transliterationRepository = $transliterationRepository; |
66 | 72 |
$this->litReferenceRepository = $litReferenceRepository; |
73 |
$this->bookFacade = $bookFacade; |
|
67 | 74 |
} |
68 | 75 |
|
69 |
public function saveTransliterationInfo($id, Form $form) |
|
76 |
/** |
|
77 |
* Vložení nové transliterace do databáze |
|
78 |
* |
|
79 |
* @param \App\Utils\Form $form |
|
80 |
* @return bool|void |
|
81 |
*/ |
|
82 |
public function saveNewTransliteration(\App\Utils\Form $form) |
|
70 | 83 |
{ |
84 |
$data = $form->getValues(); |
|
85 |
$transliteration = $this->saveTransliterationInfo($form); |
|
71 | 86 |
|
72 |
$formValues = $form->getValues(); |
|
73 |
|
|
74 |
$formValues = isset($formValues['infoContainer']) ? $formValues['infoContainer'] : $formValues; |
|
87 |
if ($data['bookContainer']['book'] == 0) |
|
88 |
{ |
|
89 |
$bookId = $data['bookContainer'][BookRepository::COLUMN_ID]; |
|
90 |
} else |
|
91 |
{ |
|
92 |
$book = $this->bookFacade->saveBook($form); |
|
93 |
$bookId = $book[BookRepository::COLUMN_ID]; |
|
94 |
} |
|
75 | 95 |
|
76 |
$references = $formValues['references'];
|
|
96 |
$transliteration->update([TransliterationRepository::COLUMN_BOOK_ID => $bookId]);
|
|
77 | 97 |
|
78 |
if ($this->isAnyReferenceEmpty($references))
|
|
98 |
if ($transliteration == null)
|
|
79 | 99 |
{ |
80 |
return null;
|
|
100 |
return FALSE;
|
|
81 | 101 |
} |
82 | 102 |
|
103 |
$result = $this->saveTransliterationData($transliteration[TransliterationRepository::COLUMN_ID], $form); |
|
104 |
return $result; |
|
105 |
} |
|
106 |
|
|
107 |
/** |
|
108 |
* Uložení informací o transliteraci do databáze |
|
109 |
* |
|
110 |
* @param Form $form |
|
111 |
* @param int|null $id |
|
112 |
* @return ActiveRow|null |
|
113 |
*/ |
|
114 |
public function saveTransliterationInfo(Form $form, int $id = null) |
|
115 |
{ |
|
116 |
$formValues = $form->getValues(); |
|
117 |
$formValues = isset($formValues['infoContainer']) ? $formValues['infoContainer'] : $formValues; |
|
118 |
|
|
119 |
$references = $formValues['references']; |
|
83 | 120 |
unset($formValues['references']); |
84 | 121 |
|
85 | 122 |
$newTransliteration = $this->transliterationRepository->save($formValues, $id); |
86 | 123 |
|
87 |
if($id != null){ |
|
124 |
if ($id != null) |
|
125 |
{ |
|
88 | 126 |
$this->deleteRemovedReferences($references, $id); |
89 |
} |
|
90 |
else{
|
|
127 |
} else
|
|
128 |
{ |
|
91 | 129 |
$id = $newTransliteration[TransliterationRepository::COLUMN_ID]; |
92 | 130 |
} |
93 | 131 |
|
... | ... | |
124 | 162 |
* |
125 | 163 |
* @param $newReferences array nových transliterací |
126 | 164 |
*/ |
127 |
public function deleteRemovedReferences($newReferences,$id) |
|
165 |
public function deleteRemovedReferences($newReferences, $id)
|
|
128 | 166 |
{ |
129 | 167 |
$references = $this->litReferenceRepository->findByTransliterationId($id); |
130 | 168 |
|
... | ... | |
162 | 200 |
* |
163 | 201 |
* @param int|null $id : ID transliterace |
164 | 202 |
* @param Form $form |
165 |
* @return bool
|
|
203 |
* @return int $id : Vrací ID transliterace
|
|
166 | 204 |
*/ |
167 |
public function saveTransliterationData(int $id, Form $form): bool
|
|
205 |
public function saveTransliterationData(int $id, Form $form): int
|
|
168 | 206 |
{ |
169 | 207 |
$formValues = $form->getValues(); |
170 |
|
|
171 | 208 |
$formValues = isset($formValues['dataContainer']) ? $formValues['dataContainer'] : $formValues; |
172 | 209 |
|
173 | 210 |
$this->removeDeletedLines($id, $formValues); |
... | ... | |
209 | 246 |
} catch (\Exception $exception) |
210 | 247 |
{ |
211 | 248 |
\Tracy\Debugger::log('Nepodařilo se uložit data transliterace. Chyba: ' . $exception->getMessage(), 'transliteration-facade'); |
212 |
return FALSE;
|
|
249 |
return 0;
|
|
213 | 250 |
} |
214 | 251 |
} |
215 | 252 |
} |
216 | 253 |
} |
217 | 254 |
|
218 |
return TRUE;
|
|
255 |
return $id;
|
|
219 | 256 |
} |
220 | 257 |
|
221 | 258 |
/** |
... | ... | |
305 | 342 |
|
306 | 343 |
return $deletedIds; |
307 | 344 |
} |
308 |
/** |
|
309 |
* Vrací název inputu pro formulář |
|
310 |
* |
|
311 |
* @param string|NULL $name |
|
312 |
* @return string |
|
313 |
*/ |
|
314 |
public function getInputName(string $name): string |
|
315 |
{ |
|
316 |
return str_replace(' ', '', $name); |
|
317 |
} |
|
318 | 345 |
} |
Také k dispozici: Unified diff
Re #7507 přidávání nových textů