1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* AnimeDb package |
4
|
|
|
* |
5
|
|
|
* @package AnimeDb |
6
|
|
|
* @author Peter Gribanov <[email protected]> |
7
|
|
|
* @copyright Copyright (c) 2011, Peter Gribanov |
8
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 GPL v3 |
9
|
|
|
*/ |
10
|
|
|
namespace AnimeDb\Bundle\PaginationBundle\Service; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @package AnimeDb\Bundle\PaginationBundle\Service |
14
|
|
|
* @author Peter Gribanov <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class Configuration |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Length of the list of pagination defaults |
20
|
|
|
* |
21
|
|
|
* @var int |
22
|
|
|
*/ |
23
|
|
|
const DEFAULT_LIST_LENGTH = 5; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var int |
27
|
|
|
*/ |
28
|
|
|
const DEFAULT_PAGE_LINK = '%s'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var int |
32
|
|
|
*/ |
33
|
|
|
protected $total_pages = 0; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var int |
37
|
|
|
*/ |
38
|
|
|
protected $current_page = 1; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var View |
42
|
|
|
*/ |
43
|
|
|
protected $view; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The number of pages displayed in the navigation |
47
|
|
|
* |
48
|
|
|
* @var int |
49
|
|
|
*/ |
50
|
|
|
protected $max_navigate = self::DEFAULT_LIST_LENGTH; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string|callback |
54
|
|
|
*/ |
55
|
|
|
protected $page_link = self::DEFAULT_PAGE_LINK; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
protected $first_page_link = ''; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param int $total_pages |
64
|
|
|
* @param int $current_page |
65
|
|
|
*/ |
66
|
11 |
|
public function __construct($total_pages = 0, $current_page = 1) |
67
|
|
|
{ |
68
|
|
|
$this->setCurrentPage($current_page); |
69
|
|
|
$this->setTotalPages($total_pages); |
70
|
11 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param int $total_pages |
74
|
|
|
* @param int $current_page |
75
|
|
|
* |
76
|
|
|
* @return Configuration |
77
|
|
|
*/ |
78
|
|
|
public static function create($total_pages = 0, $current_page = 1) |
79
|
|
|
{ |
80
|
|
|
return new static($total_pages, $current_page); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return int |
85
|
|
|
*/ |
86
|
8 |
|
public function getTotalPages() |
87
|
|
|
{ |
88
|
8 |
|
return $this->total_pages; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param int $total_pages |
93
|
|
|
* |
94
|
|
|
* @return Configuration |
95
|
|
|
*/ |
96
|
10 |
|
public function setTotalPages($total_pages) |
97
|
|
|
{ |
98
|
10 |
|
$this->total_pages = $total_pages; |
99
|
10 |
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return int |
104
|
|
|
*/ |
105
|
8 |
|
public function getCurrentPage() |
106
|
|
|
{ |
107
|
8 |
|
return $this->current_page; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param int $current_page |
112
|
|
|
* |
113
|
|
|
* @return Configuration |
114
|
|
|
*/ |
115
|
10 |
|
public function setCurrentPage($current_page) |
116
|
|
|
{ |
117
|
10 |
|
$this->current_page = $current_page; |
118
|
10 |
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return int |
123
|
|
|
*/ |
124
|
4 |
|
public function getMaxNavigate() |
125
|
|
|
{ |
126
|
4 |
|
return $this->max_navigate; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param int $max_navigate |
131
|
|
|
* |
132
|
|
|
* @return Configuration |
133
|
|
|
*/ |
134
|
5 |
|
public function setMaxNavigate($max_navigate) |
135
|
|
|
{ |
136
|
5 |
|
$this->max_navigate = $max_navigate; |
137
|
5 |
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return string|callback |
142
|
|
|
*/ |
143
|
|
|
public function getPageLink() |
144
|
|
|
{ |
145
|
|
|
return $this->page_link; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Set page link |
150
|
|
|
* |
151
|
|
|
* Basic reference, for example `page_%s.html` where %s page number, or |
152
|
|
|
* callback function which takes one parameter - the number of the page. |
153
|
|
|
* |
154
|
|
|
* <code> |
155
|
|
|
* function ($number) { |
156
|
|
|
* return 'page_'.$number.'.html'; |
157
|
|
|
* } |
158
|
|
|
* </code> |
159
|
|
|
* |
160
|
|
|
* @param string|callback $page_link |
161
|
|
|
* |
162
|
|
|
* @return Configuration |
163
|
|
|
*/ |
164
|
3 |
|
public function setPageLink($page_link) |
165
|
|
|
{ |
166
|
3 |
|
$this->page_link = $page_link; |
167
|
3 |
|
return $this; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return string |
172
|
|
|
*/ |
173
|
|
|
public function getFirstPageLink() |
174
|
|
|
{ |
175
|
|
|
return $this->first_page_link; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param string $first_page_link |
180
|
|
|
* |
181
|
|
|
* @return Configuration |
182
|
|
|
*/ |
183
|
1 |
|
public function setFirstPageLink($first_page_link) |
184
|
|
|
{ |
185
|
1 |
|
$this->first_page_link = $first_page_link; |
186
|
1 |
|
return $this; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @return View |
191
|
|
|
*/ |
192
|
|
|
public function getView() |
193
|
|
|
{ |
194
|
|
|
if (!$this->view) { |
195
|
|
|
$this->view = new View($this); |
196
|
|
|
} |
197
|
|
|
return $this->view; |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|