5 |
5 |
|
6 |
6 |
use App\Enum\EAdjacentLines;
|
7 |
7 |
use App\Enum\EPageLimit;
|
|
8 |
use App\Enum\ESearchFormOperators;
|
|
9 |
use App\Model\Repository\LineRepository;
|
8 |
10 |
use App\Model\Repository\TransliterationRepository;
|
9 |
11 |
use App\Model\TransliterationSearchModel;
|
10 |
12 |
use App\Utils\Form;
|
... | ... | |
19 |
21 |
/** @var TransliterationRepository */
|
20 |
22 |
private $transliterationRepository;
|
21 |
23 |
|
|
24 |
/** @var LineRepository */
|
|
25 |
private $lineRepository;
|
|
26 |
|
22 |
27 |
/** @var Paginator */
|
23 |
28 |
private $paginator;
|
24 |
29 |
|
... | ... | |
31 |
36 |
private $resultRows;
|
32 |
37 |
private $totalCount;
|
33 |
38 |
|
34 |
|
private $adjacentLines;
|
|
39 |
/**
|
|
40 |
* @persistent
|
|
41 |
*/
|
|
42 |
public $adjacentLines;
|
|
43 |
|
|
44 |
/**
|
|
45 |
* @persistent
|
|
46 |
*/
|
|
47 |
public $page;
|
|
48 |
|
|
49 |
/**
|
|
50 |
* @persistent
|
|
51 |
*/
|
|
52 |
public $limit;
|
35 |
53 |
|
36 |
54 |
/**
|
37 |
55 |
* TransliterationSearchResultList constructor.
|
38 |
56 |
* @param TransliterationSearchModel $transliterationSearchModel
|
39 |
57 |
* @param TransliterationRepository $transliterationRepository
|
|
58 |
* @param LineRepository $lineRepository
|
40 |
59 |
* @throws \Nette\Application\AbortException
|
41 |
60 |
*/
|
42 |
|
public function __construct(TransliterationSearchModel $transliterationSearchModel, TransliterationRepository $transliterationRepository)
|
|
61 |
public function __construct(
|
|
62 |
TransliterationSearchModel $transliterationSearchModel,
|
|
63 |
TransliterationRepository $transliterationRepository,
|
|
64 |
LineRepository $lineRepository
|
|
65 |
)
|
43 |
66 |
{
|
44 |
67 |
parent::__construct();
|
45 |
68 |
$this->transliterationSearchModel = $transliterationSearchModel;
|
46 |
69 |
$this->transliterationRepository = $transliterationRepository;
|
47 |
|
$this->paginator = new Paginator(1, 10);
|
|
70 |
$this->lineRepository = $lineRepository;
|
|
71 |
|
|
72 |
if(!$this->page)
|
|
73 |
{
|
|
74 |
$this->page = 1;
|
|
75 |
}
|
|
76 |
|
|
77 |
if(!$this->limit)
|
|
78 |
{
|
|
79 |
$this->limit = EPageLimit::$defaultLimit;
|
|
80 |
}
|
|
81 |
$this->paginator = new Paginator($this->page, $this->limit);
|
48 |
82 |
|
49 |
83 |
$this->searchTerms = $this->transliterationSearchModel->getSearchTerms();
|
50 |
84 |
$this->totalCount = $this->transliterationRepository->getTransliterationsFulltextSearchTotalCount($this->searchTerms);
|
... | ... | |
67 |
101 |
|
68 |
102 |
$this->resultRows = $this->transliterationRepository->transliterationsFulltextSearch($this->searchTerms, $this->paginator->getOffset(), $this->paginator->getPageSize())->fetchAll();
|
69 |
103 |
$this->paginator->setPageCount($this->totalCount);
|
|
104 |
|
70 |
105 |
$this->highlight();
|
|
106 |
if(in_array($this->adjacentLines, EAdjacentLines::$lines) && $this->adjacentLines > 0)
|
|
107 |
{
|
|
108 |
foreach ($this->resultRows as &$row)
|
|
109 |
{
|
|
110 |
$row['adjacentLines'] = $this->lineRepository->getAdjacentLines($row['line_id'], $row['surface_id'], $this->adjacentLines);
|
|
111 |
}
|
|
112 |
}
|
71 |
113 |
|
72 |
114 |
$this->template->resultRows = $this->resultRows;
|
73 |
115 |
$this->template->paginator = $this->paginator;
|
... | ... | |
78 |
120 |
{
|
79 |
121 |
foreach ($this->resultRows as $resultRow)
|
80 |
122 |
{
|
81 |
|
$resultRow->transliteration = str_replace("<", "<", $resultRow->transliteration);
|
82 |
|
$resultRow->transliteration = str_replace(">", ">", $resultRow->transliteration);
|
|
123 |
//nejprve escape html znaků, které chceme nechat zobrazovat,
|
|
124 |
//jelikož následně přidáváme html tagy pro vyznačení a výstup v latte nemůže být escapovaný
|
|
125 |
$resultRow->transliteration = htmlspecialchars($resultRow->transliteration);
|
83 |
126 |
|
84 |
127 |
$resultRow->transliteration = preg_replace(
|
85 |
128 |
"/" . $this->transliterationRepository->prepareSearchRegExp($this->searchTerms['word1']) . "/",
|
86 |
129 |
"<span class='found'>$0</span>",
|
87 |
130 |
$resultRow->transliteration);
|
88 |
131 |
|
89 |
|
//TODO: dořešit označování slov, když se zadají slova co se překrývají tak se tagy mezi sebou ruší,
|
90 |
|
// viz např. vyhledávání slov 'šu' a 'as'
|
91 |
|
|
92 |
|
// if($this->searchTerms['word2_condition'] === ESearchFormOperators::AND || $this->searchTerms['word2_condition'] === ESearchFormOperators::OR )
|
93 |
|
// {
|
94 |
|
// $resultRow->transliteration = preg_replace(
|
95 |
|
// "/" . $this->transliterationRepository->prepareSearchRegExp($this->searchTerms['word2']) . "/",
|
96 |
|
// "<span class='found'>$0</span>",
|
97 |
|
// $resultRow->transliteration);
|
98 |
|
// }
|
99 |
|
//
|
100 |
|
// if($this->searchTerms['word3_condition'] === ESearchFormOperators::AND || $this->searchTerms['word3_condition'] === ESearchFormOperators::OR )
|
101 |
|
// {
|
102 |
|
// $resultRow->transliteration = preg_replace(
|
103 |
|
// "/" . $this->transliterationRepository->prepareSearchRegExp($this->searchTerms['word3']) . "/",
|
104 |
|
// "<span class='found'>$0</span>",
|
105 |
|
// $resultRow->transliteration);
|
106 |
|
// }
|
|
132 |
/**
|
|
133 |
* TODO: dořešit označování slov, když se zadají slova co se překrývají tak se tagy mezi sebou ruší,
|
|
134 |
* viz např. vyhledávání slov 'šu' a 'as'
|
|
135 |
*/
|
|
136 |
if($this->searchTerms['word2_condition'] === ESearchFormOperators::AND || $this->searchTerms['word2_condition'] === ESearchFormOperators::OR )
|
|
137 |
{
|
|
138 |
$resultRow->transliteration = preg_replace(
|
|
139 |
"/" . $this->transliterationRepository->prepareSearchRegExp($this->searchTerms['word2']) . "/",
|
|
140 |
"<span class='found'>$0</span>",
|
|
141 |
$resultRow->transliteration);
|
|
142 |
}
|
|
143 |
|
|
144 |
if($this->searchTerms['word3_condition'] === ESearchFormOperators::AND || $this->searchTerms['word3_condition'] === ESearchFormOperators::OR )
|
|
145 |
{
|
|
146 |
$resultRow->transliteration = preg_replace(
|
|
147 |
"/" . $this->transliterationRepository->prepareSearchRegExp($this->searchTerms['word3']) . "/",
|
|
148 |
"<span class='found'>$0</span>",
|
|
149 |
$resultRow->transliteration);
|
|
150 |
}
|
107 |
151 |
}
|
108 |
152 |
}
|
109 |
153 |
|
110 |
154 |
public function handleChangePage($page, $limit)
|
111 |
155 |
{
|
|
156 |
$this->page = $page;
|
|
157 |
$this->limit = $limit;
|
112 |
158 |
$this->paginator = new Paginator($page, $limit);
|
113 |
159 |
$this->redrawControl('resultList');
|
114 |
160 |
}
|
... | ... | |
149 |
195 |
if($lines !== null)
|
150 |
196 |
{
|
151 |
197 |
$this->adjacentLines = $lines;
|
|
198 |
$this->paginator = new Paginator($this->page, $this->limit);
|
|
199 |
|
152 |
200 |
$this['searchSettingsForm']->setDefaults(array('lines' => $lines));
|
153 |
201 |
$this->redrawControl('resultList');
|
154 |
202 |
|
Re #7328 Zobrazování okolních řádek ve výsledcích vyhledávání