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 | 1 | public function __construct(int $perPage = 15) |
|
45 | |||
46 | 1 | protected function _afterInit() |
|
50 | |||
51 | /** |
||
52 | * How many entries per page? |
||
53 | * |
||
54 | * @param int $perPage |
||
55 | * @return $this |
||
56 | */ |
||
57 | public function entriesPerPage($perPage = 15) |
||
63 | |||
64 | /** |
||
65 | * How many surrounding pages should be shown? |
||
66 | * |
||
67 | * @param int $count |
||
68 | * @return $this |
||
69 | */ |
||
70 | public function surroundingPages($count = 2) |
||
76 | |||
77 | /** |
||
78 | * @return Builder |
||
79 | */ |
||
80 | public function shapeData(): Builder |
||
89 | |||
90 | /** |
||
91 | * @return int |
||
92 | */ |
||
93 | 1 | public function pageCount(): int |
|
108 | |||
109 | /** |
||
110 | * @return null|string |
||
111 | * @throws \RuntimeException |
||
112 | */ |
||
113 | 1 | private function _getFirstPageUrl() |
|
122 | |||
123 | /** |
||
124 | * @return null|string |
||
125 | * @throws \RuntimeException |
||
126 | */ |
||
127 | 1 | private function _getPreviousPageUrl() |
|
137 | |||
138 | /** |
||
139 | * @return null|string |
||
140 | * @throws \RuntimeException |
||
141 | */ |
||
142 | 1 | private function _getNextPageUrl() |
|
151 | |||
152 | /** |
||
153 | * @return null|string |
||
154 | * @throws \RuntimeException |
||
155 | */ |
||
156 | 1 | private function _getLastPageUrl() |
|
166 | |||
167 | /** |
||
168 | * Generate URL to jump to {$pageNumber}. |
||
169 | * |
||
170 | * @param int $pageNumber |
||
171 | * @return string |
||
172 | * |
||
173 | * @throws \RuntimeException |
||
174 | */ |
||
175 | 1 | private function _buildPageUrl(int $pageNumber): string |
|
182 | |||
183 | /** |
||
184 | * Renders a list item with a page link. |
||
185 | * |
||
186 | * @param string $pagenumber |
||
187 | * @param string $url |
||
188 | * @param string|null $symbol |
||
189 | * |
||
190 | * @return string |
||
191 | */ |
||
192 | 1 | private function _renderListItem(string $pagenumber, ? string $url, ? string $symbol = null) : string |
|
212 | |||
213 | /** |
||
214 | * Renders a list of pages. |
||
215 | * |
||
216 | * @return string |
||
217 | * @throws \RuntimeException |
||
218 | */ |
||
219 | 1 | private function _renderPageList(): string |
|
242 | |||
243 | /** |
||
244 | * Render the page links. |
||
245 | * |
||
246 | * @return string |
||
247 | * @throws \RuntimeException |
||
248 | */ |
||
249 | 1 | public function render(): string |
|
264 | } |