1 | <?php |
||
2 | |||
3 | namespace Spinen\Halo\Support; |
||
4 | |||
5 | use Illuminate\Support\Collection as BaseCollection; |
||
6 | |||
7 | class Collection extends BaseCollection |
||
8 | { |
||
9 | protected array $pagination = []; |
||
10 | |||
11 | /** |
||
12 | * Current page that the collection holds |
||
13 | */ |
||
14 | public function page(): ?int |
||
15 | { |
||
16 | return $this->pagination['page'] ?? null; |
||
17 | } |
||
18 | |||
19 | /** |
||
20 | * Number of avaliable pages |
||
21 | */ |
||
22 | public function pages(): ?int |
||
23 | { |
||
24 | return ceil($this->recordCount() / $this->pageSize()); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
25 | } |
||
26 | |||
27 | /** |
||
28 | * Records per page |
||
29 | */ |
||
30 | public function pageSize(): ?int |
||
31 | { |
||
32 | return $this->pagination['pageSize'] ?? null; |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Count of records avaliable in the the |
||
37 | */ |
||
38 | public function recordCount(): ?int |
||
39 | { |
||
40 | return $this->pagination['count'] ?? null; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Set pagination |
||
45 | */ |
||
46 | public function setPagination(?int $count = null, ?int $page = null, ?int $pageSize = null): self |
||
47 | { |
||
48 | $this->pagination = array_merge($this->pagination, compact('count', 'page', 'pageSize')); |
||
49 | |||
50 | return $this; |
||
51 | } |
||
52 | } |
||
53 |