Добавил пагинацию на страницы точек по категориям и по пользователю
This commit is contained in:
parent
10e5a941ef
commit
36c22549e7
|
|
@ -41,7 +41,16 @@ class PageController extends Controller
|
|||
// ------------------------------------------
|
||||
|
||||
$param = array();
|
||||
$param['where'] = '`status` = "published" AND `categoryId` NOT IN ('. implode(',', Category::$paidIds).')';
|
||||
$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,12 +64,16 @@ 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;
|
||||
}
|
||||
|
||||
for ($index = 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) {
|
||||
|
|
@ -69,33 +82,23 @@ 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"';
|
||||
if ($page == $pagesCount && $residue < self::minElementsByPage) {
|
||||
$param['limit'] = self::elementsByPage + $residue;
|
||||
} else {
|
||||
$param['where'] = '`status` = "published" AND `categoryId` NOT IN ('. implode(',', Category::$paidIds).')';
|
||||
$param['limit'] = self::elementsByPage;
|
||||
}
|
||||
|
||||
if ($page == $pagesCount && $residue < self::minElementsByPage) {
|
||||
$param['limit'] = self::elementsByPage + $residue;
|
||||
} else {
|
||||
$param['limit'] = self::elementsByPage;
|
||||
}
|
||||
|
||||
if($page) {
|
||||
$param['offset'] = self::elementsByPage * ($page - 1);
|
||||
}
|
||||
if($page) {
|
||||
$param['offset'] = self::elementsByPage * ($page - 1);
|
||||
}
|
||||
|
||||
$points = Point::model()->getAll($param);
|
||||
|
|
|
|||
|
|
@ -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' : '' ?>">
|
||||
|
|
|
|||
Loading…
Reference in New Issue