commit 29295606d3fc77f4f1fe729593662e568b1df298
Author: Filip Jani <jsem@filek.cz>
Date:   Sat Jun 8 15:11:09 2019 +0200

    Re #7507 úprava ukládání nových transliterací

diff --git a/app/AdminModule/component/Transliteration/TransliterationNewForm.php b/app/AdminModule/component/Transliteration/TransliterationNewForm.php
index fba1cba..bb49d7e 100644
--- a/app/AdminModule/component/Transliteration/TransliterationNewForm.php
+++ b/app/AdminModule/component/Transliteration/TransliterationNewForm.php
@@ -27,6 +27,9 @@ class TransliterationNewForm extends Control
     const BOOK_EXISTING_ID = 'book-existing';
     const BOOK_NEW_ID = 'book-new';
 
+    const BOOK_EXISTING = 0;
+    const BOOK_NEW = 1;
+
     /**
      * @var Form
      */
@@ -137,23 +140,22 @@ class TransliterationNewForm extends Control
 
         $bookContainer = $this->form->addContainer('bookContainer');
 
-        $bookContainer->addRadioList('book', 'Book option', [0 => 'Existing book', 1 => 'New book'])
-            ->setDefaultValue(0)
-            ->addCondition(Form::EQUAL, 0)
+        $bookContainer->addRadioList('book', 'Book option', [self::BOOK_EXISTING => 'Existing book', self::BOOK_NEW => 'New book'])
+            ->setDefaultValue(self::BOOK_EXISTING)
+            ->addCondition(Form::EQUAL, self::BOOK_EXISTING)
                 ->toggle(self::BOOK_EXISTING_ID)
             ->elseCondition()
                 ->toggle(self::BOOK_NEW_ID)
             ->endCondition();
 
-        $bookContainer->addSelect(TransliterationRepository::COLUMN_BOOK_ID, 'Book', $this->bookRepository->getBookAbbrevForSelect())
-            ->setOption('id', TransliterationRepository::COLUMN_BOOK_ID);
+        $bookContainer->addSelect(TransliterationRepository::COLUMN_BOOK_ID, 'Book', $this->bookRepository->getBookAbbrevForSelect());
 
         $bookContainer->addText(BookRepository::COLUMN_BOOK_ABREV, 'Abbreviation')
-            ->addConditionOn($this->form['bookContainer']['book'], Form::EQUAL, 1)
+            ->addConditionOn($this->form['bookContainer']['book'], Form::EQUAL, self::BOOK_NEW)
             ->addRule(Form::REQUIRED, 'Field %label is required', TRUE);
         $bookContainer->addText(BookRepository::COLUMN_BOOK_AUTHOR, 'Author');
         $bookContainer->addText(BookRepository::COLUMN_BOOK_NAME, 'Name')
-            ->addConditionOn($this->form['bookContainer']['book'], Form::EQUAL, 1)
+            ->addConditionOn($this->form['bookContainer']['book'], Form::EQUAL, self::BOOK_NEW)
             ->addRule(Form::REQUIRED, 'Field %label is required', TRUE);
         $bookContainer->addText(BookRepository::COLUMN_BOOK_SUBTITLE, 'Alternate name');
         $bookContainer->addTextArea(BookRepository::COLUMN_BOOK_DESCRIPTION, 'Description');
diff --git a/app/model/facade/BookFacade.php b/app/model/facade/BookFacade.php
index ffa5ca5..a14029a 100644
--- a/app/model/facade/BookFacade.php
+++ b/app/model/facade/BookFacade.php
@@ -31,13 +31,18 @@ class BookFacade
      * @param int|null $id
      * @return \Nette\Database\Table\ActiveRow
      */
-    public function saveBook(Form $form, int $id = null)
+    public function saveBook(Form $form, int $id = NULL)
     {
         $formValues = $form->getValues();
         $formValues = isset($formValues['bookContainer']) ? $formValues['bookContainer'] : $formValues;
 
         unset($formValues['book']);
 
+        if ($id === NULL && isset($formValues['id_book']))
+        {
+            unset($formValues['id_book']);
+        }
+
         return $this->bookRepository->save($formValues, $id);
     }
 
diff --git a/app/model/facade/TransliterationFacade.php b/app/model/facade/TransliterationFacade.php
index f50548c..b5b39dd 100644
--- a/app/model/facade/TransliterationFacade.php
+++ b/app/model/facade/TransliterationFacade.php
@@ -4,6 +4,7 @@
 namespace App\Model\Facade;
 
 
+use App\AdminModule\Components\TransliterationNewForm;
 use App\Enum\EFlashMessage;
 use App\Model\Repository\BookRepository;
 use App\Model\Repository\LineRepository;
@@ -84,7 +85,7 @@ class TransliterationFacade
         $data = $form->getValues();
         $transliteration = $this->saveTransliterationInfo($form);
 
-        if ($data['bookContainer']['book'] == 0)
+        if ($data['bookContainer']['book'] == TransliterationNewForm::BOOK_EXISTING)
         {
             $bookId = $data['bookContainer'][BookRepository::COLUMN_ID];
         } else
