1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the League\Fractal package. |
5
|
|
|
* |
6
|
|
|
* (c) Phil Sturgeon <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace League\Fractal\Pagination; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* A paginator adapter for PhalconPHP/pagination. |
16
|
|
|
* |
17
|
|
|
* @author Thien Tran <[email protected]> |
18
|
|
|
* |
19
|
|
|
*/ |
20
|
|
|
class PhalconFrameworkPaginatorAdapter implements PaginatorInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* A slice of the result set to show in the pagination |
24
|
|
|
* |
25
|
|
|
* @var \Phalcon\Paginator\AdapterInterface |
26
|
|
|
*/ |
27
|
|
|
private $paginator; |
28
|
|
|
|
29
|
|
|
|
30
|
1 |
|
public function __construct($paginator) |
31
|
|
|
{ |
32
|
1 |
|
$this->paginator = $paginator->getPaginate(); |
33
|
1 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get the current page. |
37
|
|
|
* |
38
|
|
|
* @return int |
39
|
|
|
*/ |
40
|
1 |
|
public function getCurrentPage() |
41
|
|
|
{ |
42
|
1 |
|
return $this->paginator->current; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get the last page. |
47
|
|
|
* |
48
|
|
|
* @return int |
49
|
|
|
*/ |
50
|
1 |
|
public function getLastPage() |
51
|
|
|
{ |
52
|
1 |
|
return $this->paginator->last; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Get the total. |
57
|
|
|
* |
58
|
|
|
* @return int |
59
|
|
|
*/ |
60
|
1 |
|
public function getTotal() |
61
|
|
|
{ |
62
|
1 |
|
return $this->paginator->total_items; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get the count. |
67
|
|
|
* |
68
|
|
|
* @return int |
69
|
|
|
*/ |
70
|
1 |
|
public function getCount() |
71
|
|
|
{ |
72
|
1 |
|
return $this->paginator->total_pages; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get the number per page. |
77
|
|
|
* |
78
|
|
|
* @return int |
79
|
|
|
*/ |
80
|
|
|
public function getPerPage() |
81
|
|
|
{ |
82
|
|
|
// $this->paginator->items->count() |
|
|
|
|
83
|
|
|
// Because when we use raw sql have not this method |
84
|
|
|
return count($this->paginator->items); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Get the next. |
89
|
|
|
* |
90
|
|
|
* @return int |
91
|
|
|
*/ |
92
|
|
|
public function getNext() |
93
|
|
|
{ |
94
|
|
|
return $this->paginator->next; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Get the url for the given page. |
99
|
|
|
* |
100
|
|
|
* @param int $page |
101
|
|
|
* |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
public function getUrl($page) |
105
|
|
|
{ |
106
|
|
|
return $page; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.