Conditions | 3 |
Paths | 3 |
Total Lines | 31 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
47 | public function createSmartPager(AdapterInterface $adapter, $page, $limit) |
||
48 | { |
||
49 | $results = $adapter->getSlice($this->core->getOffset($page, $limit), $limit); |
||
50 | |||
51 | $count = $adapter->getCount(); |
||
52 | |||
53 | if ($count === 0) { |
||
54 | return new Pager( |
||
55 | 1, |
||
56 | $limit, |
||
57 | $count, |
||
58 | 0, |
||
59 | [] |
||
60 | ); |
||
61 | } |
||
62 | |||
63 | $pageCount = $this->core->getPageCount($count, $limit); |
||
64 | |||
65 | if ($page > $pageCount) { |
||
66 | $page = 1; |
||
67 | $results = $adapter->getSlice($this->core->getOffset($page, $limit), $limit); |
||
68 | } |
||
69 | |||
70 | return new Pager( |
||
71 | $page, |
||
72 | $limit, |
||
73 | $count, |
||
74 | $pageCount, |
||
75 | $results |
||
76 | ); |
||
77 | } |
||
78 | } |
||
79 |