From c19ab70a0f595724da6dae50b3ad29860d158d04 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 2 Aug 2011 11:22:59 -0500 Subject: [PATCH] refactor paginator for readability. --- system/paginator.php | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/system/paginator.php b/system/paginator.php index 1045b831..10c8481e 100644 --- a/system/paginator.php +++ b/system/paginator.php @@ -107,7 +107,9 @@ class Paginator { */ public function links($adjacent = 3) { - return ($this->last_page > 1) ? '' : ''; + if ($this->last_page <= 1) return ''; + + return ''; } /** @@ -120,7 +122,14 @@ class Paginator { */ 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 @@ class Paginator { { $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 @@ class Paginator { { $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')); } /**