Advertisement
Guest User

get_paginator

a guest
Apr 16th, 2011
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1.     function get_paginator() {
  2.         $display = array();
  3.  
  4.         if ($this->current_page <= $this->num_pages) {
  5.             $visible_pages = floor($this->window_size/2) * 2 + 1;
  6.  
  7.             if ($this->num_pages <= $visible_pages) {
  8.                 $minp = 1;
  9.                 $maxp = $this->num_pages;
  10.             } else {
  11.                 $minp = $this->current_page - floor($this->window_size/2);
  12.  
  13.                 if ($minp < 1) $minp = 1;
  14.                 $maxp = $minp + $visible_pages - 1;
  15.  
  16.                 if ($maxp > $this->num_pages) {
  17.                     $maxp = $this->num_pages;
  18.                     $minp = $maxp - $visible_pages + 1;
  19.                 }
  20.             }
  21.  
  22.             if ($minp > 1) {
  23.                 $page =  new stdClass();
  24.                 $page->number = '…';
  25.                 $page->selected = False;
  26.                 $page->link = False;
  27.                 $display[] = $page;
  28.             }
  29.  
  30.             for ($i = $minp; $i <= $maxp; $i++) {
  31.                 $page =  new stdClass();
  32.                 $page->number = $i;
  33.                 $page->selected = False;
  34.                 $page->link = True;
  35.  
  36.                 if ($i == $this->current_page) {
  37.                     $page->selected = True;
  38.                 }
  39.  
  40.                 $display[] = $page;
  41.             }
  42.  
  43.             if ($maxp < $this->num_pages) {
  44.                 $page =  new stdClass();
  45.                 $page->number = '…';
  46.                 $page->selected = False;
  47.                 $page->link = False;
  48.                 $display[] = $page;
  49.             }
  50.         }
  51.  
  52.         return $display;
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement