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