1 | <?php |
||
9 | abstract class Carbon_Pagination { |
||
10 | |||
11 | /** |
||
12 | * @var array |
||
13 | * |
||
14 | * Optional. Can be used if you want to loop through IDs instead of consecutive pages. |
||
15 | * If not defined, falls back to an array of all pages from 1 to $total_pages. |
||
16 | */ |
||
17 | protected $pages = array(); |
||
18 | |||
19 | /** |
||
20 | * @var int The total number of pages. |
||
21 | */ |
||
22 | protected $total_pages = 1; |
||
23 | |||
24 | /** |
||
25 | * @var int The current page number. |
||
26 | */ |
||
27 | protected $current_page = 1; |
||
28 | |||
29 | /** |
||
30 | * @var bool Whether the previous page link should be displayed. |
||
31 | */ |
||
32 | protected $enable_prev = true; |
||
33 | |||
34 | /** |
||
35 | * @var bool Whether the next page link should be displayed. |
||
36 | */ |
||
37 | protected $enable_next = true; |
||
38 | |||
39 | /** |
||
40 | * @var bool Whether the first page link should be displayed. |
||
41 | */ |
||
42 | protected $enable_first = false; |
||
43 | |||
44 | /** |
||
45 | * @var bool Whether the last page link should be displayed. |
||
46 | */ |
||
47 | protected $enable_last = false; |
||
48 | |||
49 | /** |
||
50 | * @var bool Whether the page number links should be displayed. |
||
51 | */ |
||
52 | protected $enable_numbers = false; |
||
53 | |||
54 | /** |
||
55 | * @var bool Whether the current page text ("Page X of Y") should be displayed. |
||
56 | */ |
||
57 | protected $enable_current_page_text = false; |
||
58 | |||
59 | /** |
||
60 | * @var int |
||
61 | * |
||
62 | * How much page number links should be displayed (on each side of the current page item). |
||
63 | * Using 0 means only the current page item will be displayed. |
||
64 | * Using -1 means no limit (all page number links will be displayed). |
||
65 | */ |
||
66 | protected $number_limit = -1; |
||
67 | |||
68 | /** |
||
69 | * @var int |
||
70 | * |
||
71 | * How much larger page number links should be displayed. |
||
72 | * Larger page numbers can be: 10, 20, 30, etc. |
||
73 | * Using 0 means none (no larger page number links will be displayed). |
||
74 | */ |
||
75 | protected $large_page_number_limit = 0; |
||
76 | |||
77 | /** |
||
78 | * @var int |
||
79 | * |
||
80 | * The interval between larger page number links. |
||
81 | * If set to 5, larger page numbers will be 5, 10, 15, 20, etc. |
||
82 | */ |
||
83 | protected $large_page_number_interval = 10; |
||
84 | |||
85 | /** |
||
86 | * @var string The class name of the pagination collection object. |
||
87 | */ |
||
88 | protected $collection = 'Carbon_Pagination_Collection'; |
||
89 | |||
90 | /** |
||
91 | * @var string The class name of the pagination renderer object. |
||
92 | */ |
||
93 | protected $renderer = 'Carbon_Pagination_Renderer'; |
||
94 | |||
95 | /** |
||
96 | * @var array |
||
97 | * |
||
98 | * The default argument values. Can be declared in the inheriting classes. |
||
99 | * Will override the default configuration options in Carbon_Pagination::__construct |
||
100 | * but can be overriden by the $args parameter. |
||
101 | */ |
||
102 | public $default_args = array(); |
||
103 | |||
104 | /** |
||
105 | * Constructor. |
||
106 | * Creates and configures a new pagination with the provided settings. |
||
107 | * |
||
108 | * @param array $args Configuration options to modify the pagination settings. |
||
109 | */ |
||
110 | 5 | public function __construct( $args = array() ) { |
|
120 | |||
121 | /** |
||
122 | * Bulk set certain configuration options & constraints. |
||
123 | * |
||
124 | * @param array $args Configuration options |
||
125 | */ |
||
126 | 3 | public function set( $args ) { |
|
134 | |||
135 | /** |
||
136 | * Retrieve the pages array. |
||
137 | * |
||
138 | * @return array $pages The pages array. |
||
139 | */ |
||
140 | 7 | public function get_pages() { |
|
143 | |||
144 | /** |
||
145 | * Modify the pages array. |
||
146 | * Array keys are intentionally reset. |
||
147 | * |
||
148 | * @param array $pages The new pages array. |
||
149 | */ |
||
150 | 3 | public function set_pages( $pages = array() ) { |
|
158 | |||
159 | /** |
||
160 | * Retrieve the current page number. |
||
161 | * |
||
162 | * @return int $current_page The current page number. |
||
163 | */ |
||
164 | 3 | public function get_current_page() { |
|
167 | |||
168 | /** |
||
169 | * Modify the current page number, affecting $total_pages as well. |
||
170 | * |
||
171 | * @param int $current_page The new current page number. |
||
172 | */ |
||
173 | 5 | public function set_current_page( $current_page = 1 ) { |
|
186 | |||
187 | /** |
||
188 | * Retrieve the total number of pages. |
||
189 | * |
||
190 | * @return int $total_pages The total number of pages. |
||
191 | */ |
||
192 | 7 | public function get_total_pages() { |
|
195 | |||
196 | /** |
||
197 | * Modify the total number of pages, affecting $pages as well. |
||
198 | * |
||
199 | * @param int $total_pages The new total number of pages. |
||
200 | */ |
||
201 | 4 | public function set_total_pages( $total_pages ) { |
|
210 | |||
211 | /** |
||
212 | * Whether the previous page link should be displayed. |
||
213 | * |
||
214 | * @return bool $enable_prev Whether the previous page link should be displayed. |
||
215 | */ |
||
216 | 1 | public function get_enable_prev() { |
|
219 | |||
220 | /** |
||
221 | * Change whether the previous page link should be displayed. |
||
222 | * |
||
223 | * @param bool $enable_prev Whether the previous page link should be displayed. |
||
224 | */ |
||
225 | 1 | public function set_enable_prev( $enable_prev ) { |
|
228 | |||
229 | /** |
||
230 | * Whether the next page link should be displayed. |
||
231 | * |
||
232 | * @return bool $enable_next Whether the next page link should be displayed. |
||
233 | */ |
||
234 | 1 | public function get_enable_next() { |
|
237 | |||
238 | /** |
||
239 | * Change whether the next page link should be displayed. |
||
240 | * |
||
241 | * @param bool $enable_next Whether the next page link should be displayed. |
||
242 | */ |
||
243 | 1 | public function set_enable_next( $enable_next ) { |
|
246 | |||
247 | /** |
||
248 | * Whether the first page link should be displayed. |
||
249 | * |
||
250 | * @return bool $enable_first Whether the first page link should be displayed. |
||
251 | */ |
||
252 | 1 | public function get_enable_first() { |
|
255 | |||
256 | /** |
||
257 | * Change whether the first page link should be displayed. |
||
258 | * |
||
259 | * @param bool $enable_first Whether the first page link should be displayed. |
||
260 | */ |
||
261 | 1 | public function set_enable_first( $enable_first ) { |
|
264 | |||
265 | /** |
||
266 | * Whether the last page link should be displayed. |
||
267 | * |
||
268 | * @return bool $enable_last Whether the last page link should be displayed. |
||
269 | */ |
||
270 | 1 | public function get_enable_last() { |
|
273 | |||
274 | /** |
||
275 | * Change whether the last page link should be displayed. |
||
276 | * |
||
277 | * @param bool $enable_last Whether the last page link should be displayed. |
||
278 | */ |
||
279 | 1 | public function set_enable_last( $enable_last ) { |
|
282 | |||
283 | /** |
||
284 | * Whether the page number links should be displayed. |
||
285 | * |
||
286 | * @return bool $enable_numbers Whether the page number links should be displayed. |
||
287 | */ |
||
288 | 1 | public function get_enable_numbers() { |
|
291 | |||
292 | /** |
||
293 | * Change whether the page number links should be displayed. |
||
294 | * |
||
295 | * @param bool $enable_numbers Whether the page number links should be displayed. |
||
296 | */ |
||
297 | 1 | public function set_enable_numbers( $enable_numbers ) { |
|
300 | |||
301 | /** |
||
302 | * Whether the current page text should be displayed. |
||
303 | * |
||
304 | * @return bool $enable_current_page_text Whether the current page text should be displayed. |
||
305 | */ |
||
306 | 1 | public function get_enable_current_page_text() { |
|
309 | |||
310 | /** |
||
311 | * Change whether the current page text should be displayed. |
||
312 | * |
||
313 | * @param bool $enable_current_page_text Whether the current page text should be displayed. |
||
314 | */ |
||
315 | 1 | public function set_enable_current_page_text( $enable_current_page_text ) { |
|
318 | |||
319 | /** |
||
320 | * Retrieve the page number links limit. |
||
321 | * |
||
322 | * @return int $number_limit The page number links limit. |
||
323 | */ |
||
324 | 4 | public function get_number_limit() { |
|
327 | |||
328 | /** |
||
329 | * Modify the page number links limit. |
||
330 | * |
||
331 | * @param int $number_limit The new page number links limit. |
||
332 | */ |
||
333 | 4 | public function set_number_limit( $number_limit ) { |
|
336 | |||
337 | /** |
||
338 | * Retrieve the large page number links limit. |
||
339 | * |
||
340 | * @return int $large_page_number_limit The large page number links limit. |
||
341 | */ |
||
342 | 4 | public function get_large_page_number_limit() { |
|
345 | |||
346 | /** |
||
347 | * Modify the large page number links limit. |
||
348 | * |
||
349 | * @param int $large_page_number_limit The new large page number links limit. |
||
350 | */ |
||
351 | 4 | public function set_large_page_number_limit( $large_page_number_limit ) { |
|
354 | |||
355 | /** |
||
356 | * Retrieve the large page number links interval. |
||
357 | * |
||
358 | * @return int $large_page_number_interval The large page number links interval. |
||
359 | */ |
||
360 | 4 | public function get_large_page_number_interval() { |
|
363 | |||
364 | /** |
||
365 | * Modify the large page number links interval. |
||
366 | * |
||
367 | * @param int $large_page_number_interval The new large page number links interval. |
||
368 | */ |
||
369 | 4 | public function set_large_page_number_interval( $large_page_number_interval ) { |
|
372 | |||
373 | /** |
||
374 | * Retrieve the collection object class name. |
||
375 | * |
||
376 | * @return string $collection The collection object class name. |
||
377 | */ |
||
378 | 1 | public function get_collection() { |
|
381 | |||
382 | /** |
||
383 | * Modify the collection object class name. |
||
384 | * |
||
385 | * @param string $collection The new collection object class name. |
||
386 | */ |
||
387 | 1 | public function set_collection( $collection ) { |
|
390 | |||
391 | /** |
||
392 | * Retrieve the renderer object class name. |
||
393 | * |
||
394 | * @return string $renderer The renderer object class name. |
||
395 | */ |
||
396 | 1 | public function get_renderer() { |
|
399 | |||
400 | /** |
||
401 | * Modify the renderer object class name. |
||
402 | * |
||
403 | * @param string $renderer The new renderer object class name. |
||
404 | */ |
||
405 | 1 | public function set_renderer( $renderer ) { |
|
408 | |||
409 | /** |
||
410 | * Get the URL to a certain page. |
||
411 | * |
||
412 | * @abstract |
||
413 | * @param int $page_number The page number. |
||
414 | * @param string $old_url Optional. The URL to add the page number to. |
||
415 | * @return string $url The URL to the page number. |
||
416 | */ |
||
417 | abstract public function get_page_url( $page_number, $old_url = '' ); |
||
418 | |||
419 | } |