Improved pagination
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
<div class="pagination justify-content-center">
|
||||
<?php if($pagination['maxItems']): ?>
|
||||
<?=$pagination_entity_name?> <?=$pagination['start']+1?> bis <?=($pagination['start'] + $pagination['count'] > $pagination['maxItems']) ? $pagination['maxItems'] : $pagination['start'] + $pagination['count']?> von <?=$pagination['maxItems']?>
|
||||
<?php else: ?>
|
||||
Keine <?=$pagination_entity_name?> gefunden
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php if($pagination['maxItems'] > $pagination['count']): ?>
|
||||
|
||||
<?php
|
||||
$mfPagination_pagecount = intval($pagination['maxItems'] / $pagination['count']);
|
||||
$mfPagination_currentpage = $pagination['start'] / $pagination['count'];
|
||||
$mfPagination_pages = [];
|
||||
$mfPagination_baseurl_params = $pagination_baseurl_params;
|
||||
|
||||
$log = mfLoghandler::singleton();
|
||||
|
||||
if($mfPagination_pagecount < 12) {
|
||||
for($i = 0; $i < $mfPagination_pagecount+1; $i++) {
|
||||
$mfPagination_baseurl_params['s'] = $i * $pagination['count'];
|
||||
$page = [
|
||||
's' => $i * $pagination['count'],
|
||||
'url' => $pagination_baseurl."?".http_build_query($mfPagination_baseurl_params),
|
||||
'current' => ($pagination['start'] == $i*$pagination['count']),
|
||||
];
|
||||
$mfPagination_pages[$i] = $page;
|
||||
}
|
||||
} else {
|
||||
$show_from = $mfPagination_currentpage - 4;
|
||||
$show_to = $mfPagination_currentpage + 4;
|
||||
|
||||
if($show_from < 1) {
|
||||
$show_from = 1;
|
||||
}
|
||||
if($show_to > $mfPagination_pagecount) {
|
||||
$show_to = $mfPagination_pagecount+1;
|
||||
}
|
||||
|
||||
for($i = 0; $i < $mfPagination_pagecount+1; $i++) {
|
||||
if($show_from > 1 && $i == $show_from) {
|
||||
$mfPagination_pages[$i] = "separator_before";
|
||||
continue;
|
||||
}
|
||||
if($i == $show_to && $show_to < $mfPagination_pagecount) {
|
||||
$mfPagination_pages[$i] = "separator_after";
|
||||
continue;
|
||||
}
|
||||
|
||||
$mfPagination_baseurl_params['s'] = $i * $pagination['count'];
|
||||
|
||||
if(($i == 0 || $i == $mfPagination_pagecount) || ($i >= $show_from && $i <= $show_to)) {
|
||||
$log->debug("show_from: $show_from, show_to: $show_to");
|
||||
|
||||
$page = [
|
||||
's' => $i * $pagination['count'],
|
||||
'url' => $pagination_baseurl."?".http_build_query($mfPagination_baseurl_params),
|
||||
'current' => ($pagination['start'] == $i*$pagination['count']),
|
||||
];
|
||||
$mfPagination_pages[$i] = $page;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="alert alert-warning">
|
||||
pagecount: <?php var_dump($mfPagination_pagecount); ?>
|
||||
currentpage: <?php var_dump($mfPagination_currentpage); ?>
|
||||
<?php var_dump($mfPagination_pages); ?>
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center mb-1">
|
||||
<li class="page-item <?=($pagination['start'] - $pagination['count'] < 0) ? "disabled" : ""?>">
|
||||
<a class="page-link" href="<?=$this->getUrl($Mod, "Index", ["filter" => $filter])?>" tabindex="-1">Erste</a>
|
||||
</li>
|
||||
<li class="page-item <?=($pagination['start'] - $pagination['count'] < 0) ? "disabled" : ""?>">
|
||||
<a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $pagination['start'] - $pagination['count'], "filter" => $filter])?>" tabindex="-1">Zurück</a>
|
||||
</li>
|
||||
<?php foreach($mfPagination_pages as $mfPageIndex => $mfPage):?>
|
||||
<?php if($mfPage == "separator_before" || $mfPage == "separator_after"): ?>
|
||||
<li class="page-item disabled font-weight-bold text-secondary"><a class="page-link">...</a></li>
|
||||
<?php continue; endif; ?>
|
||||
<li class="page-item <?=($mfPage['current']) ? "disabled font-weight-bold text-secondary" : ""?>"><a class="page-link" href="<?=$mfPage['url']?>"><?=$mfPageIndex+1?></a></li>
|
||||
<?php endforeach; ?>
|
||||
<li class="page-item <?=($pagination['maxItems'] / ($pagination['start'] + $pagination['count']) < 1) ? "disabled" : ""?>">
|
||||
<a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $pagination['start'] + $pagination['count'], "filter" => $filter])?>">Weiter</a>
|
||||
</li>
|
||||
<li class="page-item <?=($pagination['maxItems'] / ($pagination['start'] + $pagination['count']) < 1) ? "disabled" : ""?>">
|
||||
<a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => ($pagination['maxItems'] - $pagination['maxItems'] % $pagination['count']), "filter" => $filter])?>">Letzte</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<?php endif; ?>
|
||||
Reference in New Issue
Block a user