refactor paginator for readability.

This commit is contained in:
Taylor Otwell 2011-08-02 11:22:59 -05:00
parent be3266d255
commit c19ab70a0f
1 changed files with 23 additions and 4 deletions

View File

@ -107,7 +107,9 @@ public static function page($total, $per_page)
*/
public function links($adjacent = 3)
{
return ($this->last_page > 1) ? '<div class="pagination">'.$this->previous().$this->numbers($adjacent).$this->next().'</div>' : '';
if ($this->last_page <= 1) return '';
return '<div class="pagination">'.$this->previous().$this->numbers($adjacent).$this->next().'</div>';
}
/**
@ -120,7 +122,14 @@ public function links($adjacent = 3)
*/
private function numbers($adjacent = 3)
{
return ($this->last_page < 7 + ($adjacent * 2)) ? $this->range(1, $this->last_page) : $this->slider($adjacent);
// The hard-coded "7" is to account for all of the constant elements in a sliding range.
// Namely: The the current page, the two ellipses, the two beginning pages, and the two ending pages.
if ($this->last_page < 7 + ($adjacent * 2))
{
return $this->range(1, $this->last_page);
}
return $this->slider($adjacent);
}
/**
@ -152,7 +161,12 @@ public function previous()
{
$text = Lang::line('pagination.previous')->get($this->language);
return ($this->page > 1) ? $this->link($this->page - 1, $text, 'prev_page').' ' : HTML::span($text, array('class' => 'disabled prev_page')).' ';
if ($this->page > 1)
{
return $this->link($this->page - 1, $text, 'prev_page').' ';
}
return HTML::span($text, array('class' => 'disabled prev_page')).' ';
}
/**
@ -164,7 +178,12 @@ public function next()
{
$text = Lang::line('pagination.next')->get($this->language);
return ($this->page < $this->last_page) ? $this->link($this->page + 1, $text, 'next_page') : HTML::span($text, array('class' => 'disabled next_page'));
if ($this->page < $this->last_page)
{
return $this->link($this->page + 1, $text, 'next_page');
}
return HTML::span($text, array('class' => 'disabled next_page'));
}
/**