feature/RVRNEXT-22-add-pagination-template #56
31
views/templates/pagination.php
Normal file
31
views/templates/pagination.php
Normal file
@ -0,0 +1,31 @@
|
||||
<p class="paginateContainer marginTop">
|
||||
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => 1])) ?>">«</a>
|
||||
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => max(1, $currentPage - 1)])) ?>">‹</a>
|
||||
<?php
|
||||
$maxPages = 7;
|
||||
if ($pages <= $maxPages) {
|
||||
$start = 1;
|
||||
$end = $pages;
|
||||
} else {
|
||||
$maxAdditionalPages = $maxPages - 1;
|
||||
$maxAdditionalPagesHalf = ceil($maxAdditionalPages / 2);
|
||||
$start = $currentPage - $maxAdditionalPagesHalf > 1 ?
|
||||
($currentPage - $maxAdditionalPagesHalf < $pages - $maxAdditionalPages ?
|
||||
$currentPage - $maxAdditionalPagesHalf :
|
||||
$pages - $maxAdditionalPages) :
|
||||
1;
|
||||
$end = $start + $maxAdditionalPages < $pages ?
|
||||
$start + $maxAdditionalPages :
|
||||
$pages;
|
||||
}
|
||||
?>
|
||||
<?php for ($i = $start; $i <= $end; $i++): ?>
|
||||
<?php if ($currentPage == $i): ?>
|
||||
<span class="selected"><?= $i ?></span>
|
||||
<?php else: ?>
|
||||
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => $i])) ?>"><?= $i ?></a>
|
||||
<?php endif; ?>
|
||||
<?php endfor; ?>
|
||||
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => min($pages, $currentPage + 1)])) ?>">›</a>
|
||||
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => $pages])) ?>">»</a>
|
||||
</p>
|
Loading…
Reference in New Issue
Block a user