1 | <?php |
||
13 | class Paginator extends DataComponent { |
||
14 | |||
15 | /** @var int */ |
||
16 | private $_perPage; |
||
17 | |||
18 | /** @var int */ |
||
19 | private $_currentPage; |
||
20 | |||
21 | /** @var string */ |
||
22 | private $_firstPageSymbol = 'first'; |
||
23 | |||
24 | /** @var string */ |
||
25 | private $_previousPageSymbol = '←'; |
||
26 | |||
27 | /** @var string */ |
||
28 | private $_nextPageSymbol = '→'; |
||
29 | |||
30 | /** @var string */ |
||
31 | private $_lastPageSymbol = 'last'; |
||
32 | |||
33 | /** @var int */ |
||
34 | private $_surroundingPages = 2; |
||
35 | |||
36 | |||
37 | /** |
||
38 | * Paginator constructor. |
||
39 | * @param int $perPage |
||
40 | */ |
||
41 | 3 | public function __construct(int $perPage = 15) |
|
45 | |||
46 | /** |
||
47 | * How many entries per page? |
||
48 | * |
||
49 | * @param int $perPage |
||
50 | * @return Paginator |
||
51 | */ |
||
52 | public function entriesPerPage($perPage = 15): Paginator |
||
58 | |||
59 | /** |
||
60 | * How many surrounding pages should be shown? |
||
61 | * |
||
62 | * @param int $count |
||
63 | * @return Paginator |
||
64 | */ |
||
65 | public function surroundingPages($count = 2): Paginator |
||
71 | |||
72 | /** |
||
73 | * @return Builder |
||
74 | */ |
||
75 | public function _shapeData(): Builder |
||
84 | |||
85 | /** |
||
86 | * Render the page links. |
||
87 | * |
||
88 | * @return string |
||
89 | * @throws \RuntimeException |
||
90 | */ |
||
91 | 2 | public function render(): string |
|
106 | |||
107 | /** |
||
108 | * Renders a list item with a page link. |
||
109 | * |
||
110 | * @param int $pagenumber |
||
111 | * @param string $url |
||
112 | * @param string|null $symbol |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | 1 | private function _renderListItem(int $pagenumber, ? string $url, ? string $symbol = null): string |
|
125 | |||
126 | /** |
||
127 | * @return null|string |
||
128 | * @throws \RuntimeException |
||
129 | */ |
||
130 | 1 | private function _getFirstPageUrl() |
|
139 | |||
140 | /** |
||
141 | * Generate URL to jump to {$pageNumber}. |
||
142 | * |
||
143 | * @param int $pageNumber |
||
144 | * @return string |
||
145 | * |
||
146 | * @throws \RuntimeException |
||
147 | */ |
||
148 | 1 | private function _buildPageUrl(int $pageNumber): string |
|
155 | |||
156 | /** |
||
157 | * @return null|string |
||
158 | * @throws \RuntimeException |
||
159 | */ |
||
160 | 1 | private function _getPreviousPageUrl() |
|
170 | |||
171 | /** |
||
172 | * Renders a list of pages. |
||
173 | * |
||
174 | * @return string |
||
175 | * @throws \RuntimeException |
||
176 | */ |
||
177 | 1 | private function _renderPageList(): string |
|
189 | |||
190 | /** |
||
191 | * @return int |
||
192 | */ |
||
193 | 1 | private function _getEndPage(): int |
|
200 | |||
201 | /** |
||
202 | * @return int |
||
203 | */ |
||
204 | 2 | public function pageCount(): int |
|
219 | |||
220 | /** |
||
221 | * @return int |
||
222 | */ |
||
223 | 1 | private function _getStartPage(): int |
|
229 | |||
230 | /** |
||
231 | * @return null|string |
||
232 | * @throws \RuntimeException |
||
233 | */ |
||
234 | 1 | private function _getNextPageUrl() |
|
243 | |||
244 | /** |
||
245 | * @return null|string |
||
246 | * @throws \RuntimeException |
||
247 | */ |
||
248 | 1 | private function _getLastPageUrl() |
|
258 | |||
259 | 3 | protected function _afterInit() |
|
263 | } |