FIX paginator
This commit is contained in:
parent
bbb150c5b4
commit
5b2247aa88
|
|
@ -3,6 +3,7 @@
|
||||||
class PageController extends Controller
|
class PageController extends Controller
|
||||||
{
|
{
|
||||||
const elementsByPage = 30;
|
const elementsByPage = 30;
|
||||||
|
const minElementsByPage = 10;
|
||||||
|
|
||||||
static function actionPoints()
|
static function actionPoints()
|
||||||
{
|
{
|
||||||
|
|
@ -47,6 +48,13 @@ class PageController extends Controller
|
||||||
$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));
|
||||||
|
$residue = $pointsCount - ($fullPagesCount * self::elementsByPage);
|
||||||
|
|
||||||
|
if ($residue < self::minElementsByPage) {
|
||||||
|
$pagesCount = $fullPagesCount;
|
||||||
|
}
|
||||||
|
|
||||||
$page = isset($_GET['page']) ? abs((int)$_GET['page']) : $pagesCount;
|
$page = isset($_GET['page']) ? abs((int)$_GET['page']) : $pagesCount;
|
||||||
|
|
||||||
$pages = array();
|
$pages = array();
|
||||||
|
|
@ -75,20 +83,27 @@ class PageController extends Controller
|
||||||
krsort($pages);
|
krsort($pages);
|
||||||
|
|
||||||
$param = array();
|
$param = array();
|
||||||
$param['order'] = '`ord` DESC';
|
$param['order'] = '`ord` ASC';
|
||||||
if (App::getParam('category')) {
|
if (App::getParam('category')) {
|
||||||
$param['where'] = 'categoryId = ' . (int) App::getParam('category') . ' AND `status` = "published"';
|
$param['where'] = 'categoryId = ' . (int) App::getParam('category') . ' AND `status` = "published"';
|
||||||
} else if (App::getParam('user')) {
|
} else if (App::getParam('user')) {
|
||||||
$param['where'] = '`author` = ' . (int) App::getParam('user') . ' AND `status` = "published"';
|
$param['where'] = '`author` = ' . (int) App::getParam('user') . ' AND `status` = "published"';
|
||||||
} else {
|
} else {
|
||||||
$param['where'] = '`status` = "published" AND `categoryId` NOT IN ('. implode(',', Category::$paidIds).')';
|
$param['where'] = '`status` = "published" AND `categoryId` NOT IN ('. implode(',', Category::$paidIds).')';
|
||||||
|
|
||||||
|
if ($page == $pagesCount && $residue < self::minElementsByPage) {
|
||||||
|
$param['limit'] = self::elementsByPage + $residue;
|
||||||
|
} else {
|
||||||
$param['limit'] = self::elementsByPage;
|
$param['limit'] = self::elementsByPage;
|
||||||
|
}
|
||||||
|
|
||||||
if($page) {
|
if($page) {
|
||||||
$param['offset'] = self::elementsByPage * ($pagesCount - $page);
|
$param['offset'] = self::elementsByPage * ($page - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$points = Point::model()->getAll($param);
|
$points = Point::model()->getAll($param);
|
||||||
|
$points = array_reverse($points);
|
||||||
$categories = Category::model()->getAll(array('order' => 'ord ASC'));
|
$categories = Category::model()->getAll(array('order' => 'ord ASC'));
|
||||||
|
|
||||||
$result = array();
|
$result = array();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue