Added secure and lang methods to paginator.

This commit is contained in:
Taylor Otwell 2011-07-22 11:34:44 -07:00
parent 36d9fe0b87
commit 341908d76c
1 changed files with 42 additions and 5 deletions

View File

@ -37,6 +37,20 @@ class Paginator {
*/ */
public $last_page; public $last_page;
/**
* The language that should be used when generating page links.
*
* @var string
*/
public $language;
/**
* Indicates if HTTPS links should be generated.
*
* @var bool
*/
public $https = false;
/** /**
* Create a new Paginator instance. * Create a new Paginator instance.
* *
@ -128,11 +142,11 @@ private function slider($adjacent)
*/ */
public function previous() public function previous()
{ {
$text = Lang::line('pagination.previous')->get(); $text = Lang::line('pagination.previous')->get($this->language);
if ($this->page > 1) if ($this->page > 1)
{ {
return HTML::link(Request::uri().'?page='.($this->page - 1), $text, array('class' => 'prev_page')).' '; return HTML::link(Request::uri().'?page='.($this->page - 1), $text, array('class' => 'prev_page'), $this->https).' ';
} }
return "<span class=\"disabled prev_page\">$text</span> "; return "<span class=\"disabled prev_page\">$text</span> ";
@ -145,11 +159,11 @@ public function previous()
*/ */
public function next() public function next()
{ {
$text = Lang::line('pagination.next')->get(); $text = Lang::line('pagination.next')->get($this->language);
if ($this->page < $this->last_page) if ($this->page < $this->last_page)
{ {
return HTML::link(Request::uri().'?page='.($this->page + 1), $text, array('class' => 'next_page')); return HTML::link(Request::uri().'?page='.($this->page + 1), $text, array('class' => 'next_page'), $this->https);
} }
return "<span class=\"disabled next_page\">$text</span>"; return "<span class=\"disabled next_page\">$text</span>";
@ -190,10 +204,33 @@ private function range($start, $end)
for ($i = $start; $i <= $end; $i++) for ($i = $start; $i <= $end; $i++)
{ {
$pages .= ($this->page == $i) ? "<span class=\"current\">$i</span> " : HTML::link(Request::uri().'?page='.$i, $i).' '; $pages .= ($this->page == $i) ? "<span class=\"current\">$i</span> " : HTML::link(Request::uri().'?page='.$i, $i, array(), $this->https).' ';
} }
return $pages; return $pages;
} }
/**
* Set the language that should be used when generating pagination links.
*
* @param string $language
* @return Paginator
*/
public function lang($language)
{
$this->language = $language;
return $this;
}
/**
* Force the pagination links to use HTTPS.
*
* @return Paginator
*/
public function secure()
{
$this->https = true;
return $this;
}
} }