commit 77657d08d93d3aa4e5c418c1ee6636956a39cdd9
Author: Jan Šedivý <honza.seeda@gmail.com>
Date:   Tue Apr 23 19:32:44 2019 +0200

    Re #7328 výsledky vyhledávání textů s pokročilými filtry

diff --git a/app/FrontModule/component/Transliteration/TransliterationSearchForm.php b/app/FrontModule/component/Transliteration/TransliterationSearchForm.php
index 7bb3a87..2aacd31 100644
--- a/app/FrontModule/component/Transliteration/TransliterationSearchForm.php
+++ b/app/FrontModule/component/Transliteration/TransliterationSearchForm.php
@@ -24,6 +24,8 @@ class TransliterationSearchForm extends Control
     /**
      * TransliterationSearchForm constructor.
      * @param TransliterationSearchModel $transliterationSearchModel
+     * @param BookTypeRepository $bookTypeRepository
+     * @param OriginRepository $originRepository
      */
     public function __construct(
         TransliterationSearchModel $transliterationSearchModel,
@@ -67,12 +69,10 @@ class TransliterationSearchForm extends Control
         $form->addSelect('type_condition', '', ESearchFormOperators::$selectEqualsOperatorLabels)
             ->setDefaultValue(ESearchFormOperators::IS);
         $form->addSelect('type', 'Type', $this->bookTypeRepository->getTypesForSelect());
-//            ->setDefaultValue(ESearchFormOperators::IS);
         $form->addSelect('origin_condition', '', ESearchFormOperators::$selectEqualsOperatorLabels)
             ->setDefaultValue(ESearchFormOperators::IS);
         $form->addSelect('origin', 'Origin', $this->originRepository->getOriginsForSelect());
 
-
         $form->addSelect('registration_condition', '', ESearchFormOperators::$selectLikeOperatorLabels)
             ->setDefaultValue(ESearchFormOperators::CONTAINS);
         $form->addText('registration', 'Registration / Ex. number');
diff --git a/app/model/repository/TransliterationRepository.php b/app/model/repository/TransliterationRepository.php
index 72e1e66..47ebeff 100644
--- a/app/model/repository/TransliterationRepository.php
+++ b/app/model/repository/TransliterationRepository.php
@@ -78,6 +78,42 @@ class TransliterationRepository extends Repository
             }
         }
 
+        if($queryParams['book'])
+        {
+            $where .= ' AND b.book_name' . ESearchFormOperators::$selectLikeOperatorQueryCondition[$queryParams['book_condition']];
+            $whereArgs[] = $this->prepareQueryArgByOperator($queryParams['book'], $queryParams['book_condition']);
+        }
+
+        if($queryParams['museum'])
+        {
+            $where .= ' AND t.museum_no' . ESearchFormOperators::$selectLikeOperatorQueryCondition[$queryParams['museum_condition']];
+            $whereArgs[] = $this->prepareQueryArgByOperator($queryParams['museum'], $queryParams['museum_condition']);
+        }
+
+        if($queryParams['type'])
+        {
+            $where .= ' AND t.id_book_type' . ESearchFormOperators::$selectEqualsOperatorQueryCondition[$queryParams['type_condition']];
+            $whereArgs[] = $queryParams['type'];
+        }
+
+        if($queryParams['origin'])
+        {
+            $where .= ' AND t.id_origin' . ESearchFormOperators::$selectEqualsOperatorQueryCondition[$queryParams['origin_condition']];
+            $whereArgs[] = $queryParams['origin'];
+        }
+
+        if($queryParams['registration'])
+        {
+            $where .= ' AND t.reg_no' . ESearchFormOperators::$selectLikeOperatorQueryCondition[$queryParams['registration_condition']];
+            $whereArgs[] = $this->prepareQueryArgByOperator($queryParams['registration'], $queryParams['registration_condition']);
+        }
+
+        if($queryParams['date'])
+        {
+            $where .= ' AND t.date' . ESearchFormOperators::$selectLikeOperatorQueryCondition[$queryParams['date_condition']];
+            $whereArgs[] = $this->prepareQueryArgByOperator($queryParams['date'], $queryParams['date_condition']);
+        }
+
         $query = "SELECT 
                     t.id_transliteration as id, 
                     b.book_abrev, 
@@ -87,7 +123,7 @@ class TransliterationRepository extends Repository
                   FROM transliteration t
                   LEFT JOIN surface s ON s.id_transliteration = t.id_transliteration
                   LEFT JOIN line l ON l.id_surface = s.id_surface
-                  LEFT JOIN book b on t.id_book = b.id_book
+                  LEFT JOIN book b ON t.id_book = b.id_book
                   WHERE " . $where;
 
         return $this->context->queryArgs($query, $whereArgs);
@@ -109,6 +145,27 @@ class TransliterationRepository extends Repository
         return $regex;
     }
 
+    /**
+     * Připraví argument pro dotaz podle zvoleného operátoru
+     * @param $word string
+     * @param $op string operátor pro porovnání s ESearchFormOperators
+     * @return string
+     */
+    private function prepareQueryArgByOperator($word, $op)
+    {
+        switch ($op)
+        {
+            case ESearchFormOperators::CONTAINS:
+                return '%' . $word . '%';
+            case ESearchFormOperators::BEGINS_WITH:
+                return $word . '%';
+            case ESearchFormOperators::ENDS_WITH:
+                return '%' . $word;
+            default:
+                return $word;
+        }
+    }
+
     /**
      * @param int $id id transliterace
      * @return bool|\Nette\Database\IRow|\Nette\Database\Row
