Total Complexity | 6 |
Total Lines | 72 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
26 | class ModelPaginator implements PaginatorInterface |
||
27 | { |
||
28 | |||
29 | use PaginatorTrait; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $modelClass; |
||
35 | |||
36 | /** |
||
37 | * @var QtModel |
||
38 | */ |
||
39 | private $model; |
||
40 | |||
41 | /** |
||
42 | * @param QtModel $model |
||
43 | * @param int $perPage |
||
44 | * @param int $page |
||
45 | */ |
||
46 | public function __construct(QtModel $model, int $perPage, int $page = 1) |
||
47 | { |
||
48 | $this->initialize($perPage, $page); |
||
49 | |||
50 | $this->model = $model; |
||
51 | $this->modelClass = $model->getModelName(); |
||
52 | $this->total = $model->count(); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @inheritDoc |
||
57 | */ |
||
58 | public function data(): ModelCollection |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @inheritDoc |
||
74 | */ |
||
75 | public function firstItem() |
||
76 | { |
||
77 | $data = $this->data(); |
||
78 | |||
79 | if ($data->isEmpty()) { |
||
80 | return null; |
||
81 | } |
||
82 | |||
83 | return $data->first(); |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @inheritDoc |
||
88 | */ |
||
89 | public function lastItem() |
||
98 | } |
||
99 | } |