2013-10-16 13:07:01 +02:00
|
|
|
<?php
|
2014-02-20 19:06:06 +01:00
|
|
|
if (!isset($this->context->transport->paginator))
|
|
|
|
return;
|
|
|
|
|
Paginator: introducing "..." pseudo-pages
If delta between pages in paginator is greater than 2, it adds "..." inbetween.
If delta is equal to 2, it adds missing page link instead.
Examples:
1,4,5 gets converted to 1,...,4,5
1,3,4 gets converted to 1,2,3,4
2013-11-22 08:52:24 +01:00
|
|
|
$page = $this->context->transport->paginator->page;
|
|
|
|
$pageCount = $this->context->transport->paginator->pageCount;
|
2013-10-16 13:07:01 +02:00
|
|
|
|
Paginator: introducing "..." pseudo-pages
If delta between pages in paginator is greater than 2, it adds "..." inbetween.
If delta is equal to 2, it adds missing page link instead.
Examples:
1,4,5 gets converted to 1,...,4,5
1,3,4 gets converted to 1,2,3,4
2013-11-22 08:52:24 +01:00
|
|
|
$delta = 3;
|
|
|
|
$pagesVisible = [1, $pageCount];
|
|
|
|
$pagesVisible = array_merge($pagesVisible, range($page - $delta, $page + $delta));
|
|
|
|
$pagesVisible = array_filter($pagesVisible, function($x) use ($pageCount) { return $x >= 1 and $x <= $pageCount; });
|
|
|
|
$pagesVisible = array_unique($pagesVisible);
|
|
|
|
sort($pagesVisible, SORT_NUMERIC);
|
|
|
|
|
|
|
|
$finalPages = [$pagesVisible[0]];
|
|
|
|
for ($i = 1; $i < count($pagesVisible); $i ++)
|
|
|
|
{
|
|
|
|
$prevPage = $pagesVisible[$i - 1];
|
|
|
|
$subPage = $pagesVisible[$i];
|
|
|
|
if ($subPage - $prevPage == 2)
|
|
|
|
$finalPages []= $subPage - 1;
|
|
|
|
elseif ($subPage - $prevPage > 2)
|
|
|
|
$finalPages []= null;
|
|
|
|
$finalPages []= $subPage;
|
|
|
|
}
|
|
|
|
$pagesVisible = $finalPages;
|
|
|
|
|
|
|
|
if (!function_exists('pageUrl'))
|
|
|
|
{
|
|
|
|
function pageUrl($page)
|
2013-10-16 13:07:01 +02:00
|
|
|
{
|
2014-04-29 21:35:29 +02:00
|
|
|
$context = getContext();
|
|
|
|
$destination = $context->route->destination;
|
Paginator: introducing "..." pseudo-pages
If delta between pages in paginator is greater than 2, it adds "..." inbetween.
If delta is equal to 2, it adds missing page link instead.
Examples:
1,4,5 gets converted to 1,...,4,5
1,3,4 gets converted to 1,2,3,4
2013-11-22 08:52:24 +01:00
|
|
|
$page = max(1, min($context->transport->paginator->pageCount, $page));
|
|
|
|
$params = $context->route->arguments;
|
|
|
|
$params['page'] = $page;
|
2014-04-29 21:35:29 +02:00
|
|
|
return \Chibi\Router::linkTo($destination, $params);
|
2013-10-16 13:07:01 +02:00
|
|
|
}
|
Paginator: introducing "..." pseudo-pages
If delta between pages in paginator is greater than 2, it adds "..." inbetween.
If delta is equal to 2, it adds missing page link instead.
Examples:
1,4,5 gets converted to 1,...,4,5
1,3,4 gets converted to 1,2,3,4
2013-11-22 08:52:24 +01:00
|
|
|
}
|
2013-10-16 13:07:01 +02:00
|
|
|
?>
|
|
|
|
|
|
|
|
<?php if (!empty($pagesVisible)): ?>
|
2014-02-01 11:17:02 +01:00
|
|
|
<?php
|
2014-04-29 21:35:29 +02:00
|
|
|
Assets::addStylesheet('paginator.css');
|
2014-02-01 11:17:02 +01:00
|
|
|
if ($this->context->user->hasEnabledEndlessScrolling())
|
2014-04-29 21:35:29 +02:00
|
|
|
Assets::addScript('paginator-endless.js');
|
2014-02-01 11:17:02 +01:00
|
|
|
?>
|
|
|
|
|
2013-10-16 13:07:01 +02:00
|
|
|
<nav class="paginator-wrapper">
|
|
|
|
<ul class="paginator">
|
Paginator: introducing "..." pseudo-pages
If delta between pages in paginator is greater than 2, it adds "..." inbetween.
If delta is equal to 2, it adds missing page link instead.
Examples:
1,4,5 gets converted to 1,...,4,5
1,3,4 gets converted to 1,2,3,4
2013-11-22 08:52:24 +01:00
|
|
|
<?php if ($page > 1): ?>
|
2013-10-16 13:07:01 +02:00
|
|
|
<li class="prev">
|
|
|
|
<?php else: ?>
|
|
|
|
<li class="prev disabled">
|
|
|
|
<?php endif ?>
|
2014-04-27 14:44:06 +02:00
|
|
|
<a href="<?= pageUrl($page - 1) ?>">
|
2013-10-16 13:07:01 +02:00
|
|
|
«
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
|
Paginator: introducing "..." pseudo-pages
If delta between pages in paginator is greater than 2, it adds "..." inbetween.
If delta is equal to 2, it adds missing page link instead.
Examples:
1,4,5 gets converted to 1,...,4,5
1,3,4 gets converted to 1,2,3,4
2013-11-22 08:52:24 +01:00
|
|
|
<?php foreach ($pagesVisible as $subPage): ?>
|
|
|
|
<?php if ($subPage === null): ?>
|
|
|
|
<li>…</li>
|
2013-10-16 13:07:01 +02:00
|
|
|
<?php else: ?>
|
Paginator: introducing "..." pseudo-pages
If delta between pages in paginator is greater than 2, it adds "..." inbetween.
If delta is equal to 2, it adds missing page link instead.
Examples:
1,4,5 gets converted to 1,...,4,5
1,3,4 gets converted to 1,2,3,4
2013-11-22 08:52:24 +01:00
|
|
|
<?php if ($subPage == $page): ?>
|
|
|
|
<li class="active">
|
|
|
|
<?php else: ?>
|
|
|
|
<li>
|
|
|
|
<?php endif ?>
|
2014-04-27 14:44:06 +02:00
|
|
|
<a href="<?= pageUrl($subPage) ?>">
|
|
|
|
<?= $subPage ?>
|
Paginator: introducing "..." pseudo-pages
If delta between pages in paginator is greater than 2, it adds "..." inbetween.
If delta is equal to 2, it adds missing page link instead.
Examples:
1,4,5 gets converted to 1,...,4,5
1,3,4 gets converted to 1,2,3,4
2013-11-22 08:52:24 +01:00
|
|
|
</a>
|
|
|
|
</li>
|
2013-10-16 13:07:01 +02:00
|
|
|
<?php endif ?>
|
|
|
|
<?php endforeach ?>
|
|
|
|
|
Paginator: introducing "..." pseudo-pages
If delta between pages in paginator is greater than 2, it adds "..." inbetween.
If delta is equal to 2, it adds missing page link instead.
Examples:
1,4,5 gets converted to 1,...,4,5
1,3,4 gets converted to 1,2,3,4
2013-11-22 08:52:24 +01:00
|
|
|
<?php if ($page < $pageCount): ?>
|
2013-10-16 13:07:01 +02:00
|
|
|
<li class="next">
|
|
|
|
<?php else: ?>
|
|
|
|
<li class="next disabled">
|
|
|
|
<?php endif ?>
|
2014-04-27 14:44:06 +02:00
|
|
|
<a href="<?= pageUrl($page + 1) ?>">
|
2013-10-16 13:07:01 +02:00
|
|
|
»
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
<?php endif ?>
|