pluf2

pluf2 Commit Details


Date:2010-09-01 09:18:40 (14 years 3 months ago)
Author:Thomas Riché
Branch:master
Commit:eae74c43288708c85cfd971cca44eefb51d98aab
Parents: e289514c275b734c41ca10b762bf979bb6c65499
Message:Paginator max number of pages

Changes:

File differences

src/Pluf/Paginator.php
216216
217217
218218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
219247
220248
221249
......
433461
434462
435463
436
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
437485
438
486
439487
440488
441489
442490
443491
492
493
494
495
496
497
498
499
500
501
444502
445503
446504
447
505
506
448507
449508
450509
protected $active_list_filter = array();
/**
* Maximum number of pages to be displayed
*
* Instead of showing by default unlimited number of pages,
* limit to this value.
* 0 is unlimited (default).
*
* Ex: max_number_pages = 3 will produce
* Prev 1 ... 498 499 500 ... 1678 Next
*/
public $max_number_pages = 0;
public $max_number_pages_separator = '...';
public $custom_max_items = false;
/**
* First, Previous, Next and Last page display
* Default First = 1, Last = last page num
* Prev and Next are initialized to null. In the footer() we will
* set Prev = __('Prev') and Next = __('Next') if not set
* Last has to be set during render if not set so that we know
* the number of pages
*/
public $symbol_first = '1';
public $symbol_last = null;
public $symbol_prev = null;
public $symbol_next = null;
/**
* Construct the paginator for a model.
*
* @param object Model to paginate (null).
if ($this->current_page != 1) {
$params['_px_p'] = $this->current_page - 1;
$url = $this->getUrl($params);
$out .= '<a href="'.$url.'">'.__('Prev').'</a> ';
$this->symbol_prev = ($this->symbol_prev ==null) ?__('Prev') : $this->symbol_prev;
$out .= '<a href="'.$url.'">'.$this->symbol_prev.'</a> ';
}
// Always display the link to Page#1
$i=1;
$params['_px_p'] = $i;
$class = ($i == $this->current_page) ? ' class="px-current-page"' : '';
$url = $this->getUrl($params);
$out .= '<a'.$class.' href="'.$url.'">'.$this->symbol_first.'</a> ';
// Display the number of pages given $this->max_number_pages
if ($this->max_number_pages > 0) {
$nb_pa = floor($this->max_number_pages/2);
$imin = $this->current_page - $nb_pa;
$imax = $this->current_page + $nb_pa;
// We put the separator if $imin is at leat greater than 1+$nb_pa
if($imin>2) $out .= ' '.$this->max_number_pages_separator.' ';
if($imin<=1) $imin=2;
if($imax>=$this->page_number) $imax = $this->page_number - 1;
} else {
$imin = 2;
$imax = $this->page_number - 1;
}
for ($i=1; $i<=$this->page_number; $i++) {
for ($i=$imin; $i<=$imax; $i++) {
$params['_px_p'] = $i;
$class = ($i == $this->current_page) ? ' class="px-current-page"' : '';
$url = $this->getUrl($params);
$out .= '<a'.$class.' href="'.$url.'">'.$i.'</a> ';
}
if (($this->max_number_pages > 0) && $imax < ($this->page_number - 1)) {
$out .= ' '.$this->max_number_pages_separator.' ';
}
// Always display the link to last Page
$i = $this->page_number;
$params['_px_p'] = $i;
$class = ($i == $this->current_page) ? ' class="px-current-page"' : '';
$url = $this->getUrl($params);
if ($this->symbol_last == null) $this->symbol_last=$i;
$out .= '<a'.$class.' href="'.$url.'">'.$this->symbol_last.'</a> ';
if ($this->current_page != $this->page_number) {
$params['_px_p'] = $this->current_page + 1;
$url = $this->getUrl($params);
$out .= '<a href="'.$url.'">'.__('Next').'</a> ';
$this->symbol_next = ($this->symbol_next == null) ? __('Next') : $this->symbol_next;
$out .= '<a href="'.$url.'">'.$this->symbol_next.'</a> ';
}
$out .= '</th></tr></tfoot>'."\n";
return $out;

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.05338s using 13 queries.