1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package Redcore |
4
|
|
|
* @subpackage Pagination |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) 2008 - 2021 redWEB.dk. All rights reserved. |
7
|
|
|
* @license GNU General Public License version 2 or later, see LICENSE. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
defined('JPATH_PLATFORM') or die; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Pagination Class. Provides a common interface for content pagination for the |
14
|
|
|
* Joomla! CMS. |
15
|
|
|
* |
16
|
|
|
* @package Redcore |
17
|
|
|
* @subpackage Pagination |
18
|
|
|
* @since 1.0 |
19
|
|
|
*/ |
20
|
|
|
class RPagination |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var integer The record number to start displaying from. |
24
|
|
|
* @since 1.0 |
25
|
|
|
*/ |
26
|
|
|
public $limitstart = null; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var integer Number of rows to display per page. |
30
|
|
|
* @since 1.0 |
31
|
|
|
*/ |
32
|
|
|
public $limit = null; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var integer Total number of rows. |
36
|
|
|
* @since 1.0 |
37
|
|
|
*/ |
38
|
|
|
public $total = null; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var integer Prefix used for request variables. |
42
|
|
|
* @since 1.6 |
43
|
|
|
*/ |
44
|
|
|
public $prefix = null; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var integer Value pagination object begins at |
48
|
|
|
* @since 3.0 |
49
|
|
|
*/ |
50
|
|
|
public $pagesStart; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var integer Value pagination object ends at |
54
|
|
|
* @since 3.0 |
55
|
|
|
*/ |
56
|
|
|
public $pagesStop; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var integer Current page |
60
|
|
|
* @since 3.0 |
61
|
|
|
*/ |
62
|
|
|
public $pagesCurrent; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var integer Total number of pages |
66
|
|
|
* @since 3.0 |
67
|
|
|
*/ |
68
|
|
|
public $pagesTotal; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var boolean View all flag |
72
|
|
|
* @since 3.0 |
73
|
|
|
*/ |
74
|
|
|
protected $viewall = false; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Additional URL parameters to be added to the pagination URLs generated by the class. These |
78
|
|
|
* may be useful for filters and extra values when dealing with lists and GET requests. |
79
|
|
|
* |
80
|
|
|
* @var array |
81
|
|
|
* @since 3.0 |
82
|
|
|
*/ |
83
|
|
|
protected $additionalUrlParams = array(); |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @var JApplicationCms The application object |
87
|
|
|
* @since 3.4 |
88
|
|
|
*/ |
89
|
|
|
protected $app = null; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Pagination data object |
93
|
|
|
* |
94
|
|
|
* @var object |
95
|
|
|
* @since 3.4 |
96
|
|
|
*/ |
97
|
|
|
protected $data; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Associated form name |
101
|
|
|
* |
102
|
|
|
* @var string |
103
|
|
|
*/ |
104
|
|
|
public $formName = 'adminForm'; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Constructor. |
108
|
|
|
* |
109
|
|
|
* @param integer $total The total number of items. |
110
|
|
|
* @param integer $limitstart The offset of the item to start at. |
111
|
|
|
* @param integer $limit The number of items to display per page. |
112
|
|
|
* @param string $prefix The prefix used for request variables. |
113
|
|
|
* @param JApplicationCms $app The application object |
114
|
|
|
* |
115
|
|
|
* @since 1.0 |
116
|
|
|
*/ |
117
|
|
|
public function __construct($total, $limitstart, $limit, $prefix = '', JApplicationCms $app = null) |
118
|
|
|
{ |
119
|
|
|
// Value/type checking. |
120
|
|
|
$this->total = (int) $total; |
121
|
|
|
$this->limitstart = (int) max($limitstart, 0); |
122
|
|
|
$this->limit = (int) max($limit, 0); |
123
|
|
|
$this->prefix = $prefix; |
|
|
|
|
124
|
|
|
$this->app = $app ? $app : JFactory::getApplication(); |
125
|
|
|
|
126
|
|
|
if ($this->limit > $this->total) |
127
|
|
|
{ |
128
|
|
|
$this->limitstart = 0; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
if (!$this->limit) |
132
|
|
|
{ |
133
|
|
|
$this->limit = $total; |
134
|
|
|
$this->limitstart = 0; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/* |
138
|
|
|
* If limitstart is greater than total (i.e. we are asked to display records that don't exist) |
139
|
|
|
* then set limitstart to display the last natural page of results |
140
|
|
|
*/ |
141
|
|
|
if ($this->limitstart > $this->total - $this->limit) |
142
|
|
|
{ |
143
|
|
|
$this->limitstart = max(0, (int) (ceil($this->total / $this->limit) - 1) * $this->limit); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
// Set the total pages and current page values. |
147
|
|
|
if ($this->limit > 0) |
148
|
|
|
{ |
149
|
|
|
$this->pagesTotal = ceil($this->total / $this->limit); |
150
|
|
|
$this->pagesCurrent = ceil(($this->limitstart + 1) / $this->limit); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
// Set the pagination iteration loop values. |
154
|
|
|
$displayedPages = 10; |
155
|
|
|
$this->pagesStart = $this->pagesCurrent - ($displayedPages / 2); |
156
|
|
|
|
157
|
|
|
if ($this->pagesStart < 1) |
158
|
|
|
{ |
159
|
|
|
$this->pagesStart = 1; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
if ($this->pagesStart + $displayedPages > $this->pagesTotal) |
163
|
|
|
{ |
164
|
|
|
$this->pagesStop = $this->pagesTotal; |
165
|
|
|
|
166
|
|
|
if ($this->pagesTotal < $displayedPages) |
167
|
|
|
{ |
168
|
|
|
$this->pagesStart = 1; |
169
|
|
|
} |
170
|
|
|
else |
171
|
|
|
{ |
172
|
|
|
$this->pagesStart = $this->pagesTotal - $displayedPages + 1; |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
else |
176
|
|
|
{ |
177
|
|
|
$this->pagesStop = $this->pagesStart + $displayedPages - 1; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
// If we are viewing all records set the view all flag to true. |
181
|
|
|
if ($limit == 0) |
182
|
|
|
{ |
183
|
|
|
$this->viewall = true; |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Method to set an additional URL parameter to be added to all pagination class generated |
189
|
|
|
* links. |
190
|
|
|
* |
191
|
|
|
* @param string $key The name of the URL parameter for which to set a value. |
192
|
|
|
* @param mixed $value The value to set for the URL parameter. |
193
|
|
|
* |
194
|
|
|
* @return mixed The old value for the parameter. |
195
|
|
|
* |
196
|
|
|
* @since 1.6 |
197
|
|
|
*/ |
198
|
|
|
public function setAdditionalUrlParam($key, $value) |
199
|
|
|
{ |
200
|
|
|
// Get the old value to return and set the new one for the URL parameter. |
201
|
|
|
$result = isset($this->additionalUrlParams[$key]) ? $this->additionalUrlParams[$key] : null; |
202
|
|
|
|
203
|
|
|
// If the passed parameter value is null unset the parameter, otherwise set it to the given value. |
204
|
|
|
if ($value === null) |
205
|
|
|
{ |
206
|
|
|
unset($this->additionalUrlParams[$key]); |
207
|
|
|
} |
208
|
|
|
else |
209
|
|
|
{ |
210
|
|
|
$this->additionalUrlParams[$key] = $value; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
return $result; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Method to get an additional URL parameter (if it exists) to be added to |
218
|
|
|
* all pagination class generated links. |
219
|
|
|
* |
220
|
|
|
* @param string $key The name of the URL parameter for which to get the value. |
221
|
|
|
* |
222
|
|
|
* @return mixed The value if it exists or null if it does not. |
223
|
|
|
* |
224
|
|
|
* @since 1.6 |
225
|
|
|
*/ |
226
|
|
|
public function getAdditionalUrlParam($key) |
227
|
|
|
{ |
228
|
|
|
$result = isset($this->additionalUrlParams[$key]) ? $this->additionalUrlParams[$key] : null; |
229
|
|
|
|
230
|
|
|
return $result; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Return the rationalised offset for a row with a given index. |
235
|
|
|
* |
236
|
|
|
* @param integer $index The row index |
237
|
|
|
* |
238
|
|
|
* @return integer Rationalised offset for a row with a given index. |
239
|
|
|
* |
240
|
|
|
* @since 1.0 |
241
|
|
|
*/ |
242
|
|
|
public function getRowOffset($index) |
243
|
|
|
{ |
244
|
|
|
return $index + 1 + $this->limitstart; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* Return the pagination data object, only creating it if it doesn't already exist. |
249
|
|
|
* |
250
|
|
|
* @return object Pagination data object. |
251
|
|
|
* |
252
|
|
|
* @since 1.0 |
253
|
|
|
*/ |
254
|
|
|
public function getData() |
255
|
|
|
{ |
256
|
|
|
if (!$this->data) |
257
|
|
|
{ |
258
|
|
|
$this->data = $this->_buildDataObject(); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
return $this->data; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Create and return the pagination pages counter string, ie. Page 2 of 4. |
266
|
|
|
* |
267
|
|
|
* @return string Pagination pages counter string. |
268
|
|
|
* |
269
|
|
|
* @since 1.0 |
270
|
|
|
*/ |
271
|
|
|
public function getPagesCounter() |
272
|
|
|
{ |
273
|
|
|
$html = null; |
274
|
|
|
|
275
|
|
|
if ($this->pagesTotal > 1) |
276
|
|
|
{ |
277
|
|
|
$html .= JText::sprintf('JLIB_HTML_PAGE_CURRENT_OF_TOTAL', $this->pagesCurrent, $this->pagesTotal); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
return $html; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* Create and return the pagination result set counter string, e.g. Results 1-10 of 42 |
285
|
|
|
* |
286
|
|
|
* @return string Pagination result set counter string. |
287
|
|
|
* |
288
|
|
|
* @since 1.0 |
289
|
|
|
*/ |
290
|
|
|
public function getResultsCounter() |
291
|
|
|
{ |
292
|
|
|
$html = null; |
293
|
|
|
$fromResult = $this->limitstart + 1; |
294
|
|
|
|
295
|
|
|
// If the limit is reached before the end of the list. |
296
|
|
|
if ($this->limitstart + $this->limit < $this->total) |
297
|
|
|
{ |
298
|
|
|
$toResult = $this->limitstart + $this->limit; |
299
|
|
|
} |
300
|
|
|
else |
301
|
|
|
{ |
302
|
|
|
$toResult = $this->total; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
// If there are results found. |
306
|
|
|
if ($this->total > 0) |
307
|
|
|
{ |
308
|
|
|
$msg = JText::sprintf('JLIB_HTML_RESULTS_OF', $fromResult, $toResult, $this->total); |
309
|
|
|
$html .= "\n" . $msg; |
310
|
|
|
} |
311
|
|
|
else |
312
|
|
|
{ |
313
|
|
|
$html .= "\n" . JText::_('JLIB_HTML_NO_RECORDS_FOUND'); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
return $html; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* Create and return the pagination page list string, ie. Previous, Next, 1 2 3 ... x. |
321
|
|
|
* |
322
|
|
|
* @return string Pagination page list string. |
323
|
|
|
* |
324
|
|
|
* @since 1.0 |
325
|
|
|
*/ |
326
|
|
|
public function getPagesLinks() |
327
|
|
|
{ |
328
|
|
|
$app = JFactory::getApplication(); |
329
|
|
|
|
330
|
|
|
// Build the page navigation list. |
331
|
|
|
$data = $this->_buildDataObject(); |
332
|
|
|
|
333
|
|
|
$list = array(); |
334
|
|
|
$list['prefix'] = $this->prefix; |
335
|
|
|
$list['formName'] = $this->formName; |
336
|
|
|
|
337
|
|
|
$itemOverride = false; |
338
|
|
|
$listOverride = false; |
339
|
|
|
|
340
|
|
|
// For the backend we force our html. |
341
|
|
|
if ((version_compare(JVERSION, '3.7', '<') ? $app->isSite() : $app->isClient('site'))) |
|
|
|
|
342
|
|
|
{ |
343
|
|
|
$chromePath = JPATH_THEMES . '/' . $app->getTemplate() . '/html/pagination.php'; |
344
|
|
|
|
345
|
|
|
if (file_exists($chromePath)) |
346
|
|
|
{ |
347
|
|
|
include_once $chromePath; |
348
|
|
|
|
349
|
|
|
if (function_exists('pagination_item_active') && function_exists('pagination_item_inactive')) |
350
|
|
|
{ |
351
|
|
|
$itemOverride = true; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
if (function_exists('pagination_list_render')) |
355
|
|
|
{ |
356
|
|
|
$listOverride = true; |
357
|
|
|
} |
358
|
|
|
} |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
// Build the select list |
362
|
|
|
if ($data->all->base !== null) |
363
|
|
|
{ |
364
|
|
|
$list['all']['active'] = true; |
365
|
|
|
$list['all']['data'] = ($itemOverride) ? pagination_item_active($data->all) : $this->_item_active($data->all); |
366
|
|
|
} |
367
|
|
|
else |
368
|
|
|
{ |
369
|
|
|
$list['all']['active'] = false; |
370
|
|
|
$list['all']['data'] = ($itemOverride) ? pagination_item_inactive($data->all) : $this->_item_inactive($data->all); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
if ($data->start->base !== null) |
374
|
|
|
{ |
375
|
|
|
$list['start']['active'] = true; |
376
|
|
|
$list['start']['data'] = ($itemOverride) ? pagination_item_active($data->start) : $this->_item_active($data->start); |
377
|
|
|
} |
378
|
|
|
else |
379
|
|
|
{ |
380
|
|
|
$list['start']['active'] = false; |
381
|
|
|
$list['start']['data'] = ($itemOverride) ? pagination_item_inactive($data->start) : $this->_item_inactive($data->start); |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
if ($data->previous->base !== null) |
385
|
|
|
{ |
386
|
|
|
$list['previous']['active'] = true; |
387
|
|
|
$list['previous']['data'] = ($itemOverride) ? pagination_item_active($data->previous) : $this->_item_active($data->previous); |
388
|
|
|
} |
389
|
|
|
else |
390
|
|
|
{ |
391
|
|
|
$list['previous']['active'] = false; |
392
|
|
|
$list['previous']['data'] = ($itemOverride) ? pagination_item_inactive($data->previous) : $this->_item_inactive($data->previous); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
// Make sure it exists |
396
|
|
|
$list['pages'] = array(); |
397
|
|
|
|
398
|
|
|
foreach ($data->pages as $i => $page) |
399
|
|
|
{ |
400
|
|
|
if ($page->base !== null) |
401
|
|
|
{ |
402
|
|
|
$list['pages'][$i]['active'] = true; |
403
|
|
|
$list['pages'][$i]['data'] = ($itemOverride) ? pagination_item_active($page) : $this->_item_active($page); |
404
|
|
|
} |
405
|
|
|
else |
406
|
|
|
{ |
407
|
|
|
$list['pages'][$i]['active'] = false; |
408
|
|
|
$list['pages'][$i]['data'] = ($itemOverride) ? pagination_item_inactive($page) : $this->_item_inactive($page); |
409
|
|
|
} |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
if ($data->next->base !== null) |
413
|
|
|
{ |
414
|
|
|
$list['next']['active'] = true; |
415
|
|
|
$list['next']['data'] = ($itemOverride) ? pagination_item_active($data->next) : $this->_item_active($data->next); |
416
|
|
|
} |
417
|
|
|
else |
418
|
|
|
{ |
419
|
|
|
$list['next']['active'] = false; |
420
|
|
|
$list['next']['data'] = ($itemOverride) ? pagination_item_inactive($data->next) : $this->_item_inactive($data->next); |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
if ($data->end->base !== null) |
424
|
|
|
{ |
425
|
|
|
$list['end']['active'] = true; |
426
|
|
|
$list['end']['data'] = ($itemOverride) ? pagination_item_active($data->end) : $this->_item_active($data->end); |
427
|
|
|
} |
428
|
|
|
else |
429
|
|
|
{ |
430
|
|
|
$list['end']['active'] = false; |
431
|
|
|
$list['end']['data'] = ($itemOverride) ? pagination_item_inactive($data->end) : $this->_item_inactive($data->end); |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
if ($this->total > $this->limit) |
435
|
|
|
{ |
436
|
|
|
return ($listOverride) ? pagination_list_render($list) : $this->_list_render($list); |
437
|
|
|
} |
438
|
|
|
else |
439
|
|
|
{ |
440
|
|
|
return ''; |
441
|
|
|
} |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* Get the pagination links |
446
|
|
|
* |
447
|
|
|
* @param string $layoutId Layout to render the links |
448
|
|
|
* @param array $options Optional array with settings for the layout |
449
|
|
|
* |
450
|
|
|
* @return string Pagination links. |
451
|
|
|
*/ |
452
|
|
|
public function getPaginationLinks($layoutId = 'pagination.links', $options = array()) |
453
|
|
|
{ |
454
|
|
|
// Allow to receive a null layout |
455
|
|
|
$layoutId = (null === $layoutId) ? 'pagination.links' : $layoutId; |
|
|
|
|
456
|
|
|
|
457
|
|
|
$list = array( |
458
|
|
|
'prefix' => $this->prefix, |
459
|
|
|
'limit' => $this->limit, |
460
|
|
|
'limitstart' => $this->limitstart, |
461
|
|
|
'total' => $this->total, |
462
|
|
|
'limitfield' => $this->getLimitBox(), |
463
|
|
|
'pagescounter' => $this->getPagesCounter(), |
464
|
|
|
'pages' => $this->getPaginationPages(), |
465
|
|
|
'pagesTotal' => $this->pagesTotal, |
466
|
|
|
'formName' => $this->formName |
467
|
|
|
); |
468
|
|
|
|
469
|
|
|
return RLayoutHelper::render($layoutId, array('list' => $list, 'options' => $options)); |
470
|
|
|
} |
471
|
|
|
|
472
|
|
|
/** |
473
|
|
|
* Create and return the pagination pages list, ie. Previous, Next, 1 2 3 ... x. |
474
|
|
|
* |
475
|
|
|
* @return array Pagination pages list. |
476
|
|
|
* |
477
|
|
|
* @since 1.0 |
478
|
|
|
*/ |
479
|
|
|
public function getPaginationPages() |
480
|
|
|
{ |
481
|
|
|
$list = array(); |
482
|
|
|
|
483
|
|
|
if ($this->total > $this->limit) |
484
|
|
|
{ |
485
|
|
|
// Build the page navigation list. |
486
|
|
|
$data = $this->_buildDataObject(); |
487
|
|
|
|
488
|
|
|
// All |
489
|
|
|
$list['all']['active'] = (null !== $data->all->base); |
490
|
|
|
$list['all']['data'] = $data->all; |
491
|
|
|
|
492
|
|
|
// Start |
493
|
|
|
$list['start']['active'] = (null !== $data->start->base); |
494
|
|
|
$list['start']['data'] = $data->start; |
495
|
|
|
|
496
|
|
|
// Previous link |
497
|
|
|
$list['previous']['active'] = (null !== $data->previous->base); |
498
|
|
|
$list['previous']['data'] = $data->previous; |
499
|
|
|
|
500
|
|
|
// Previous 10 link |
501
|
|
|
$list['previous_10']['active'] = (null !== $data->previous_10->base); |
502
|
|
|
$list['previous_10']['data'] = $data->previous_10; |
503
|
|
|
|
504
|
|
|
// Make sure it exists |
505
|
|
|
$list['pages'] = array(); |
506
|
|
|
|
507
|
|
|
foreach ($data->pages as $i => $page) |
508
|
|
|
{ |
509
|
|
|
$list['pages'][$i]['active'] = (null !== $page->base); |
510
|
|
|
$list['pages'][$i]['data'] = $page; |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
$list['next']['active'] = (null !== $data->next->base); |
514
|
|
|
$list['next']['data'] = $data->next; |
515
|
|
|
|
516
|
|
|
$list['next_10']['active'] = (null !== $data->next_10->base); |
517
|
|
|
$list['next_10']['data'] = $data->next_10; |
518
|
|
|
|
519
|
|
|
$list['end']['active'] = (null !== $data->end->base); |
520
|
|
|
$list['end']['data'] = $data->end; |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
return $list; |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
/** |
527
|
|
|
* Return the pagination footer. |
528
|
|
|
* |
529
|
|
|
* @return string Pagination footer. |
530
|
|
|
* |
531
|
|
|
* @since 1.0 |
532
|
|
|
*/ |
533
|
|
|
public function getListFooter() |
534
|
|
|
{ |
535
|
|
|
// Keep B/C for overrides done with chromes |
536
|
|
|
$chromePath = JPATH_THEMES . '/' . JFactory::getApplication()->getTemplate() . '/html/pagination.php'; |
537
|
|
|
|
538
|
|
|
if (file_exists($chromePath)) |
539
|
|
|
{ |
540
|
|
|
$list = array( |
541
|
|
|
'prefix' => $this->prefix, |
542
|
|
|
'limit' => $this->limit, |
543
|
|
|
'limitstart' => $this->limitstart, |
544
|
|
|
'total' => $this->total, |
545
|
|
|
'limitfield' => $this->getLimitBox(), |
546
|
|
|
'pagescounter' => $this->getPagesCounter(), |
547
|
|
|
'pageslinks' => $this->getPagesLinks(), |
548
|
|
|
'formName' => $this->formName, |
549
|
|
|
); |
550
|
|
|
|
551
|
|
|
include_once $chromePath; |
552
|
|
|
|
553
|
|
|
if (function_exists('pagination_list_footer')) |
554
|
|
|
{ |
555
|
|
|
return pagination_list_footer($list); |
556
|
|
|
} |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
return $this->getPaginationLinks(); |
560
|
|
|
} |
561
|
|
|
|
562
|
|
|
/** |
563
|
|
|
* Creates a dropdown box for selecting how many records to show per page. |
564
|
|
|
* |
565
|
|
|
* @return string The HTML for the limit # input box. |
566
|
|
|
* |
567
|
|
|
* @since 1.0 |
568
|
|
|
*/ |
569
|
|
|
public function getLimitBox() |
570
|
|
|
{ |
571
|
|
|
$app = JFactory::getApplication(); |
572
|
|
|
$limits = array(); |
573
|
|
|
|
574
|
|
|
// Make the option list. |
575
|
|
|
for ($i = 5; $i <= 30; $i += 5) |
576
|
|
|
{ |
577
|
|
|
$limits[] = JHtml::_('select.option', "$i"); |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
$limits[] = JHtml::_('select.option', '50', JText::_('J50')); |
581
|
|
|
$limits[] = JHtml::_('select.option', '100', JText::_('J100')); |
582
|
|
|
$limits[] = JHtml::_('select.option', '0', JText::_('JALL')); |
583
|
|
|
|
584
|
|
|
$selected = $this->viewall ? 0 : $this->limit; |
585
|
|
|
|
586
|
|
|
// Build the select list. |
587
|
|
|
if ((version_compare(JVERSION, '3.7', '<') ? $app->isAdmin() : $app->isClient('administrator'))) |
|
|
|
|
588
|
|
|
{ |
589
|
|
|
$html = JHtml::_( |
590
|
|
|
'select.genericlist', |
591
|
|
|
$limits, |
592
|
|
|
$this->prefix . 'limit', |
593
|
|
|
'class="inputbox input-mini" size="1" onchange="Joomla.submitform(\'\',document.forms[\'' . $this->formName . '\']);"', |
594
|
|
|
'value', |
595
|
|
|
'text', |
596
|
|
|
$selected |
597
|
|
|
); |
598
|
|
|
} |
599
|
|
|
else |
600
|
|
|
{ |
601
|
|
|
$html = JHtml::_( |
602
|
|
|
'select.genericlist', |
603
|
|
|
$limits, |
604
|
|
|
$this->prefix . 'limit', |
605
|
|
|
'class="inputbox input-mini" size="1" onchange="Joomla.submitform(\'\',document.forms[\'' . $this->formName . '\']);"', |
606
|
|
|
'value', |
607
|
|
|
'text', |
608
|
|
|
$selected |
609
|
|
|
); |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
return $html; |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
/** |
616
|
|
|
* Return the icon to move an item UP. |
617
|
|
|
* |
618
|
|
|
* @param integer $i The row index. |
619
|
|
|
* @param boolean $condition True to show the icon. |
620
|
|
|
* @param string $task The task to fire. |
621
|
|
|
* @param string $alt The image alternative text string. |
622
|
|
|
* @param boolean $enabled An optional setting for access control on the action. |
623
|
|
|
* @param string $checkbox An optional prefix for checkboxes. |
624
|
|
|
* |
625
|
|
|
* @return string Either the icon to move an item up or a space. |
626
|
|
|
* |
627
|
|
|
* @since 1.0 |
628
|
|
|
*/ |
629
|
|
|
public function orderUpIcon($i, $condition = true, $task = 'orderup', $alt = 'JLIB_HTML_MOVE_UP', $enabled = true, $checkbox = 'cb') |
630
|
|
|
{ |
631
|
|
|
if (($i > 0 || ($i + $this->limitstart > 0)) && $condition) |
632
|
|
|
{ |
633
|
|
|
return JHtml::_('rgrid.orderUp', $i, $task, '', $alt, $enabled, $checkbox); |
634
|
|
|
} |
635
|
|
|
else |
636
|
|
|
{ |
637
|
|
|
return ' '; |
638
|
|
|
} |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
/** |
642
|
|
|
* Return the icon to move an item DOWN. |
643
|
|
|
* |
644
|
|
|
* @param integer $i The row index. |
645
|
|
|
* @param integer $n The number of items in the list. |
646
|
|
|
* @param boolean $condition True to show the icon. |
647
|
|
|
* @param string $task The task to fire. |
648
|
|
|
* @param string $alt The image alternative text string. |
649
|
|
|
* @param boolean $enabled An optional setting for access control on the action. |
650
|
|
|
* @param string $checkbox An optional prefix for checkboxes. |
651
|
|
|
* |
652
|
|
|
* @return string Either the icon to move an item down or a space. |
653
|
|
|
* |
654
|
|
|
* @since 1.0 |
655
|
|
|
*/ |
656
|
|
|
public function orderDownIcon($i, $n, $condition = true, $task = 'orderdown', $alt = 'JLIB_HTML_MOVE_DOWN', $enabled = true, $checkbox = 'cb') |
657
|
|
|
{ |
658
|
|
|
if (($i < $n - 1 || $i + $this->limitstart < $this->total - 1) && $condition) |
659
|
|
|
{ |
660
|
|
|
return JHtml::_('rgrid.orderDown', $i, $task, '', $alt, $enabled, $checkbox); |
661
|
|
|
} |
662
|
|
|
else |
663
|
|
|
{ |
664
|
|
|
return ' '; |
665
|
|
|
} |
666
|
|
|
} |
667
|
|
|
|
668
|
|
|
/** |
669
|
|
|
* Create the HTML for a list footer |
670
|
|
|
* |
671
|
|
|
* @param array $list Pagination list data structure. |
672
|
|
|
* |
673
|
|
|
* @return string HTML for a list footer |
674
|
|
|
* |
675
|
|
|
* @since 1.5 |
676
|
|
|
*/ |
677
|
|
|
protected function _list_footer($list) |
678
|
|
|
{ |
679
|
|
|
$html = "<div class=\"list-footer\">\n"; |
680
|
|
|
|
681
|
|
|
$html .= "\n<div class=\"limit\">" . JText::_('JGLOBAL_DISPLAY_NUM') . $list['limitfield'] . "</div>"; |
682
|
|
|
$html .= $list['pageslinks']; |
683
|
|
|
$html .= "\n<div class=\"counter\">" . $list['pagescounter'] . "</div>"; |
684
|
|
|
|
685
|
|
|
$html .= "\n<input type=\"hidden\" name=\"" . $list['prefix'] . "limitstart\" value=\"" . $list['limitstart'] . "\" />"; |
686
|
|
|
$html .= "\n</div>"; |
687
|
|
|
|
688
|
|
|
return $html; |
689
|
|
|
} |
690
|
|
|
|
691
|
|
|
/** |
692
|
|
|
* Create the html for a list footer |
693
|
|
|
* |
694
|
|
|
* @param array $list Pagination list data structure. |
695
|
|
|
* |
696
|
|
|
* @return string HTML for a list start, previous, next,end |
697
|
|
|
* |
698
|
|
|
* @since 1.0 |
699
|
|
|
*/ |
700
|
|
|
protected function _list_render($list) |
701
|
|
|
{ |
702
|
|
|
return RLayoutHelper::render('pagination.list.render', $list); |
|
|
|
|
703
|
|
|
} |
704
|
|
|
|
705
|
|
|
/** |
706
|
|
|
* Method to create an active pagination link to the item |
707
|
|
|
* |
708
|
|
|
* @param RPaginationObject $item The object with which to make an active link. |
709
|
|
|
* |
710
|
|
|
* @return string HTML link |
711
|
|
|
* |
712
|
|
|
* @since 1.0 |
713
|
|
|
*/ |
714
|
|
|
protected function _item_active(RPaginationObject $item) |
715
|
|
|
{ |
716
|
|
|
return RLayoutHelper::render('pagination.item.active', $item); |
717
|
|
|
} |
718
|
|
|
|
719
|
|
|
/** |
720
|
|
|
* Method to create an inactive pagination string |
721
|
|
|
* |
722
|
|
|
* @param RPaginationObject $item The item to be processed |
723
|
|
|
* |
724
|
|
|
* @return string |
725
|
|
|
* |
726
|
|
|
* @since 1.0 |
727
|
|
|
*/ |
728
|
|
|
protected function _item_inactive(RPaginationObject $item) |
729
|
|
|
{ |
730
|
|
|
return RLayoutHelper::render('pagination.item.inactive', $item); |
731
|
|
|
} |
732
|
|
|
|
733
|
|
|
/** |
734
|
|
|
* Create and return the pagination data object. |
735
|
|
|
* |
736
|
|
|
* @return object Pagination data object. |
737
|
|
|
* |
738
|
|
|
* @since 1.0 |
739
|
|
|
*/ |
740
|
|
|
protected function _buildDataObject() |
741
|
|
|
{ |
742
|
|
|
$data = new stdClass; |
743
|
|
|
|
744
|
|
|
// Build the additional URL parameters string. |
745
|
|
|
$params = ''; |
746
|
|
|
|
747
|
|
|
if (!empty($this->additionalUrlParams)) |
748
|
|
|
{ |
749
|
|
|
foreach ($this->additionalUrlParams as $key => $value) |
750
|
|
|
{ |
751
|
|
|
$params .= '&' . $key . '=' . $value; |
752
|
|
|
} |
753
|
|
|
} |
754
|
|
|
|
755
|
|
|
$data->all = new RPaginationObject(JText::_('JLIB_HTML_VIEW_ALL'), $this->prefix); |
756
|
|
|
$data->all->setFormName($this->formName); |
757
|
|
|
|
758
|
|
|
if (!$this->viewall) |
759
|
|
|
{ |
760
|
|
|
$data->all->base = '0'; |
|
|
|
|
761
|
|
|
$data->all->link = JRoute::_($params . '&' . $this->prefix . 'limitstart='); |
762
|
|
|
} |
763
|
|
|
|
764
|
|
|
// Set the start and previous data objects. |
765
|
|
|
$data->start = new RPaginationObject(JText::_('JLIB_HTML_START'), $this->prefix); |
766
|
|
|
$data->start->setFormName($this->formName); |
767
|
|
|
$data->previous_10 = new RPaginationObject(JText::_('LIB_REDCORE_PREVIOUS_10'), $this->prefix); |
768
|
|
|
$data->previous_10->setFormName($this->formName); |
769
|
|
|
$data->previous = new RPaginationObject(JText::_('JPREV'), $this->prefix); |
770
|
|
|
$data->previous->setFormName($this->formName); |
771
|
|
|
|
772
|
|
|
if ($this->pagesCurrent > 1) |
773
|
|
|
{ |
774
|
|
|
$page = ($this->pagesCurrent - 2) * $this->limit; |
775
|
|
|
|
776
|
|
|
// Set the empty for removal from route |
777
|
|
|
// @todo remove code: $page = $page == 0 ? '' : $page; |
778
|
|
|
|
779
|
|
|
$data->start->base = '0'; |
|
|
|
|
780
|
|
|
$data->start->link = JRoute::_($params . '&' . $this->prefix . 'limitstart=0'); |
781
|
|
|
$data->previous->base = $page; |
782
|
|
|
$data->previous->link = JRoute::_($params . '&' . $this->prefix . 'limitstart=' . $page); |
783
|
|
|
} |
784
|
|
|
|
785
|
|
|
if ($this->pagesCurrent > 10) |
786
|
|
|
{ |
787
|
|
|
$page = ($this->pagesCurrent - 11) * $this->limit; |
788
|
|
|
|
789
|
|
|
$data->previous_10->base = $page; |
790
|
|
|
$data->previous_10->link = JRoute::_($params . '&' . $this->prefix . 'limitstart=' . $page); |
791
|
|
|
} |
792
|
|
|
|
793
|
|
|
// Set the next and end data objects. |
794
|
|
|
$data->next = new RPaginationObject(JText::_('JNEXT'), $this->prefix); |
795
|
|
|
$data->next->setFormName($this->formName); |
796
|
|
|
$data->next_10 = new RPaginationObject(JText::_('LIB_REDCORE_NEXT_10'), $this->prefix); |
797
|
|
|
$data->next_10->setFormName($this->formName); |
798
|
|
|
$data->end = new RPaginationObject(JText::_('JLIB_HTML_END'), $this->prefix); |
799
|
|
|
$data->end->setFormName($this->formName); |
800
|
|
|
|
801
|
|
|
if ($this->pagesCurrent < $this->pagesTotal) |
802
|
|
|
{ |
803
|
|
|
$next = $this->pagesCurrent * $this->limit; |
804
|
|
|
$end = ($this->pagesTotal - 1) * $this->limit; |
805
|
|
|
|
806
|
|
|
$data->next->base = $next; |
807
|
|
|
$data->next->link = JRoute::_($params . '&' . $this->prefix . 'limitstart=' . $next); |
808
|
|
|
$data->end->base = $end; |
809
|
|
|
$data->end->link = JRoute::_($params . '&' . $this->prefix . 'limitstart=' . $end); |
810
|
|
|
} |
811
|
|
|
|
812
|
|
|
if ($this->pagesCurrent < $this->pagesTotal - 9) |
813
|
|
|
{ |
814
|
|
|
$page = ($this->pagesCurrent + 9) * $this->limit; |
815
|
|
|
|
816
|
|
|
$data->next_10->base = $page; |
817
|
|
|
$data->next_10->link = JRoute::_($params . '&' . $this->prefix . 'limitstart=' . $page); |
818
|
|
|
} |
819
|
|
|
|
820
|
|
|
$data->pages = array(); |
821
|
|
|
$stop = $this->pagesStop; |
822
|
|
|
|
823
|
|
|
for ($i = $this->pagesStart; $i <= $stop; $i++) |
824
|
|
|
{ |
825
|
|
|
$offset = ($i - 1) * $this->limit; |
826
|
|
|
|
827
|
|
|
$data->pages[$i] = new RPaginationObject($i, $this->prefix); |
828
|
|
|
$data->pages[$i]->setFormName($this->formName); |
829
|
|
|
|
830
|
|
|
if ($i != $this->pagesCurrent || $this->viewall) |
831
|
|
|
{ |
832
|
|
|
$data->pages[$i]->base = $offset; |
833
|
|
|
$data->pages[$i]->link = JRoute::_($params . '&' . $this->prefix . 'limitstart=' . $offset); |
834
|
|
|
} |
835
|
|
|
else |
836
|
|
|
{ |
837
|
|
|
$data->pages[$i]->active = true; |
838
|
|
|
} |
839
|
|
|
} |
840
|
|
|
|
841
|
|
|
return $data; |
842
|
|
|
} |
843
|
|
|
|
844
|
|
|
/** |
845
|
|
|
* Modifies a property of the object, creating it if it does not already exist. |
846
|
|
|
* |
847
|
|
|
* @param string $property The name of the property. |
848
|
|
|
* @param mixed $value The value of the property to set. |
849
|
|
|
* |
850
|
|
|
* @return void |
851
|
|
|
* |
852
|
|
|
* @since 3.0 |
853
|
|
|
* @deprecated 4.0 Access the properties directly. |
854
|
|
|
*/ |
855
|
|
|
public function set($property, $value = null) |
856
|
|
|
{ |
857
|
|
|
JLog::add(__CLASS__ . '::set() is deprecated. Access the properties directly.', JLog::WARNING, 'deprecated'); |
858
|
|
|
|
859
|
|
|
if (strpos($property, '.')) |
860
|
|
|
{ |
861
|
|
|
$prop = explode('.', $property); |
862
|
|
|
$prop[1] = ucfirst($prop[1]); |
863
|
|
|
$property = implode($prop); |
864
|
|
|
} |
865
|
|
|
|
866
|
|
|
$this->$property = $value; |
867
|
|
|
} |
868
|
|
|
|
869
|
|
|
/** |
870
|
|
|
* Returns a property of the object or the default value if the property is not set. |
871
|
|
|
* |
872
|
|
|
* @param string $property The name of the property. |
873
|
|
|
* @param mixed $default The default value. |
874
|
|
|
* |
875
|
|
|
* @return mixed The value of the property. |
876
|
|
|
* |
877
|
|
|
* @since 3.0 |
878
|
|
|
* @deprecated 4.0 Access the properties directly. |
879
|
|
|
*/ |
880
|
|
|
public function get($property, $default = null) |
881
|
|
|
{ |
882
|
|
|
JLog::add(__CLASS__ . '::get() is deprecated. Access the properties directly.', JLog::WARNING, 'deprecated'); |
883
|
|
|
|
884
|
|
|
if (strpos($property, '.')) |
885
|
|
|
{ |
886
|
|
|
$prop = explode('.', $property); |
887
|
|
|
$prop[1] = ucfirst($prop[1]); |
888
|
|
|
$property = implode($prop); |
889
|
|
|
} |
890
|
|
|
|
891
|
|
|
if (isset($this->$property)) |
892
|
|
|
{ |
893
|
|
|
return $this->$property; |
894
|
|
|
} |
895
|
|
|
|
896
|
|
|
return $default; |
897
|
|
|
} |
898
|
|
|
} |
899
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.