commit 1cb3c2d38ae25ca554d2a1ff115d8fe37a554960
Author: Jan Šedivý <honza.seeda@gmail.com>
Date:   Wed Apr 24 23:42:52 2019 +0200

    Re #7328 označování hledaných slov ve výsledcích

diff --git a/app/FrontModule/component/Transliteration/TransliterationSearchResultList.latte b/app/FrontModule/component/Transliteration/TransliterationSearchResultList.latte
index 64988fb..2d5f887 100644
--- a/app/FrontModule/component/Transliteration/TransliterationSearchResultList.latte
+++ b/app/FrontModule/component/Transliteration/TransliterationSearchResultList.latte
@@ -63,7 +63,7 @@
         </a>
         <div>
             <span class="linefound">{$result->line_number}.</span>
-            <span>{$result->transliteration}</span>
+            <span>{$result->transliteration|noescape}</span>
         </div>
 
     {/foreach}
diff --git a/app/FrontModule/component/Transliteration/TransliterationSearchResultList.php b/app/FrontModule/component/Transliteration/TransliterationSearchResultList.php
index 611f095..3f6c732 100644
--- a/app/FrontModule/component/Transliteration/TransliterationSearchResultList.php
+++ b/app/FrontModule/component/Transliteration/TransliterationSearchResultList.php
@@ -10,7 +10,6 @@ use App\Model\TransliterationSearchModel;
 use App\Utils\Form;
 use App\Utils\Paginator;
 use Nette\Application\UI\Control;
-use Tracy\Debugger;
 
 class TransliterationSearchResultList extends Control
 {
@@ -20,7 +19,7 @@ class TransliterationSearchResultList extends Control
     /** @var TransliterationRepository */
     private $transliterationRepository;
 
-    /** @var PaginatorControl */
+    /** @var Paginator */
     private $paginator;
 
     /**
@@ -66,14 +65,48 @@ class TransliterationSearchResultList extends Control
     {
         $this->template->setFile(__DIR__ . '/TransliterationSearchResultList.latte');
 
-        $this->resultRows = $this->transliterationRepository->transliterationsFulltextSearch($this->searchTerms, $this->paginator->getOffset(), $this->paginator->getPageSize());
+        $this->resultRows = $this->transliterationRepository->transliterationsFulltextSearch($this->searchTerms, $this->paginator->getOffset(), $this->paginator->getPageSize())->fetchAll();
         $this->paginator->setPageCount($this->totalCount);
+        $this->highlight();
 
         $this->template->resultRows = $this->resultRows;
         $this->template->paginator = $this->paginator;
         $this->template->render();
     }
 
+    public function highlight()
+    {
+        foreach ($this->resultRows as $resultRow)
+        {
+            $resultRow->transliteration = str_replace("<", "&lt;", $resultRow->transliteration);
+            $resultRow->transliteration = str_replace(">", "&gt;", $resultRow->transliteration);
+
+            $resultRow->transliteration = preg_replace(
+                "/" . $this->transliterationRepository->prepareSearchRegExp($this->searchTerms['word1']) . "/",
+                "<span class='found'>$0</span>",
+                $resultRow->transliteration);
+
+            //TODO: dořešit označování slov, když se zadají slova co se překrývají tak se tagy mezi sebou ruší,
+            // viz např. vyhledávání slov 'šu' a 'as'
+
+//            if($this->searchTerms['word2_condition'] === ESearchFormOperators::AND || $this->searchTerms['word2_condition'] === ESearchFormOperators::OR )
+//            {
+//                $resultRow->transliteration = preg_replace(
+//                    "/" . $this->transliterationRepository->prepareSearchRegExp($this->searchTerms['word2']) . "/",
+//                    "<span class='found'>$0</span>",
+//                    $resultRow->transliteration);
+//            }
+//
+//            if($this->searchTerms['word3_condition'] === ESearchFormOperators::AND || $this->searchTerms['word3_condition'] === ESearchFormOperators::OR )
+//            {
+//                $resultRow->transliteration = preg_replace(
+//                    "/" . $this->transliterationRepository->prepareSearchRegExp($this->searchTerms['word3']) . "/",
+//                    "<span class='found'>$0</span>",
+//                    $resultRow->transliteration);
+//            }
+        }
+    }
+
     public function handleChangePage($page, $limit)
     {
         $this->paginator = new Paginator($page, $limit);
diff --git a/app/model/repository/TransliterationRepository.php b/app/model/repository/TransliterationRepository.php
index a030788..9d3e188 100644
--- a/app/model/repository/TransliterationRepository.php
+++ b/app/model/repository/TransliterationRepository.php
@@ -150,7 +150,7 @@ class TransliterationRepository extends Repository
      * @param $word string hledané slovo
      * @return string Regexp
      */
-    private function prepareSearchRegExp(string $word)
+    public function prepareSearchRegExp(string $word)
     {
         $splitWord = preg_split('//u',$word, -1, PREG_SPLIT_NO_EMPTY);
         foreach ($splitWord as &$char)
