Refactoring paginator... added paginator->append method.

This commit is contained in:
Taylor Otwell 2011-08-08 09:37:56 -05:00
parent aba4eec83d
commit bad119a48b
1 changed files with 28 additions and 7 deletions

View File

@ -44,6 +44,13 @@ class Paginator {
*/
public $language;
/**
* The values that should be appended to the end of the link query strings.
*
* @var array
*/
public $append = array();
/**
* Create a new Paginator instance.
*
@ -124,12 +131,7 @@ private function numbers($adjacent = 3)
{
// 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);
return ($this->last_page < 7 + ($adjacent * 2)) ? $this->range(1, $this->last_page) : $this->slider($adjacent);
}
/**
@ -237,7 +239,14 @@ private function range($start, $end)
*/
private function link($page, $text, $class)
{
return HTML::link(Request::uri().'?page='.$page, $text, array('class' => $class), Request::is_secure());
$append = '';
foreach ($this->append as $key => $value)
{
$append .= '&'.$key.'='.$value;
}
return HTML::link(Request::uri().'?page='.$page.$append, $text, array('class' => $class), Request::is_secure());
}
/**
@ -252,4 +261,16 @@ public function lang($language)
return $this;
}
/**
* Set the items that should be appended to the link query strings.
*
* @param array $values
* @return Paginator
*/
public function append($values)
{
$this->append = $values;
return $this;
}
}