Refactoring the Paginator class.

This commit is contained in:
Taylor Otwell 2011-07-22 09:49:13 -07:00
parent f7f790301f
commit c09481c519
1 changed files with 5 additions and 18 deletions

View File

@ -72,11 +72,7 @@ public function __construct($results, $total, $per_page)
*/ */
public static function page($total, $per_page) public static function page($total, $per_page)
{ {
$last_page = ceil($total / $per_page); if (is_numeric($page = Input::get('page', 1)) and $page > $last_page = ceil($total / $per_page))
$page = Input::get('page', 1);
if (is_numeric($page) and $page > $last_page)
{ {
return $last_page; return $last_page;
} }
@ -92,12 +88,7 @@ public static function page($total, $per_page)
*/ */
public function links($adjacent = 3) public function links($adjacent = 3)
{ {
if ($this->last_page() > 1) return ($this->last_page() > 1) ? '<div class="pagination">'.$this->previous().$this->numbers($adjacent).$this->next() : '';
{
return '<div class="pagination">'.$this->previous().$this->numbers($adjacent).$this->next();
}
return '';
} }
/** /**
@ -124,22 +115,18 @@ private function numbers($adjacent = 3)
*/ */
private function slider($adjacent) private function slider($adjacent)
{ {
$pagination = '';
if ($this->page <= $adjacent * 2) if ($this->page <= $adjacent * 2)
{ {
$pagination .= $this->range(1, 4 + ($adjacent * 2)).$this->ending(); return $this->range(1, 4 + ($adjacent * 2)).$this->ending();
} }
elseif ($this->page >= $this->last_page() - ($adjacent * 2)) elseif ($this->page >= $this->last_page() - ($adjacent * 2))
{ {
$pagination .= $this->beginning().$this->range($this->last_page() - 2 - ($adjacent * 2), $this->last_page()); return $this->beginning().$this->range($this->last_page() - 2 - ($adjacent * 2), $this->last_page());
} }
else else
{ {
$pagination .= $this->beginning().$this->range($this->page - $adjacent, $this->page + $adjacent).$this->ending(); return $this->beginning().$this->range($this->page - $adjacent, $this->page + $adjacent).$this->ending();
} }
return $pagination;
} }
/** /**