refactor paginator, introducing new variable $PREV, $NEXT and $END. By

default, 10 pages are display. you can use numPage for managing how many
page are display
This commit is contained in:
Manuel Raynaud
2014-03-03 11:30:40 +01:00
parent 19121c607a
commit c7323d1c5b
3 changed files with 33 additions and 15 deletions

View File

@@ -241,7 +241,7 @@ class TheliaLoop extends AbstractSmartyPlugin
// Find pagination
$pagination = self::getPagination($loopName);
if ($pagination === null) { // loop gas no result
if ($pagination === null) { // loop has no result
return '';
}
@@ -250,17 +250,33 @@ class TheliaLoop extends AbstractSmartyPlugin
return '';
}
$nbPage = $this->getParam($params, 'numPage', 10);
$maxPage = $pagination->getLastPage();
if ($content === null) {
$page = 1;
$page = $pagination->getPage();
if($maxPage > ($page + $nbPage)) {
$end = $page + $nbPage;
} else {
$end = $maxPage;
}
$template->assign('PREV', $page > 1 ? $page-1: $page);
$template->assign('NEXT', $page < $maxPage ? $page+1 : $maxPage);
$template->assign('END', $end);
$template->assign('LAST', $pagination->getLastPage());
} else {
$page = $template->getTemplateVars('PAGE');
$page++;
}
if ($page <= $pagination->getLastPage()) {
if ($page <= $template->getTemplateVars('END')) {
$template->assign('PAGE', $page);
$template->assign('CURRENT', $pagination->getPage());
$template->assign('LAST', $pagination->getLastPage());
$repeat = true;
}

View File

@@ -182,13 +182,15 @@
<div class="text-center">
<ul class="pagination pagination-centered">
{if $page != 1}
<li><a href="{url path="/admin/customers" page="1"}">&laquo;</a></li>
{else}
<li class="disabled"><a href="#">&laquo;</a></li>
{if $page != 1}
<li><a href="{url path="/admin/customers" page="1"}">&laquo;</a></li>
{/if}
{pageloop rel="customer_list" numPage="20"}
{if $PAGE == $CURRENT && $PAGE > 2}
<li><a href="{url path="/admin/customers" page=$PREV}">&lsaquo;</a></li>
{/if}
{pageloop rel="customer_list"}
{if $PAGE != $CURRENT}
<li><a href="{url path="/admin/customers" page="{$PAGE}"}">{$PAGE}</a></li>
@@ -196,12 +198,12 @@
<li class="active"><a href="#">{$PAGE}</a></li>
{/if}
{if $PAGE == $END && $PAGE < $LAST}
<li><a href="{url path="/admin/customers" page=$NEXT}">&rsaquo;</a></li>
{/if}
{/pageloop}
{if $PAGE == $LAST && $LAST != $CURRENT}
<li><a href="{url path="/admin/customers" page="$PAGE"}">&raquo;</a></li>
{else}
<li class="disabled"><a href="#">&raquo;</a></li>
{if $LAST > $CURRENT}
<li><a href="{url path="/admin/customers" page="$LAST"}">&raquo;</a></li>
{/if}
</ul>
</div>

View File

@@ -91,7 +91,7 @@
{pageloop rel="product_list"}
<li{if $PAGE eq $CURRENT} class="active"{/if}><a href="{url path={navigate to="current"} page=$PAGE }"> {$PAGE} </a></li>
{if $PAGE eq $LAST}
<li{if $CURRENT eq $LAST} class="disabled"{/if}><a href="{url path={navigate to="current"} page={$CURRENT+1} }" title="{intl l="Next"}" class="next"><i class="icon-next"></i></a></li>
<li{if $CURRENT eq $LAST} class="disabled"{/if}><a href="{url path={navigate to="current"} page={$NEXT} }" title="{intl l="Next"}" class="next"><i class="icon-next"></i></a></li>
{/if}
{/pageloop}
</ul>