Revize 5dea830a
Přidáno uživatelem Jan Šedivý před téměř 6 roky(ů)
app/FrontModule/component/Transliteration/TransliterationSearchResultList.latte | ||
---|---|---|
1 |
{snippet resultList} |
|
2 |
<div class="row h-100 pagination-header"> |
|
3 |
<div class="col my-auto"> |
|
4 |
{if $paginator->getPageCount() > 1} |
|
5 |
<nav aria-label="Page navigation example"> |
|
6 |
<ul class="pagination"> |
|
7 |
<li class="page-item"> |
|
8 |
<a class="page-link" href="{link changePage!, $paginator->first()->getPageNumber(), $paginator->first()->getPageSize()}"> |
|
9 |
<span aria-hidden="true">«</span> |
|
10 |
<span class="sr-only">First</span> |
|
11 |
</a> |
|
12 |
</li> |
|
13 |
<li class="page-item"> |
|
14 |
<a class="page-link" href="{link changePage!, $paginator->previous()->getPageNumber(), $paginator->previous()->getPageSize()}"> |
|
15 |
<span aria-hidden="true">‹</span> |
|
16 |
<span class="sr-only">Previous</span> |
|
17 |
</a> |
|
18 |
</li> |
|
19 |
{for $i = $paginator->getStartingPage(); $i <= $paginator->getEndingPage(); $i++} |
|
20 |
<li class="page-item{if $paginator->getPageNumber() == $i} active{/if}"> |
|
21 |
<a class="page-link" href="{link changePage!, $i, $paginator->getPageSize()}"> |
|
22 |
{$i} |
|
23 |
</a> |
|
24 |
</li> |
|
25 |
{/for} |
|
26 |
<li class="page-item"> |
|
27 |
<a class="page-link" href="{link changePage!, $paginator->next()->getPageNumber(), $paginator->next()->getPageSize()}"> |
|
28 |
<span aria-hidden="true">›</span> |
|
29 |
<span class="sr-only">Next</span> |
|
30 |
</a> |
|
31 |
</li> |
|
32 |
<li class="page-item"> |
|
33 |
<a class="page-link" href="{link changePage!, $paginator->last()->getPageNumber(), $paginator->last()->getPageSize()}"> |
|
34 |
<span aria-hidden="true">»</span> |
|
35 |
<span class="sr-only">Last</span> |
|
36 |
</a> |
|
37 |
</li> |
|
38 |
</ul> |
|
39 |
</nav> |
|
40 |
{/if} |
|
41 |
</div> |
|
42 |
<div class="col text-right my-auto"> |
|
43 |
<span class="text-muted align-middle"> |
|
44 |
Results found: {$paginator->getItemCount()} ({$paginator->getPageSize()} per page). |
|
45 |
</span> |
|
46 |
</div> |
|
47 |
</div> |
|
48 |
|
|
49 |
{foreach $resultRows as $result} |
|
50 |
<hr> |
|
51 |
|
|
52 |
<a href="{plink Transliteration:view $result->id}"> |
|
53 |
{$result->book_abrev}, {$result->chapter} |
|
54 |
</a> |
|
55 |
<div> |
|
56 |
<span class="lineno linefound">{$result->line_number}.</span> |
|
57 |
<span class="line">{$result->transliteration}</span> |
|
58 |
</div> |
|
59 |
|
|
60 |
{/foreach} |
|
61 |
{/snippet} |
app/FrontModule/component/Transliteration/TransliterationSearchResultList.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
namespace App\FrontModule\Components; |
|
4 |
|
|
5 |
|
|
6 |
use App\Model\Repository\TransliterationRepository; |
|
7 |
use App\Model\TransliterationSearchModel; |
|
8 |
use App\Utils\Paginator; |
|
9 |
use Nette\Application\UI\Control; |
|
10 |
use Tracy\Debugger; |
|
11 |
|
|
12 |
class TransliterationSearchResultList extends Control |
|
13 |
{ |
|
14 |
/** @var TransliterationSearchModel */ |
|
15 |
private $transliterationSearchModel; |
|
16 |
|
|
17 |
/** @var TransliterationRepository */ |
|
18 |
private $transliterationRepository; |
|
19 |
|
|
20 |
/** @var PaginatorControl */ |
|
21 |
private $paginator; |
|
22 |
|
|
23 |
private $searchTerms; |
|
24 |
private $resultRows; |
|
25 |
private $totalCount; |
|
26 |
|
|
27 |
/** |
|
28 |
* TransliterationSearchResultList constructor. |
|
29 |
* @param TransliterationSearchModel $transliterationSearchModel |
|
30 |
* @param TransliterationRepository $transliterationRepository |
|
31 |
* @throws \Nette\Application\AbortException |
|
32 |
*/ |
|
33 |
public function __construct(TransliterationSearchModel $transliterationSearchModel, TransliterationRepository $transliterationRepository) |
|
34 |
{ |
|
35 |
parent::__construct(); |
|
36 |
$this->transliterationSearchModel = $transliterationSearchModel; |
|
37 |
$this->transliterationRepository = $transliterationRepository; |
|
38 |
$this->paginator = new Paginator(1, 10); |
|
39 |
|
|
40 |
$this->searchTerms = $this->transliterationSearchModel->getSearchTerms(); |
|
41 |
$this->totalCount = $this->transliterationRepository->getTransliterationsFulltextSearchTotalCount($this->searchTerms); |
|
42 |
|
|
43 |
if (!$this->searchTerms) |
|
44 |
{ |
|
45 |
$this->presenter->redirect('Transliteration:search'); |
|
46 |
} |
|
47 |
|
|
48 |
if(!$this->searchTerms['word1']) |
|
49 |
{ |
|
50 |
$this->presenter->redirect('Transliteration:search'); |
|
51 |
} |
|
52 |
} |
|
53 |
|
|
54 |
|
|
55 |
public function render() |
|
56 |
{ |
|
57 |
$this->template->setFile(__DIR__ . '/TransliterationSearchResultList.latte'); |
|
58 |
|
|
59 |
$this->resultRows = $this->transliterationRepository->transliterationsFulltextSearch($this->searchTerms, $this->paginator->getOffset(), $this->paginator->getPageSize()); |
|
60 |
$this->paginator->setPageCount($this->totalCount); |
|
61 |
|
|
62 |
Debugger::barDump($this->paginator->getOffset(), 'offset'); |
|
63 |
Debugger::barDump($this->paginator->getPageSize(), 'limit'); |
|
64 |
$this->template->resultRows = $this->resultRows; |
|
65 |
$this->template->paginator = $this->paginator; |
|
66 |
$this->template->render(); |
|
67 |
} |
|
68 |
|
|
69 |
public function handleChangePage($page, $limit) |
|
70 |
{ |
|
71 |
$this->paginator = new Paginator($page, $limit); |
|
72 |
$this->redrawControl('resultList'); |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
interface ITransliterationSearchResultListFactory |
|
77 |
{ |
|
78 |
/** |
|
79 |
* @return TransliterationSearchResultList |
|
80 |
*/ |
|
81 |
public function create(); |
|
82 |
} |
app/FrontModule/presenters/TransliterationPresenter.php | ||
---|---|---|
5 | 5 |
|
6 | 6 |
|
7 | 7 |
use App\FrontModule\Components\ITransliterationSearchFormFactory; |
8 |
use App\FrontModule\Components\ITransliterationSearchResultListFactory; |
|
8 | 9 |
use App\Model\Repository\LineRepository; |
9 | 10 |
use App\Model\Repository\LitReferenceRepository; |
10 | 11 |
use App\Model\Repository\RevHistoryRepository; |
... | ... | |
32 | 33 |
/** @var LineRepository */ |
33 | 34 |
private $lineRepository; |
34 | 35 |
|
36 |
/** @var ITransliterationSearchResultListFactory */ |
|
37 |
private $transliterationSearchResultListFactory; |
|
38 |
|
|
35 | 39 |
public function __construct( |
36 | 40 |
ITransliterationSearchFormFactory $transliterationSearchFormFactory, |
37 | 41 |
TransliterationRepository $transliterationRepository, |
38 | 42 |
TransliterationSearchModel $transliterationSearchModel, |
39 | 43 |
LitReferenceRepository $litReferenceRepository, |
40 | 44 |
RevHistoryRepository $revHistoryRepository, |
41 |
LineRepository $lineRepository |
|
45 |
LineRepository $lineRepository, |
|
46 |
ITransliterationSearchResultListFactory $transliterationSearchResultListFactory |
|
42 | 47 |
) |
43 | 48 |
{ |
44 | 49 |
parent::__construct(); |
... | ... | |
49 | 54 |
$this->litReferenceRepository = $litReferenceRepository; |
50 | 55 |
$this->revHistoryRepository = $revHistoryRepository; |
51 | 56 |
$this->lineRepository = $lineRepository; |
57 |
$this->transliterationSearchResultListFactory = $transliterationSearchResultListFactory; |
|
52 | 58 |
} |
53 | 59 |
|
54 | 60 |
|
... | ... | |
59 | 65 |
|
60 | 66 |
public function actionSearchResult() |
61 | 67 |
{ |
62 |
$searchTerms = $this->transliterationSearchModel->getSearchTerms(); |
|
63 | 68 |
|
64 |
if (!$searchTerms) |
|
65 |
{ |
|
66 |
$this->redirect('Transliteration:search'); |
|
67 |
} |
|
68 |
|
|
69 |
if(!$searchTerms['word1']) |
|
70 |
{ |
|
71 |
$this->redirect('Transliteration:search'); |
|
72 |
} |
|
73 |
|
|
74 |
$resultRows = $this->transliterationRepository->transliterationsFulltextSearch($searchTerms); |
|
75 |
|
|
76 |
$this->template->resultRows = $resultRows; |
|
77 | 69 |
} |
78 | 70 |
|
79 | 71 |
public function actionView($id) |
... | ... | |
101 | 93 |
{ |
102 | 94 |
return $this->transliterationSearchFormFactory->create(); |
103 | 95 |
} |
96 |
|
|
97 |
public function createComponentTransliterationSearchResultList() |
|
98 |
{ |
|
99 |
return $this->transliterationSearchResultListFactory->create(); |
|
100 |
} |
|
104 | 101 |
} |
app/FrontModule/templates/Transliteration/searchResult.latte | ||
---|---|---|
1 | 1 |
{block content} |
2 | 2 |
<div class="display-5">Search in texts - Results</div> |
3 | 3 |
|
4 |
<div class="row h-100 pagination-header"> |
|
5 |
<div class="col my-auto"> |
|
6 |
<nav aria-label="Page navigation example"> |
|
7 |
<ul class="pagination"> |
|
8 |
<li class="page-item"><a class="page-link" href="#"><span aria-hidden="true">«</span> |
|
9 |
<span class="sr-only">Previous</span></a></li> |
|
10 |
<li class="page-item"><a class="page-link" href="#"><span aria-hidden="true">‹</span> |
|
11 |
<span class="sr-only">Previous</span></a></li> |
|
12 |
<li class="page-item active"><a class="page-link" href="#">1</a></li> |
|
13 |
<li class="page-item"><a class="page-link" href="#">2</a></li> |
|
14 |
<li class="page-item"><a class="page-link" href="#">3</a></li> |
|
15 |
<li class="page-item"><a class="page-link" href="#">4</a></li> |
|
16 |
<li class="page-item"><a class="page-link" href="#">5</a></li> |
|
17 |
<li class="page-item"><a class="page-link" href="#"><span aria-hidden="true">›</span> |
|
18 |
<span class="sr-only">Next</span></a></li> |
|
19 |
<li class="page-item"><a class="page-link" href="#"><span aria-hidden="true">»</span> |
|
20 |
<span class="sr-only">Next</span></a></li> |
|
21 |
</ul> |
|
22 |
</nav> |
|
23 |
</div> |
|
24 |
<div class="col text-right my-auto"> |
|
25 |
<span class="text-muted align-middle"> |
|
26 |
Total count: 23655. Showing page 1 of 4731 (5 results per site). |
|
27 |
</span> |
|
28 |
</div> |
|
29 |
</div> |
|
30 |
|
|
31 |
{foreach $resultRows as $result} |
|
32 |
<hr> |
|
33 |
|
|
34 |
<a n:href="Transliteration:view $result->id"> |
|
35 |
{$result->book_abrev}, {$result->chapter} |
|
36 |
</a> |
|
37 |
<div> |
|
38 |
<span class="lineno linefound">{$result->line_number}.</span> |
|
39 |
<span class="line">{$result->transliteration}</span> |
|
40 |
</div> |
|
41 |
|
|
42 |
{/foreach} |
|
4 |
{control transliterationSearchResultList} |
|
43 | 5 |
{/block} |
app/config/components.neon | ||
---|---|---|
18 | 18 |
- App\AdminModule\Components\ISurfaceTypeEditFormFactory |
19 | 19 |
- App\AdminModule\Components\IMuseumEditFormFactory |
20 | 20 |
- App\AdminModule\Components\IBookTypeEditFormFactory |
21 |
- App\AdminModule\Components\IBookEditFormFactory |
|
21 |
- App\AdminModule\Components\IBookEditFormFactory |
|
22 |
|
|
23 |
- App\FrontModule\Components\ITransliterationSearchResultListFactory |
app/model/repository/TransliterationRepository.php | ||
---|---|---|
4 | 4 |
|
5 | 5 |
use App\Enum\ESearchFormOperators; |
6 | 6 |
use Nette\Utils\ArrayHash; |
7 |
use Tracy\Debugger; |
|
7 | 8 |
|
8 | 9 |
/** |
9 | 10 |
* Repository pro práci s tabulkou `transliteration` |
... | ... | |
32 | 33 |
/** |
33 | 34 |
* Vyhledává texty podle slov v řádcích textu |
34 | 35 |
* @param ArrayHash $queryParams objekt s podmínkami pro hledaný text |
36 |
* @param $offset null|int |
|
37 |
* @param $limit null|int |
|
35 | 38 |
* @return \Nette\Database\ResultSet |
36 | 39 |
*/ |
37 |
public function transliterationsFulltextSearch(ArrayHash $queryParams) |
|
40 |
public function transliterationsFulltextSearch(ArrayHash $queryParams, $offset = null, $limit = null)
|
|
38 | 41 |
{ |
39 | 42 |
$where = ''; |
40 | 43 |
$whereArgs = []; |
... | ... | |
126 | 129 |
LEFT JOIN book b ON t.id_book = b.id_book |
127 | 130 |
WHERE " . $where; |
128 | 131 |
|
132 |
if($offset != null && $limit != null) |
|
133 |
{ |
|
134 |
Debugger::barDump('tu'); |
|
135 |
$query .= ' LIMIT ?, ?'; |
|
136 |
$whereArgs[] = (int) $offset; |
|
137 |
$whereArgs[] = (int) $limit; |
|
138 |
} |
|
139 |
|
|
140 |
Debugger::barDump($offset); |
|
141 |
Debugger::barDump($limit); |
|
142 |
Debugger::barDump($query); |
|
143 |
|
|
129 | 144 |
return $this->context->queryArgs($query, $whereArgs); |
130 | 145 |
} |
131 | 146 |
|
147 |
public function getTransliterationsFulltextSearchTotalCount($queryParams) |
|
148 |
{ |
|
149 |
return $this->transliterationsFulltextSearch($queryParams, null, null)->getRowCount(); |
|
150 |
} |
|
151 |
|
|
132 | 152 |
/** |
133 | 153 |
* Vytváří regulární výraz z hledaného slova, escapuje regexp znaky |
134 | 154 |
* @param $word string hledané slovo |
app/utils/Paginator.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
namespace App\Utils; |
|
4 |
|
|
5 |
|
|
6 |
class Paginator |
|
7 |
{ |
|
8 |
|
|
9 |
private $limit; |
|
10 |
private $page; |
|
11 |
|
|
12 |
private $pageCount; |
|
13 |
private $itemCount; |
|
14 |
|
|
15 |
private $startingPage; |
|
16 |
private $endingPage; |
|
17 |
|
|
18 |
const ALLOWED_LIMITS = [10, 25, 50, 100]; |
|
19 |
|
|
20 |
/** |
|
21 |
* Implementation of spring Data Pageable to paginate and sort JPA queries |
|
22 |
* @param $page int query offset |
|
23 |
* @param $limit int query limit |
|
24 |
*/ |
|
25 |
public function __construct($page, $limit) |
|
26 |
{ |
|
27 |
if ($page < 1) |
|
28 |
{ |
|
29 |
$page = 1; |
|
30 |
} |
|
31 |
$this->page = $page; |
|
32 |
|
|
33 |
foreach (self::ALLOWED_LIMITS as $l) |
|
34 |
{ |
|
35 |
if ($l == $limit) |
|
36 |
{ |
|
37 |
$this->limit = $limit; |
|
38 |
} |
|
39 |
} |
|
40 |
if ($this->limit == 0) |
|
41 |
{ |
|
42 |
$this->limit = self::ALLOWED_LIMITS[0]; |
|
43 |
} |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* @return int |
|
48 |
*/ |
|
49 |
public function getPageNumber() |
|
50 |
{ |
|
51 |
return $this->page; |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* @return int |
|
56 |
*/ |
|
57 |
public function getPageSize() |
|
58 |
{ |
|
59 |
return $this->limit; |
|
60 |
} |
|
61 |
|
|
62 |
public function getOffset() |
|
63 |
{ |
|
64 |
return ($this->page - 1) * $this->limit; |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* @return Paginator |
|
69 |
*/ |
|
70 |
public function next() |
|
71 |
{ |
|
72 |
return $this->hasNext() ? new Paginator($this->getPageNumber() + 1, $this->getPageSize()) : $this; |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* @return Paginator |
|
77 |
*/ |
|
78 |
public function previous() |
|
79 |
{ |
|
80 |
return $this->hasPrevious() ? new Paginator($this->getPageNumber() - 1, $this->getPageSize()) : $this; |
|
81 |
} |
|
82 |
|
|
83 |
public function previousOrFirst() |
|
84 |
{ |
|
85 |
return $this->hasPrevious() ? $this->previous() : $this->first(); |
|
86 |
} |
|
87 |
|
|
88 |
public function first() |
|
89 |
{ |
|
90 |
return new Paginator(1, $this->getPageSize()); |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* @return bool |
|
95 |
*/ |
|
96 |
public function hasPrevious() |
|
97 |
{ |
|
98 |
return $this->getOffset() >= $this->limit; |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* @return bool |
|
103 |
*/ |
|
104 |
public function hasNext() |
|
105 |
{ |
|
106 |
return $this->getPageNumber() < $this->getPageCount(); |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* @return Paginator |
|
111 |
*/ |
|
112 |
public function last() |
|
113 |
{ |
|
114 |
return new Paginator($this->getPageCount(), $this->getPageSize()); |
|
115 |
} |
|
116 |
|
|
117 |
public function getPageCount() |
|
118 |
{ |
|
119 |
return $this->pageCount; |
|
120 |
} |
|
121 |
|
|
122 |
public function getItemCount() |
|
123 |
{ |
|
124 |
return $this->itemCount; |
|
125 |
} |
|
126 |
|
|
127 |
/** |
|
128 |
* Sets maximum possible page to be displayed and total number of items |
|
129 |
* @param $itemCount int total count |
|
130 |
*/ |
|
131 |
public function setPageCount($itemCount) |
|
132 |
{ |
|
133 |
$this->itemCount = $itemCount; |
|
134 |
$this->pageCount = ceil($itemCount / $this->getPageSize()); |
|
135 |
$this->setPagesList(); |
|
136 |
} |
|
137 |
|
|
138 |
public function getAllowedLimits() |
|
139 |
{ |
|
140 |
return self::ALLOWED_LIMITS; |
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 |
* Sets starting and ending page number to be displayed in template |
|
145 |
*/ |
|
146 |
private function setPagesList() |
|
147 |
{ |
|
148 |
$offset = 2; |
|
149 |
|
|
150 |
if ($this->getPageNumber() + $offset >= $this->getPageCount()) |
|
151 |
{ |
|
152 |
$this->startingPage = max(1, $this->getPageCount() - 2 * $offset); |
|
153 |
$this->endingPage = $this->getPageCount(); |
|
154 |
} else |
|
155 |
{ |
|
156 |
$this->startingPage = max(1, $this->getPageNumber() - $offset); |
|
157 |
$this->endingPage = min($this->startingPage + 2 * $offset, $this->getPageCount()); |
|
158 |
} |
|
159 |
} |
|
160 |
|
|
161 |
public function getStartingPage() |
|
162 |
{ |
|
163 |
return $this->startingPage; |
|
164 |
} |
|
165 |
|
|
166 |
public function getEndingPage() |
|
167 |
{ |
|
168 |
return $this->endingPage; |
|
169 |
} |
|
170 |
} |
Také k dispozici: Unified diff
Re #7328 výsledky vyhledávání přesunuty do komponenty, stránkování výsledků