Добавил пагинацию на страницы точек по категориям и по пользователю

This commit is contained in:
Krivchikov Dmitry 2016-02-23 23:30:57 +03:00
parent 10e5a941ef
commit 36c22549e7
2 changed files with 25 additions and 22 deletions

View File

@ -41,7 +41,16 @@ class PageController extends Controller
// ------------------------------------------
$param = array();
$param['order'] = '`ord` ASC';
if (App::getParam('category')) {
$param['where'] = 'categoryId = ' . (int) App::getParam('category') . ' AND `status` = "published"';
} else if (App::getParam('user')) {
$param['where'] = '`author` = ' . (int) App::getParam('user') . ' AND `status` = "published"';
} else {
$param['where'] = '`status` = "published" AND `categoryId` NOT IN ('. implode(',', Category::$paidIds).')';
}
$pointsCount = Point::model()->getCount($param);
$pagesCount = intval(ceil($pointsCount/self::elementsByPage));
$fullPagesCount = intval(floor($pointsCount/self::elementsByPage));
@ -55,13 +64,17 @@ class PageController extends Controller
$pages = array();
for ($index = $pagesCount; $index > $pagesCount-3; $index--) {
// Заполняем страницы от большей к меньшей - добавляем 3 штуки
for ($index = $pagesCount; (($index > $pagesCount-3) && ($index > 0)); $index--) {
$pages[$index] = 1;
}
// Заполняем страницы от 3 к 1 - добавляем 3 штуки
if ($pagesCount >= 3) {
for ($index = 3; $index > 0; $index--) {
$pages[$index] = 1;
}
}
if ($page > $pagesCount) {
$page = $pagesCount;
@ -69,24 +82,15 @@ class PageController extends Controller
$page = 1;
}
// Заполняем страницы вокруг текущей. +/- 2 штуки.
$topIndex = ($page+2 > $pagesCount) ? $pagesCount : $page+2;
$bottomIndex = ($page-3 < 1) ? 1 : $page-3;
for ($index = $topIndex; $index > $bottomIndex; $index--) {
$pages[$index] = 1;
}
krsort($pages);
$param = array();
$param['order'] = '`ord` ASC';
if (App::getParam('category')) {
$param['where'] = 'categoryId = ' . (int) App::getParam('category') . ' AND `status` = "published"';
} else if (App::getParam('user')) {
$param['where'] = '`author` = ' . (int) App::getParam('user') . ' AND `status` = "published"';
} else {
$param['where'] = '`status` = "published" AND `categoryId` NOT IN ('. implode(',', Category::$paidIds).')';
if ($page == $pagesCount && $residue < self::minElementsByPage) {
$param['limit'] = self::elementsByPage + $residue;
} else {
@ -96,7 +100,6 @@ class PageController extends Controller
if($page) {
$param['offset'] = self::elementsByPage * ($page - 1);
}
}
$points = Point::model()->getAll($param);
$points = array_reverse($points);

View File

@ -67,7 +67,7 @@ $oldIndex = $pagesCount+1;
</div>
</div>
</div>
<?php if (!(int) App::getParam('category') && !(int) App::getParam('user')):?>
<?php if ($pagesCount > 1):?>
<nav>
<ul class="pagination">
<li class="<?= ($page >= $pagesCount) ? 'disabled' : '' ?>">