Conditions | 4 |
Paths | 8 |
Total Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
29 | public function getPageInfo() |
||
30 | { |
||
31 | $query = clone $this->query; |
||
32 | $query->resetOrderBy(); |
||
33 | $query->resetLimit(); |
||
34 | $query->resetColumns(); |
||
35 | $query->columns('COUNT(*)'); |
||
36 | |||
37 | $statement = $query->perform(); |
||
38 | $statement->setFetchMode(PDO::FETCH_NUM); |
||
39 | |||
40 | $page = $this->page; |
||
41 | $count = $statement->fetch(); |
||
42 | $count = intval($count[0]); |
||
43 | |||
44 | return [ |
||
45 | 'totalRows' => $count, |
||
46 | 'totalPages' => (int) ceil($count / $this->perPage), |
||
47 | 'currentPage' => $count ? $page : null, |
||
48 | 'previousPage' => $page > 1 ? $page - 1 : null, |
||
49 | 'nextPage' => $count > ($page * $this->perPage) ? $page + 1 : null, |
||
50 | ]; |
||
51 | } |
||
52 | } |
||
53 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: