UrlWindowPresenterTrait.php 0000666 00000002715 13436754053 0012126 0 ustar 00 window['first'])) {
$html .= $this->getUrlLinks($this->window['first']);
}
if (is_array($this->window['slider'])) {
$html .= $this->getDots();
$html .= $this->getUrlLinks($this->window['slider']);
}
if (is_array($this->window['last'])) {
$html .= $this->getDots();
$html .= $this->getUrlLinks($this->window['last']);
}
return $html;
}
/**
* Get the links for the URLs in the given array.
*
* @param array $urls
* @return string
*/
protected function getUrlLinks(array $urls)
{
$html = '';
foreach ($urls as $page => $url) {
$html .= $this->getPageLinkWrapper($url, $page);
}
return $html;
}
/**
* Get HTML wrapper for a page link.
*
* @param string $url
* @param int $page
* @param string|null $rel
* @return string
*/
protected function getPageLinkWrapper($url, $page, $rel = null)
{
if ($page == $this->paginator->currentPage()) {
return $this->getActivePageWrapper($page);
}
return $this->getAvailablePageWrapper($url, $page, $rel);
}
}
Paginator.php 0000666 00000010016 13436754053 0007215 0 ustar 00 $value) {
$this->{$key} = $value;
}
$this->perPage = $perPage;
$this->currentPage = $this->setCurrentPage($currentPage);
$this->path = $this->path != '/' ? rtrim($this->path, '/') : $this->path;
$this->items = $items instanceof Collection ? $items : Collection::make($items);
$this->checkForMorePages();
}
/**
* Get the current page for the request.
*
* @param int $currentPage
* @return int
*/
protected function setCurrentPage($currentPage)
{
$currentPage = $currentPage ?: static::resolveCurrentPage();
return $this->isValidPageNumber($currentPage) ? (int) $currentPage : 1;
}
/**
* Check for more pages. The last item will be sliced off.
*
* @return void
*/
protected function checkForMorePages()
{
$this->hasMore = count($this->items) > ($this->perPage);
$this->items = $this->items->slice(0, $this->perPage);
}
/**
* Get the URL for the next page.
*
* @return string|null
*/
public function nextPageUrl()
{
if ($this->hasMore) {
return $this->url($this->currentPage() + 1);
}
}
/**
* Determine if there are more items in the data source.
*
* @return bool
*/
public function hasMorePages()
{
return $this->hasMore;
}
/**
* Render the paginator using the given presenter.
*
* @param \Illuminate\Contracts\Pagination\Presenter|null $presenter
* @return string
*/
public function links(Presenter $presenter = null)
{
return $this->render($presenter);
}
/**
* Render the paginator using the given presenter.
*
* @param \Illuminate\Contracts\Pagination\Presenter|null $presenter
* @return string
*/
public function render(Presenter $presenter = null)
{
if (is_null($presenter) && static::$presenterResolver) {
$presenter = call_user_func(static::$presenterResolver, $this);
}
$presenter = $presenter ?: new SimpleBootstrapThreePresenter($this);
return $presenter->render();
}
/**
* Get the instance as an array.
*
* @return array
*/
public function toArray()
{
return [
'per_page' => $this->perPage(), 'current_page' => $this->currentPage(),
'next_page_url' => $this->nextPageUrl(), 'prev_page_url' => $this->previousPageUrl(),
'from' => $this->firstItem(), 'to' => $this->lastItem(),
'data' => $this->items->toArray(),
];
}
/**
* Convert the object into something JSON serializable.
*
* @return array
*/
public function jsonSerialize()
{
return $this->toArray();
}
/**
* Convert the object to its JSON representation.
*
* @param int $options
* @return string
*/
public function toJson($options = 0)
{
return json_encode($this->jsonSerialize(), $options);
}
}
BootstrapThreePresenter.php 0000666 00000006151 13436754053 0012133 0 ustar 00 paginator = $paginator;
$this->window = is_null($window) ? UrlWindow::make($paginator) : $window->get();
}
/**
* Determine if the underlying paginator being presented has pages to show.
*
* @return bool
*/
public function hasPages()
{
return $this->paginator->hasPages();
}
/**
* Convert the URL window into Bootstrap HTML.
*
* @return \Illuminate\Support\HtmlString
*/
public function render()
{
if ($this->hasPages()) {
return new HtmlString(sprintf(
'
',
$this->getPreviousButton(),
$this->getLinks(),
$this->getNextButton()
));
}
return '';
}
/**
* Get HTML wrapper for an available page link.
*
* @param string $url
* @param int $page
* @param string|null $rel
* @return string
*/
protected function getAvailablePageWrapper($url, $page, $rel = null)
{
$rel = is_null($rel) ? '' : ' rel="'.$rel.'"';
return ''.$page.'';
}
/**
* Get HTML wrapper for disabled text.
*
* @param string $text
* @return string
*/
protected function getDisabledTextWrapper($text)
{
return ''.$text.'';
}
/**
* Get HTML wrapper for active text.
*
* @param string $text
* @return string
*/
protected function getActivePageWrapper($text)
{
return ''.$text.'';
}
/**
* Get a pagination "dot" element.
*
* @return string
*/
protected function getDots()
{
return $this->getDisabledTextWrapper('...');
}
/**
* Get the current page from the paginator.
*
* @return int
*/
protected function currentPage()
{
return $this->paginator->currentPage();
}
/**
* Get the last page from the paginator.
*
* @return int
*/
protected function lastPage()
{
return $this->paginator->lastPage();
}
}
LengthAwarePaginator.php 0000666 00000011002 13436754053 0011333 0 ustar 00 $value) {
$this->{$key} = $value;
}
$this->total = $total;
$this->perPage = $perPage;
$this->lastPage = (int) ceil($total / $perPage);
$this->path = $this->path != '/' ? rtrim($this->path, '/') : $this->path;
$this->currentPage = $this->setCurrentPage($currentPage, $this->lastPage);
$this->items = $items instanceof Collection ? $items : Collection::make($items);
}
/**
* Get the current page for the request.
*
* @param int $currentPage
* @param int $lastPage
* @return int
*/
protected function setCurrentPage($currentPage, $lastPage)
{
$currentPage = $currentPage ?: static::resolveCurrentPage();
return $this->isValidPageNumber($currentPage) ? (int) $currentPage : 1;
}
/**
* Get the URL for the next page.
*
* @return string|null
*/
public function nextPageUrl()
{
if ($this->lastPage() > $this->currentPage()) {
return $this->url($this->currentPage() + 1);
}
}
/**
* Determine if there are more items in the data source.
*
* @return bool
*/
public function hasMorePages()
{
return $this->currentPage() < $this->lastPage();
}
/**
* Get the total number of items being paginated.
*
* @return int
*/
public function total()
{
return $this->total;
}
/**
* Get the last page.
*
* @return int
*/
public function lastPage()
{
return $this->lastPage;
}
/**
* Render the paginator using the given presenter.
*
* @param \Illuminate\Contracts\Pagination\Presenter|null $presenter
* @return string
*/
public function links(Presenter $presenter = null)
{
return $this->render($presenter);
}
/**
* Render the paginator using the given presenter.
*
* @param \Illuminate\Contracts\Pagination\Presenter|null $presenter
* @return string
*/
public function render(Presenter $presenter = null)
{
if (is_null($presenter) && static::$presenterResolver) {
$presenter = call_user_func(static::$presenterResolver, $this);
}
$presenter = $presenter ?: new BootstrapThreePresenter($this);
return $presenter->render();
}
/**
* Get the instance as an array.
*
* @return array
*/
public function toArray()
{
return [
'total' => $this->total(),
'per_page' => $this->perPage(),
'current_page' => $this->currentPage(),
'last_page' => $this->lastPage(),
'next_page_url' => $this->nextPageUrl(),
'prev_page_url' => $this->previousPageUrl(),
'from' => $this->firstItem(),
'to' => $this->lastItem(),
'data' => $this->items->toArray(),
];
}
/**
* Convert the object into something JSON serializable.
*
* @return array
*/
public function jsonSerialize()
{
return $this->toArray();
}
/**
* Convert the object to its JSON representation.
*
* @param int $options
* @return string
*/
public function toJson($options = 0)
{
return json_encode($this->jsonSerialize(), $options);
}
}
AbstractPaginator.php 0000666 00000024127 13436754053 0010711 0 ustar 00 = 1 && filter_var($page, FILTER_VALIDATE_INT) !== false;
}
/**
* Create a range of pagination URLs.
*
* @param int $start
* @param int $end
* @return string
*/
public function getUrlRange($start, $end)
{
$urls = [];
for ($page = $start; $page <= $end; $page++) {
$urls[$page] = $this->url($page);
}
return $urls;
}
/**
* Get a URL for a given page number.
*
* @param int $page
* @return string
*/
public function url($page)
{
if ($page <= 0) {
$page = 1;
}
// If we have any extra query string key / value pairs that need to be added
// onto the URL, we will put them in query string form and then attach it
// to the URL. This allows for extra information like sortings storage.
$parameters = [$this->pageName => $page];
if (count($this->query) > 0) {
$parameters = array_merge($this->query, $parameters);
}
return $this->path.'?'
.urldecode(http_build_query($parameters, null, '&'))
.$this->buildFragment();
}
/**
* Get the URL for the previous page.
*
* @return string|null
*/
public function previousPageUrl()
{
if ($this->currentPage() > 1) {
return $this->url($this->currentPage() - 1);
}
}
/**
* Get / set the URL fragment to be appended to URLs.
*
* @param string|null $fragment
* @return $this|string|null
*/
public function fragment($fragment = null)
{
if (is_null($fragment)) {
return $this->fragment;
}
$this->fragment = $fragment;
return $this;
}
/**
* Add a set of query string values to the paginator.
*
* @param array|string $key
* @param string|null $value
* @return $this
*/
public function appends($key, $value = null)
{
if (is_array($key)) {
return $this->appendArray($key);
}
return $this->addQuery($key, $value);
}
/**
* Add an array of query string values.
*
* @param array $keys
* @return $this
*/
protected function appendArray(array $keys)
{
foreach ($keys as $key => $value) {
$this->addQuery($key, $value);
}
return $this;
}
/**
* Add a query string value to the paginator.
*
* @param string $key
* @param string $value
* @return $this
*/
public function addQuery($key, $value)
{
if ($key !== $this->pageName) {
$this->query[$key] = $value;
}
return $this;
}
/**
* Build the full fragment portion of a URL.
*
* @return string
*/
protected function buildFragment()
{
return $this->fragment ? '#'.$this->fragment : '';
}
/**
* Get the slice of items being paginated.
*
* @return array
*/
public function items()
{
return $this->items->all();
}
/**
* Get the number of the first item in the slice.
*
* @return int
*/
public function firstItem()
{
if (count($this->items) === 0) {
return;
}
return ($this->currentPage - 1) * $this->perPage + 1;
}
/**
* Get the number of the last item in the slice.
*
* @return int
*/
public function lastItem()
{
if (count($this->items) === 0) {
return;
}
return $this->firstItem() + $this->count() - 1;
}
/**
* Get the number of items shown per page.
*
* @return int
*/
public function perPage()
{
return $this->perPage;
}
/**
* Get the current page.
*
* @return int
*/
public function currentPage()
{
return $this->currentPage;
}
/**
* Determine if there are enough items to split into multiple pages.
*
* @return bool
*/
public function hasPages()
{
return ! ($this->currentPage() == 1 && ! $this->hasMorePages());
}
/**
* Resolve the current request path or return the default value.
*
* @param string $default
* @return string
*/
public static function resolveCurrentPath($default = '/')
{
if (isset(static::$currentPathResolver)) {
return call_user_func(static::$currentPathResolver);
}
return $default;
}
/**
* Set the current request path resolver callback.
*
* @param \Closure $resolver
* @return void
*/
public static function currentPathResolver(Closure $resolver)
{
static::$currentPathResolver = $resolver;
}
/**
* Resolve the current page or return the default value.
*
* @param string $pageName
* @param int $default
* @return int
*/
public static function resolveCurrentPage($pageName = 'page', $default = 1)
{
if (isset(static::$currentPageResolver)) {
return call_user_func(static::$currentPageResolver, $pageName);
}
return $default;
}
/**
* Set the current page resolver callback.
*
* @param \Closure $resolver
* @return void
*/
public static function currentPageResolver(Closure $resolver)
{
static::$currentPageResolver = $resolver;
}
/**
* Set the default Presenter resolver.
*
* @param \Closure $resolver
* @return void
*/
public static function presenter(Closure $resolver)
{
static::$presenterResolver = $resolver;
}
/**
* Get the query string variable used to store the page.
*
* @return string
*/
public function getPageName()
{
return $this->pageName;
}
/**
* Set the query string variable used to store the page.
*
* @param string $name
* @return $this
*/
public function setPageName($name)
{
$this->pageName = $name;
return $this;
}
/**
* Set the base path to assign to all URLs.
*
* @param string $path
* @return $this
*/
public function setPath($path)
{
$this->path = $path;
return $this;
}
/**
* Get an iterator for the items.
*
* @return \ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->items->all());
}
/**
* Determine if the list of items is empty or not.
*
* @return bool
*/
public function isEmpty()
{
return $this->items->isEmpty();
}
/**
* Get the number of items for the current page.
*
* @return int
*/
public function count()
{
return $this->items->count();
}
/**
* Get the paginator's underlying collection.
*
* @return \Illuminate\Support\Collection
*/
public function getCollection()
{
return $this->items;
}
/**
* Determine if the given item exists.
*
* @param mixed $key
* @return bool
*/
public function offsetExists($key)
{
return $this->items->has($key);
}
/**
* Get the item at the given offset.
*
* @param mixed $key
* @return mixed
*/
public function offsetGet($key)
{
return $this->items->get($key);
}
/**
* Set the item at the given offset.
*
* @param mixed $key
* @param mixed $value
* @return void
*/
public function offsetSet($key, $value)
{
$this->items->put($key, $value);
}
/**
* Unset the item at the given key.
*
* @param mixed $key
* @return void
*/
public function offsetUnset($key)
{
$this->items->forget($key);
}
/**
* Render the contents of the paginator to HTML.
*
* @return string
*/
public function toHtml()
{
return (string) $this->render();
}
/**
* Make dynamic calls into the collection.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
return call_user_func_array([$this->getCollection(), $method], $parameters);
}
/**
* Render the contents of the paginator when casting to string.
*
* @return string
*/
public function __toString()
{
return (string) $this->render();
}
}
composer.json 0000666 00000001416 13436754053 0007306 0 ustar 00 {
"name": "illuminate/pagination",
"description": "The Illuminate Pagination package.",
"license": "MIT",
"homepage": "http://laravel.com",
"support": {
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"authors": [
{
"name": "Taylor Otwell",
"email": "taylorotwell@gmail.com"
}
],
"require": {
"php": ">=5.5.9",
"illuminate/contracts": "5.2.*",
"illuminate/support": "5.2.*"
},
"autoload": {
"psr-4": {
"Illuminate\\Pagination\\": ""
}
},
"extra": {
"branch-alias": {
"dev-master": "5.2-dev"
}
},
"minimum-stability": "dev"
}
UrlWindow.php 0000666 00000013123 13436754053 0007225 0 ustar 00 paginator = $paginator;
}
/**
* Create a new URL window instance.
*
* @param \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator
* @param int $onEachSide
* @return array
*/
public static function make(PaginatorContract $paginator, $onEachSide = 3)
{
return (new static($paginator))->get($onEachSide);
}
/**
* Get the window of URLs to be shown.
*
* @param int $onEachSide
* @return array
*/
public function get($onEachSide = 3)
{
if ($this->paginator->lastPage() < ($onEachSide * 2) + 6) {
return $this->getSmallSlider();
}
return $this->getUrlSlider($onEachSide);
}
/**
* Get the slider of URLs there are not enough pages to slide.
*
* @return array
*/
protected function getSmallSlider()
{
return [
'first' => $this->paginator->getUrlRange(1, $this->lastPage()),
'slider' => null,
'last' => null,
];
}
/**
* Create a URL slider links.
*
* @param int $onEachSide
* @return array
*/
protected function getUrlSlider($onEachSide)
{
$window = $onEachSide * 2;
if (! $this->hasPages()) {
return [
'first' => null,
'slider' => null,
'last' => null,
];
}
// 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) {
return $this->getSliderTooCloseToBeginning($window);
}
// 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)) {
return $this->getSliderTooCloseToEnding($window);
}
// 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.
return $this->getFullSlider($onEachSide);
}
/**
* Get the slider of URLs when too close to beginning of window.
*
* @param int $window
* @return array
*/
protected function getSliderTooCloseToBeginning($window)
{
return [
'first' => $this->paginator->getUrlRange(1, $window + 2),
'slider' => null,
'last' => $this->getFinish(),
];
}
/**
* Get the slider of URLs when too close to ending of window.
*
* @param int $window
* @return array
*/
protected function getSliderTooCloseToEnding($window)
{
$last = $this->paginator->getUrlRange(
$this->lastPage() - ($window + 2),
$this->lastPage()
);
return [
'first' => $this->getStart(),
'slider' => null,
'last' => $last,
];
}
/**
* Get the slider of URLs when a full slider can be made.
*
* @param int $onEachSide
* @return array
*/
protected function getFullSlider($onEachSide)
{
return [
'first' => $this->getStart(),
'slider' => $this->getAdjacentUrlRange($onEachSide),
'last' => $this->getFinish(),
];
}
/**
* Get the page range for the current page window.
*
* @param int $onEachSide
* @return array
*/
public function getAdjacentUrlRange($onEachSide)
{
return $this->paginator->getUrlRange(
$this->currentPage() - $onEachSide,
$this->currentPage() + $onEachSide
);
}
/**
* Get the starting URLs of a pagination slider.
*
* @return array
*/
public function getStart()
{
return $this->paginator->getUrlRange(1, 2);
}
/**
* Get the ending URLs of a pagination slider.
*
* @return array
*/
public function getFinish()
{
return $this->paginator->getUrlRange(
$this->lastPage() - 1,
$this->lastPage()
);
}
/**
* Determine if the underlying paginator being presented has pages to show.
*
* @return bool
*/
public function hasPages()
{
return $this->paginator->lastPage() > 1;
}
/**
* Get the current page from the paginator.
*
* @return int
*/
protected function currentPage()
{
return $this->paginator->currentPage();
}
/**
* Get the last page from the paginator.
*
* @return int
*/
protected function lastPage()
{
return $this->paginator->lastPage();
}
}
BootstrapThreeNextPreviousButtonRendererTrait.php 0000666 00000002750 13436754053 0016527 0 ustar 00 paginator->currentPage() <= 1) {
return $this->getDisabledTextWrapper($text);
}
$url = $this->paginator->url(
$this->paginator->currentPage() - 1
);
return $this->getPageLinkWrapper($url, $text, 'prev');
}
/**
* Get the next page pagination element.
*
* @param string $text
* @return string
*/
public function getNextButton($text = '»')
{
// 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->paginator->hasMorePages()) {
return $this->getDisabledTextWrapper($text);
}
$url = $this->paginator->url($this->paginator->currentPage() + 1);
return $this->getPageLinkWrapper($url, $text, 'next');
}
}
SimpleBootstrapThreePresenter.php 0000666 00000002204 13436754053 0013300 0 ustar 00 paginator = $paginator;
}
/**
* Determine if the underlying paginator being presented has pages to show.
*
* @return bool
*/
public function hasPages()
{
return $this->paginator->hasPages() && count($this->paginator->items()) > 0;
}
/**
* Convert the URL window into Bootstrap HTML.
*
* @return \Illuminate\Support\HtmlString
*/
public function render()
{
if ($this->hasPages()) {
return new HtmlString(sprintf(
'',
$this->getPreviousButton(),
$this->getNextButton()
));
}
return '';
}
}
PaginationServiceProvider.php 0000666 00000001251 13436754053 0012417 0 ustar 00 app['request']->url();
});
Paginator::currentPageResolver(function ($pageName = 'page') {
$page = $this->app['request']->input($pageName);
if (filter_var($page, FILTER_VALIDATE_INT) !== false && (int) $page >= 1) {
return $page;
}
return 1;
});
}
}