File: D:/HostingSpaces/SBogers33/bbec.nl/app/Komma/Pagination/Presenters.php
<?php
namespace Komma\Pagination;
use Illuminate\Pagination\Presenter;
class Presenters extends Presenter
{
/**
* Get HTML wrapper for a page link.
*
* @param string $url
* @param int $page
* @param string $rel
* @return string
*/
public function getPageLinkWrapper($url, $page, $rel = null)
{
$rel = is_null($rel) ? '' : ' rel="'.$rel.'"';
return '<li><a href="'.$url.'"'.$rel.'>'.$page.'</a></li>';
}
/**
* Get HTML wrapper for disabled text.
*
* @param string $text
* @return string
*/
public function getDisabledTextWrapper($text)
{
return '<li class="disabled">'.$text.'</li>';
}
/**
* Get HTML wrapper for active text.
*
* @param string $text
* @return string
*/
public function getActivePageWrapper($text)
{
return '<li class="active"><span>'.$text.'</span></li>';
}
/**
* Get the previous page pagination element.
*
* @param string $text
* @return string
*/
public function getPrevious($text = '')
{
$text = trans('pagination.previous');
$text = "<span></span>";
// If the current page is less than or equal to one, it means we can't go any
// further back in the pages, so we will render a disabled previous button
// when that is the case. Otherwise, we will give it an active "status".
if ($this->currentPage <= 1)
{
return $this->getDisabledTextWrapper($text);
}
$url = $this->paginator->getUrl($this->currentPage - 1);
return $this->getPageLinkWrapper($url, $text, 'prev');
}
/**
* Get the next page pagination element.
*
* @param string $text
* @return string
*/
public function getNext($text = '')
{
$text = trans('pagination.next');
$text = "<span></span>";
// If the current page is greater than or equal to the last page, it means we
// can't go any further into the pages, as we're already on this last page
// that is available, so we will make it the "next" link style disabled.
if ($this->currentPage >= $this->lastPage)
{
return $this->getDisabledTextWrapper($text);
}
$url = $this->paginator->getUrl($this->currentPage + 1);
return $this->getPageLinkWrapper($url, $text, 'next');
}
/**
* Get a pagination "dot" element.
*
* @return string
*/
public function getDots()
{
return '<li class="dots">...</li>';
}
/**
* Get the page range for the current page window.
*
* @return string
*/
public function getAdjacentRange()
{
return $this->getPageRange($this->currentPage - 1, $this->currentPage + 1);
}
/**
* Render the Pagination contents.
*
* @return string
*/
public function render()
{
// The hard-coded thirteen represents the minimum number of pages we need to
// be able to create a sliding page window. If we have less than that, we
// will just render a simple range of page links insteadof the sliding.
if ($this->lastPage < 7)
{
$content = $this->getPageRange(1, $this->lastPage);
}
else
{
$content = $this->getPageSlider();
}
return $this->getPrevious().$content.$this->getNext();
}
/**
* Create a pagination slider link window.
*
* @return string
*/
protected function getPageSlider()
{
$window = 3;
// If the current page is very close to the beginning of the page range, we will
// just render the beginning of the page range, followed by the last 2 of the
// links in this list, since we will not have room to create a full slider.
if ($this->currentPage <= $window)
{
$ending = $this->getFinish();
return $this->getPageRange(1, $window + 2).$ending;
}
// If the current page is close to the ending of the page range we will just get
// this first couple pages, followed by a larger window of these ending pages
// since we're too close to the end of the list to create a full on slider.
elseif ($this->currentPage >= $this->lastPage - $window)
{
$start = $this->lastPage - 4;
$content = $this->getPageRange($start, $this->lastPage);
return $this->getStart().$content;
}
// If we have enough room on both sides of the current page to build a slider we
// will surround it with both the beginning and ending caps, with this window
// of pages in the middle providing a Google style sliding paginator setup.
else
{
$content = $this->getAdjacentRange();
return $this->getStart().$content.$this->getFinish();
}
}
}