Добавил пагинацию на страницы точек по категориям и по пользователю
This commit is contained in:
parent
10e5a941ef
commit
36c22549e7
|
|
@ -41,7 +41,16 @@ class PageController extends Controller
|
||||||
// ------------------------------------------
|
// ------------------------------------------
|
||||||
|
|
||||||
$param = array();
|
$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).')';
|
$param['where'] = '`status` = "published" AND `categoryId` NOT IN ('. implode(',', Category::$paidIds).')';
|
||||||
|
}
|
||||||
|
|
||||||
$pointsCount = Point::model()->getCount($param);
|
$pointsCount = Point::model()->getCount($param);
|
||||||
$pagesCount = intval(ceil($pointsCount/self::elementsByPage));
|
$pagesCount = intval(ceil($pointsCount/self::elementsByPage));
|
||||||
$fullPagesCount = intval(floor($pointsCount/self::elementsByPage));
|
$fullPagesCount = intval(floor($pointsCount/self::elementsByPage));
|
||||||
|
|
@ -55,13 +64,17 @@ class PageController extends Controller
|
||||||
|
|
||||||
$pages = array();
|
$pages = array();
|
||||||
|
|
||||||
for ($index = $pagesCount; $index > $pagesCount-3; $index--) {
|
// Заполняем страницы от большей к меньшей - добавляем 3 штуки
|
||||||
|
for ($index = $pagesCount; (($index > $pagesCount-3) && ($index > 0)); $index--) {
|
||||||
$pages[$index] = 1;
|
$pages[$index] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Заполняем страницы от 3 к 1 - добавляем 3 штуки
|
||||||
|
if ($pagesCount >= 3) {
|
||||||
for ($index = 3; $index > 0; $index--) {
|
for ($index = 3; $index > 0; $index--) {
|
||||||
$pages[$index] = 1;
|
$pages[$index] = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($page > $pagesCount) {
|
if ($page > $pagesCount) {
|
||||||
$page = $pagesCount;
|
$page = $pagesCount;
|
||||||
|
|
@ -69,24 +82,15 @@ class PageController extends Controller
|
||||||
$page = 1;
|
$page = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Заполняем страницы вокруг текущей. +/- 2 штуки.
|
||||||
$topIndex = ($page+2 > $pagesCount) ? $pagesCount : $page+2;
|
$topIndex = ($page+2 > $pagesCount) ? $pagesCount : $page+2;
|
||||||
$bottomIndex = ($page-3 < 1) ? 1 : $page-3;
|
$bottomIndex = ($page-3 < 1) ? 1 : $page-3;
|
||||||
|
|
||||||
for ($index = $topIndex; $index > $bottomIndex; $index--) {
|
for ($index = $topIndex; $index > $bottomIndex; $index--) {
|
||||||
$pages[$index] = 1;
|
$pages[$index] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
krsort($pages);
|
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) {
|
if ($page == $pagesCount && $residue < self::minElementsByPage) {
|
||||||
$param['limit'] = self::elementsByPage + $residue;
|
$param['limit'] = self::elementsByPage + $residue;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -96,7 +100,6 @@ class PageController extends Controller
|
||||||
if($page) {
|
if($page) {
|
||||||
$param['offset'] = self::elementsByPage * ($page - 1);
|
$param['offset'] = self::elementsByPage * ($page - 1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$points = Point::model()->getAll($param);
|
$points = Point::model()->getAll($param);
|
||||||
$points = array_reverse($points);
|
$points = array_reverse($points);
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ $oldIndex = $pagesCount+1;
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php if (!(int) App::getParam('category') && !(int) App::getParam('user')):?>
|
<?php if ($pagesCount > 1):?>
|
||||||
<nav>
|
<nav>
|
||||||
<ul class="pagination">
|
<ul class="pagination">
|
||||||
<li class="<?= ($page >= $pagesCount) ? 'disabled' : '' ?>">
|
<li class="<?= ($page >= $pagesCount) ? 'disabled' : '' ?>">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue