Commit 57d62f55 authored by Taylor Otwell's avatar Taylor Otwell

working on the pain in the rear paginator class.

parent d2f30156
...@@ -51,6 +51,13 @@ class Paginator { ...@@ -51,6 +51,13 @@ class Paginator {
*/ */
public $append = array(); public $append = array();
/**
* The format that will be used to wrap the entire pagination string.
*
* @var string
*/
protected $wrapper = '<div class="pagination">%s</div>';
/** /**
* Create a new Paginator instance. * Create a new Paginator instance.
* *
...@@ -96,7 +103,7 @@ class Paginator { ...@@ -96,7 +103,7 @@ class Paginator {
*/ */
public static function page($total, $per_page) public static function page($total, $per_page)
{ {
$page = Input::get('page', 1); $page = IoC::container()->core('input')->get('page', 1);
if (is_numeric($page) and $page > $last_page = ceil($total / $per_page)) if (is_numeric($page) and $page > $last_page = ceil($total / $per_page))
{ {
...@@ -112,22 +119,17 @@ class Paginator { ...@@ -112,22 +119,17 @@ class Paginator {
* @param int $adjacent * @param int $adjacent
* @return string * @return string
*/ */
public function links($adjacent = 3) public function links($adjacent = 4)
{ {
if ($this->last_page <= 1) return ''; if ($this->last_page <= 1) return '';
// The hard-coded "7" is to account for all of the constant elements in a sliding range. // If there are two few pages to make showing a slider possible, we will just display a
// Namely: The the current page, the two ellipses, the two beginning pages, and the two ending pages. // range of plain number links. The hard-coded "7" is to account for all of the constant
if ($this->last_page < 7 + ($adjacent * 2)) // elements in a sliding range, namely the current page, the two ellipses, the two
{ // beginning and ending pages.
$numbers = $this->range(1, $this->last_page); $numbers = ($this->last_page < 7 + ($adjacent * 2)) ? $this->range(1, $this->last_page) : $this->slider($adjacent);
}
else
{
$numbers = $this->slider($adjacent);
}
return '<div class="pagination">'.$this->previous().$numbers.$this->next().'</div>'; return sprintf($this->wrapper, $this->previous().$numbers.$this->next());
} }
/** /**
...@@ -244,7 +246,9 @@ class Paginator { ...@@ -244,7 +246,9 @@ class Paginator {
$append .= '&'.$key.'='.$value; $append .= '&'.$key.'='.$value;
} }
return HTML::link(Request::uri().'?page='.$page.$append, $text, compact('class'), Request::secure()); $request = IoC::container()->core('request');
return HTML::link($request->uri().'?page='.$page.$append, $text, compact('class'), $request->secure());
} }
/** /**
...@@ -256,6 +260,7 @@ class Paginator { ...@@ -256,6 +260,7 @@ class Paginator {
public function lang($language) public function lang($language)
{ {
$this->language = $language; $this->language = $language;
return $this; return $this;
} }
...@@ -268,6 +273,7 @@ class Paginator { ...@@ -268,6 +273,7 @@ class Paginator {
public function append($values) public function append($values)
{ {
$this->append = $values; $this->append = $values;
return $this; return $this;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment