-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #20175: Fix bad result for pagination when used with GridView
- Loading branch information
Showing
19 changed files
with
64 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,6 @@ | |
|
||
namespace yii\base; | ||
|
||
use Yii; | ||
|
||
/** | ||
* ErrorException represents a PHP error. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
|
||
namespace yii\base; | ||
|
||
use Yii; | ||
use yii\helpers\StringHelper; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
namespace yii\data; | ||
|
||
use Closure; | ||
use Yii; | ||
use yii\base\BaseObject; | ||
use yii\web\Link; | ||
|
@@ -69,6 +70,7 @@ | |
* @property-read int $pageCount Number of pages. | ||
* @property int $pageSize The number of items per page. If it is less than 1, it means the page size is | ||
* infinite, and thus a single page contains all items. | ||
* @property int $totalCount total number of items. | ||
* | ||
* @author Qiang Xue <[email protected]> | ||
* @since 2.0 | ||
|
@@ -123,10 +125,6 @@ class Pagination extends BaseObject implements Linkable | |
* number validation. By doing so, [[page]] will return the value indexed by [[pageParam]] in [[params]]. | ||
*/ | ||
public $validatePage = true; | ||
/** | ||
* @var int total number of items. | ||
*/ | ||
public $totalCount = 0; | ||
/** | ||
* @var int the default page size. This property will be returned by [[pageSize]] when page size | ||
* cannot be determined by [[pageSizeParam]] from [[params]]. | ||
|
@@ -143,6 +141,10 @@ class Pagination extends BaseObject implements Linkable | |
* If it is less than 1, it means the page size is infinite, and thus a single page contains all items. | ||
*/ | ||
private $_pageSize; | ||
/** | ||
* @var Closure|int total number of items or closure returning it. | ||
*/ | ||
private $_totalCount = 0; | ||
|
||
|
||
/** | ||
|
@@ -151,13 +153,11 @@ class Pagination extends BaseObject implements Linkable | |
public function getPageCount() | ||
{ | ||
$pageSize = $this->getPageSize(); | ||
$totalCount = $this->getTotalCount(); | ||
if ($pageSize < 1) { | ||
return $this->totalCount > 0 ? 1 : 0; | ||
return $totalCount > 0 ? 1 : 0; | ||
} | ||
|
||
$totalCount = $this->totalCount < 0 ? 0 : (int) $this->totalCount; | ||
|
||
return (int) (($totalCount + $pageSize - 1) / $pageSize); | ||
return (int) ((max($totalCount, 0) + $pageSize - 1) / $pageSize); | ||
} | ||
|
||
private $_page; | ||
|
@@ -173,7 +173,6 @@ public function getPage($recalculate = false) | |
$page = (int) $this->getQueryParam($this->pageParam, 1) - 1; | ||
$this->setPage($page, true); | ||
} | ||
|
||
return $this->_page; | ||
} | ||
|
||
|
@@ -221,7 +220,6 @@ public function getPageSize() | |
$this->setPageSize($pageSize, true); | ||
} | ||
} | ||
|
||
return $this->_pageSize; | ||
} | ||
|
||
|
@@ -264,7 +262,7 @@ public function createUrl($page, $pageSize = null, $absolute = false) | |
$request = Yii::$app->getRequest(); | ||
$params = $request instanceof Request ? $request->getQueryParams() : []; | ||
} | ||
if ($page > 0 || $page == 0 && $this->forcePageParam) { | ||
if ($page > 0 || ($page === 0 && $this->forcePageParam)) { | ||
$params[$this->pageParam] = $page + 1; | ||
} else { | ||
unset($params[$this->pageParam]); | ||
|
@@ -282,7 +280,6 @@ public function createUrl($page, $pageSize = null, $absolute = false) | |
if ($absolute) { | ||
return $urlManager->createAbsoluteUrl($params); | ||
} | ||
|
||
return $urlManager->createUrl($params); | ||
} | ||
|
||
|
@@ -293,7 +290,6 @@ public function createUrl($page, $pageSize = null, $absolute = false) | |
public function getOffset() | ||
{ | ||
$pageSize = $this->getPageSize(); | ||
|
||
return $pageSize < 1 ? 0 : $this->getPage() * $pageSize; | ||
} | ||
|
||
|
@@ -305,7 +301,6 @@ public function getOffset() | |
public function getLimit() | ||
{ | ||
$pageSize = $this->getPageSize(); | ||
|
||
return $pageSize < 1 ? -1 : $pageSize; | ||
} | ||
|
||
|
@@ -331,7 +326,6 @@ public function getLinks($absolute = false) | |
$links[self::LINK_NEXT] = $this->createUrl($currentPage + 1, null, $absolute); | ||
} | ||
} | ||
|
||
return $links; | ||
} | ||
|
||
|
@@ -348,7 +342,25 @@ protected function getQueryParam($name, $defaultValue = null) | |
$request = Yii::$app->getRequest(); | ||
$params = $request instanceof Request ? $request->getQueryParams() : []; | ||
} | ||
|
||
return isset($params[$name]) && is_scalar($params[$name]) ? $params[$name] : $defaultValue; | ||
} | ||
|
||
/** | ||
* @return int total number of items. | ||
*/ | ||
public function getTotalCount() | ||
{ | ||
if (is_numeric($this->_totalCount)) { | ||
return (int)$this->_totalCount; | ||
} | ||
return (int)call_user_func($this->_totalCount); | ||
} | ||
|
||
/** | ||
* @param Closure|int $count | ||
*/ | ||
public function setTotalCount($count) | ||
{ | ||
$this->_totalCount = $count; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
|
||
namespace yii\db; | ||
|
||
use Yii; | ||
use yii\base\BaseObject; | ||
use yii\helpers\StringHelper; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
|
||
namespace yii\log; | ||
|
||
use Yii; | ||
use yii\base\Component; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
|
||
namespace yii\log; | ||
|
||
use Yii; | ||
use yii\helpers\VarDumper; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
|
||
namespace yii\rbac; | ||
|
||
use Yii; | ||
use yii\base\BaseObject; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
|
||
namespace yii\web; | ||
|
||
use Yii; | ||
use yii\caching\CacheInterface; | ||
use yii\di\Instance; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
|
||
namespace yii\web; | ||
|
||
use Yii; | ||
use yii\base\BaseObject; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters