1 | <?php |
||
9 | class PagerView |
||
10 | { |
||
11 | /** |
||
12 | * @var int |
||
13 | */ |
||
14 | private $currentPage; |
||
15 | |||
16 | /** |
||
17 | * @var int|null is set when data is fetched |
||
18 | */ |
||
19 | private $total; |
||
20 | |||
21 | /** |
||
22 | * @var int |
||
23 | */ |
||
24 | private $length; |
||
25 | |||
26 | /** |
||
27 | * @var Paginator |
||
28 | */ |
||
29 | private $paginator; |
||
30 | |||
31 | /** |
||
32 | * @var array|null is set when data is fetched |
||
33 | */ |
||
34 | private $data; |
||
35 | |||
36 | /** |
||
37 | * PagerView constructor. |
||
38 | * |
||
39 | * @param Paginator $paginator |
||
40 | * @param int $currentPage |
||
41 | * @param int $perPage |
||
42 | */ |
||
43 | 28 | public function __construct(Paginator $paginator, int $currentPage, int $perPage) |
|
49 | |||
50 | /** |
||
51 | * @return int |
||
52 | */ |
||
53 | 4 | public function getCurrentPage(): int |
|
57 | |||
58 | /** |
||
59 | * @return int |
||
60 | */ |
||
61 | 21 | public function getTotal(): int |
|
69 | |||
70 | /** |
||
71 | * @return int |
||
72 | */ |
||
73 | 2 | public function getLength(): int |
|
77 | |||
78 | /** |
||
79 | * @param int|null $page |
||
80 | * |
||
81 | * @return int |
||
82 | */ |
||
83 | 24 | public function getFirstResult(?int $page = null): int |
|
87 | |||
88 | /** |
||
89 | * @param int|null $page |
||
90 | * |
||
91 | * @return int |
||
92 | */ |
||
93 | 3 | public function getLastResult(?int $page = null) : int |
|
100 | |||
101 | /** |
||
102 | * @return int |
||
103 | */ |
||
104 | 7 | public function getLastPage(): int |
|
108 | |||
109 | /** |
||
110 | * @return int|null |
||
111 | */ |
||
112 | 2 | public function getPrevPage(): ?int |
|
122 | |||
123 | /** |
||
124 | * @return int|null |
||
125 | */ |
||
126 | 4 | public function getNextPage(): ?int |
|
136 | |||
137 | /** |
||
138 | * @param int $page |
||
139 | * |
||
140 | * @return bool if valid |
||
141 | */ |
||
142 | 10 | public function validatePage(int $page): bool |
|
146 | |||
147 | /** |
||
148 | * @param int $page |
||
149 | * |
||
150 | * @return bool |
||
151 | */ |
||
152 | 3 | public function iteratePage(int $page): bool |
|
163 | |||
164 | /** |
||
165 | * Sets ListView to the next page |
||
166 | * |
||
167 | * @return bool |
||
168 | */ |
||
169 | 2 | public function iterateNextPage(): bool |
|
177 | |||
178 | /** |
||
179 | * @return array |
||
180 | */ |
||
181 | 3 | public function getData(): array |
|
189 | |||
190 | /** |
||
191 | * creates pages array for rendering it in front. |
||
192 | * |
||
193 | * @param int $length To determinate pager length. (2*$length+5) |
||
194 | * Basically how much pages has to be added around active page |
||
195 | * for example length 2 with active page 10 and total pages 20 will be rendered like this: |
||
196 | * 1 ... 8 9 10 11 12 ... 20 |
||
197 | * With length 1: |
||
198 | * 1 ... 9 10 11 ... 201 |
||
199 | * |
||
200 | * @return array = [ |
||
201 | * 'page' => int|null if null - skip mark should be added (like "...") |
||
202 | * 'active' => true|false whether this page is equal to current page |
||
203 | * ][] |
||
204 | */ |
||
205 | 7 | public function getPages(int $length = 1): array |
|
240 | |||
241 | /** |
||
242 | * Sets data for provided page number |
||
243 | * |
||
244 | * @param int $page |
||
245 | */ |
||
246 | 22 | private function setData(int $page): void |
|
252 | |||
253 | /** |
||
254 | * @param int $pagerLength |
||
255 | * @param int $lastPage |
||
256 | * |
||
257 | * @return array |
||
258 | */ |
||
259 | 6 | private function getRange(int $pagerLength, int $lastPage): array |
|
279 | } |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: