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;
}