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
|
|
|
protected $paginator; |
28
|
|
|
|
29
|
|
|
/*** |
30
|
|
|
* |
31
|
|
|
* @return void |
|
|
|
|
32
|
|
|
*/ |
33
|
1 |
|
public function __construct($paginator) |
34
|
|
|
{ |
35
|
1 |
|
$this->paginator = $paginator; |
36
|
1 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get the current page. |
40
|
|
|
* |
41
|
|
|
* @return int |
42
|
|
|
*/ |
43
|
1 |
|
public function getCurrentPage() |
44
|
|
|
{ |
45
|
1 |
|
return $this->getPaginate()->current; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get the last page. |
50
|
|
|
* |
51
|
|
|
* @return int |
52
|
|
|
*/ |
53
|
1 |
|
public function getLastPage() |
54
|
|
|
{ |
55
|
1 |
|
return $this->getPaginate()->last; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Get the total. |
60
|
|
|
* |
61
|
|
|
* @return int |
62
|
|
|
*/ |
63
|
1 |
|
public function getTotal() |
64
|
|
|
{ |
65
|
1 |
|
return $this->getPaginate()->total_items; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get the count. |
70
|
|
|
* |
71
|
|
|
* @return int |
72
|
|
|
*/ |
73
|
1 |
|
public function getCount() |
74
|
|
|
{ |
75
|
1 |
|
return $this->getPaginate()->total_pages; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Get the number per page. |
80
|
|
|
* |
81
|
|
|
* @return int |
82
|
|
|
*/ |
83
|
|
|
public function getPerPage() |
84
|
|
|
{ |
85
|
|
|
return $this->paginator->getLimit(); |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get the next. |
91
|
|
|
* |
92
|
|
|
* @return int |
93
|
|
|
*/ |
94
|
|
|
public function getNext() |
95
|
|
|
{ |
96
|
|
|
return $this->getPaginate()->next; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get the url for the given page. |
101
|
|
|
* |
102
|
|
|
* @param int $page |
103
|
|
|
* |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
public function getUrl($page) |
107
|
|
|
{ |
108
|
|
|
//PhalconPHP not yet |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get the paginate object. |
113
|
|
|
* |
114
|
|
|
* @return object |
115
|
|
|
*/ |
116
|
1 |
|
public function getPaginate() |
117
|
|
|
{ |
118
|
|
|
|
119
|
1 |
|
return $this->paginator->getPaginate(); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.