Новый вариант пагинации - с точками
This commit is contained in:
parent
b23954c800
commit
2b88ddc44a
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
class PageController extends Controller
|
||||
{
|
||||
const elementsByPage = 50;
|
||||
const elementsByPage = 30;
|
||||
|
||||
static function actionPoints()
|
||||
{
|
||||
|
|
@ -46,9 +46,34 @@ class PageController extends Controller
|
|||
$param = array();
|
||||
$param['where'] = '`moderate` = 1';
|
||||
$pointsCount = Point::model()->getCount($param);
|
||||
$pagesCount = ceil($pointsCount/self::elementsByPage);
|
||||
$pagesCount = intval(ceil($pointsCount/self::elementsByPage));
|
||||
$page = isset($_GET['page']) ? abs((int)$_GET['page']) : $pagesCount;
|
||||
|
||||
$pages = array();
|
||||
|
||||
for ($index = $pagesCount; $index > $pagesCount-3; $index--) {
|
||||
$pages[$index] = 1;
|
||||
}
|
||||
|
||||
for ($index = 3; $index > 0; $index--) {
|
||||
$pages[$index] = 1;
|
||||
}
|
||||
|
||||
if ($page > $pagesCount) {
|
||||
$page = $pagesCount;
|
||||
} else if ($page < 1) {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$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'] = 'id DESC';
|
||||
if (App::getParam('category')) {
|
||||
|
|
@ -88,6 +113,7 @@ class PageController extends Controller
|
|||
'pointsCount' => $pointsCount,
|
||||
'page' => $page,
|
||||
'pagesCount' => $pagesCount,
|
||||
'pages' => $pages,
|
||||
'notModeratedPoints' => $notModeratedPoints,
|
||||
'randomPoint' => Point::model()->getRandom(),
|
||||
));
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ if (App::getParam('user')) {
|
|||
App::redirect('/page/points/');
|
||||
}
|
||||
}
|
||||
$oldIndex = $pagesCount+1;
|
||||
?>
|
||||
<div id="pageSmoothBackground" style="background-image: url(<?= $randomPoint->getImg('middle') ?>);"></div>
|
||||
|
||||
|
|
@ -74,9 +75,13 @@ if (App::getParam('user')) {
|
|||
<span aria-hidden="true">«</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php for ($index = $pagesCount; $index > 0; $index--): ?>
|
||||
<?php foreach ($pages as $index => $val): ?>
|
||||
<?php if ($oldIndex-$index != 1):?>
|
||||
<li><a href="?page=<?= $index + ceil(($oldIndex-$index)/2) ?>" style="<?= $index==$page ? 'background-color: #eeeeed;' : '' ?>">...</a></li>
|
||||
<?php endif; ?>
|
||||
<li><a href="?page=<?= $index ?>" style="<?= $index==$page ? 'background-color: #eeeeed;' : '' ?>"><?= $index ?></a></li>
|
||||
<?php endfor; ?>
|
||||
<?php $oldIndex = $index; ?>
|
||||
<?php endforeach; ?>
|
||||
<li class="<?= ($page <= 1) ? 'disabled' : '' ?>">
|
||||
<a href="<?= ($page <= 1) ? '#' : '?page='.($page-1) ?>" aria-label="Next">
|
||||
<span aria-hidden="true">»</span>
|
||||
|
|
|
|||
Loading…
Reference in New Issue