Merge pull request #734 from kavin-90/master

add bootstrap pagination code with gap+numbers xD
This commit is contained in:
Diego Najar 2018-08-06 19:21:07 +03:00 committed by GitHub
commit bb2023cb5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 54 additions and 0 deletions

View File

@ -140,5 +140,59 @@ class Paginator {
return $html;
}
/*
* Bootstrap Pagination
*/
public static function bootstrap_html($textPrevPage=false, $textNextPage=false, $showPageNumber=false){
global $Language;
$total_pages = self::amountOfPages();
$howMany = 2;
$currentPage = self::currentPage();
$first_page = self::firstPage();
$last_page = self::lastPageUrl();
$show_next = (self::showNext()) ? "" : "disabled";
$show_previois = (self::showPrev()) ? "" : "disabled";
$html = '<nav aria-label="Page navigation">';
$html .= '<ul class="pagination">';
if ($currentPage > 3 || $currentPage === $total_pages){
$html .= '<li class="page-item">';
$html .= '<a class="page-link" href="'.self::firstPageUrl().'" aria-label="First"><span aria-hidden="true">&laquo;</span> '.$Language->get('First').'</a>';
$html .= '</li>';
}
if ($currentPage > 1){
$html .= '<li class="page-item'.$show_previois.'">';
$html .= '<a class="page-link" href="'.self::prevPageUrl().'" aria-label="Previous"><span aria-hidden="true">&laquo;</span> '.$Language->get('Previous').'</a>';
$html .= '</li>';
}
if ($currentPage > $howMany + 1){
$html .= '<li class="page-item disabled"><span>...</span></li>';
}
for ($pageIndex = $currentPage - $howMany; $pageIndex <= $currentPage + $howMany; $pageIndex++){
$active = ($pageIndex==self::currentPage()) ? "active" : false;
if ($pageIndex >= 1 && $pageIndex <= $total_pages){
$html .= '<li class ="'.$active.'"><a href="'.self::numberUrl($pageIndex).'">'.$pageIndex.'</a></li>';
}
}
if ($currentPage < $total_pages){
$html .= '<li class="page-item disabled"><span>...</span></li>';
}
if ($currentPage < $total_pages){
$html .= '<li class="page-item'.$show_next.'">';
$html .= '<a class="page-link" href="'.self::nextPageUrl().'" aria-label="Next">'.$Language->get('Next').' <span aria-hidden="true">&raquo;</span></a>';
$html .= '</li>';
$html .= '<li><a href="'.$last_page.'">'.$Language->get('Last').'</a></li>';
}
$html .= '</ul>';
$html .= '</nav>';
return $html;
}
}