mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-18 23:43:19 +08:00
method renaming.
This commit is contained in:
@@ -53,7 +53,7 @@ use yii\db\Connection;
|
||||
class ActiveDataProvider extends DataProvider
|
||||
{
|
||||
/**
|
||||
* @var Query the query that is used to fetch data items and [[totalItemCount]]
|
||||
* @var Query the query that is used to fetch data items and [[totalCount]]
|
||||
* if it is not explicitly set.
|
||||
*/
|
||||
public $query;
|
||||
@@ -98,29 +98,29 @@ class ActiveDataProvider extends DataProvider
|
||||
/**
|
||||
* Returns the number of data items in the current page.
|
||||
* This is equivalent to `count($provider->items)`.
|
||||
* When [[pagination]] is false, this is the same as [[totalItemCount]].
|
||||
* When [[pagination]] is false, this is the same as [[totalCount]].
|
||||
* @param boolean $refresh whether to recalculate the item count. If true,
|
||||
* this will cause re-fetching of [[items]].
|
||||
* @return integer the number of data items in the current page.
|
||||
*/
|
||||
public function getItemCount($refresh = false)
|
||||
public function getCount($refresh = false)
|
||||
{
|
||||
return count($this->getItems($refresh));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total number of data items.
|
||||
* When [[pagination]] is false, this returns the same value as [[itemCount]].
|
||||
* If [[totalItemCount]] is not explicitly set, it will be calculated
|
||||
* When [[pagination]] is false, this returns the same value as [[count]].
|
||||
* If [[totalCount]] is not explicitly set, it will be calculated
|
||||
* using [[query]] with a COUNT query.
|
||||
* @param boolean $refresh whether to recalculate the item count
|
||||
* @return integer total number of possible data items.
|
||||
* @throws InvalidConfigException
|
||||
*/
|
||||
public function getTotalItemCount($refresh = false)
|
||||
public function getTotalCount($refresh = false)
|
||||
{
|
||||
if ($this->getPagination() === false) {
|
||||
return $this->getItemCount($refresh);
|
||||
return $this->getCount($refresh);
|
||||
} elseif ($this->_count === null || $refresh) {
|
||||
if (!$this->query instanceof Query) {
|
||||
throw new InvalidConfigException('The "query" property must be an instance of Query or its subclass.');
|
||||
@@ -135,7 +135,7 @@ class ActiveDataProvider extends DataProvider
|
||||
* Sets the total number of data items.
|
||||
* @param integer $value the total number of data items.
|
||||
*/
|
||||
public function setTotalItemCount($value)
|
||||
public function setTotalCount($value)
|
||||
{
|
||||
$this->_count = $value;
|
||||
}
|
||||
@@ -153,7 +153,7 @@ class ActiveDataProvider extends DataProvider
|
||||
throw new InvalidConfigException('The "query" property must be an instance of Query or its subclass.');
|
||||
}
|
||||
if (($pagination = $this->getPagination()) !== false) {
|
||||
$pagination->itemCount = $this->getTotalItemCount();
|
||||
$pagination->totalCount = $this->getTotalCount();
|
||||
$this->query->limit($pagination->getLimit())->offset($pagination->getOffset());
|
||||
}
|
||||
if (($sort = $this->getSort()) !== false) {
|
||||
|
||||
@@ -67,34 +67,34 @@ class ArrayDataProvider extends DataProvider
|
||||
*/
|
||||
public $allItems;
|
||||
|
||||
private $_count;
|
||||
private $_totalCount;
|
||||
|
||||
/**
|
||||
* Returns the total number of data items.
|
||||
* @return integer total number of possible data items.
|
||||
* @throws InvalidConfigException
|
||||
*/
|
||||
public function getTotalItemCount()
|
||||
public function getTotalCount()
|
||||
{
|
||||
if ($this->getPagination() === false) {
|
||||
return $this->getItemCount();
|
||||
} elseif ($this->_count === null) {
|
||||
return $this->getCount();
|
||||
} elseif ($this->_totalCount === null) {
|
||||
if ($this->allItems !== null) {
|
||||
$this->_count = count($this->allItems);
|
||||
$this->_totalCount = count($this->allItems);
|
||||
} else {
|
||||
throw new InvalidConfigException('Unable to determine total item count: either "allItems" or "totalItemCount" must be set.');
|
||||
throw new InvalidConfigException('Unable to determine total item count: either "allItems" or "totalCount" must be set.');
|
||||
}
|
||||
}
|
||||
return $this->_count;
|
||||
return $this->_totalCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the total number of data items.
|
||||
* @param integer $value the total number of data items.
|
||||
*/
|
||||
public function setTotalItemCount($value)
|
||||
public function setTotalCount($value)
|
||||
{
|
||||
$this->_count = $value;
|
||||
$this->_totalCount = $value;
|
||||
}
|
||||
|
||||
private $_items;
|
||||
@@ -116,7 +116,7 @@ class ArrayDataProvider extends DataProvider
|
||||
}
|
||||
|
||||
if (($pagination = $this->getPagination()) !== false) {
|
||||
$pagination->itemCount = $this->getTotalItemCount();
|
||||
$pagination->totalCount = $this->getTotalCount();
|
||||
$items = array_slice($items, $pagination->getOffset(), $pagination->getLimit());
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ abstract class DataProvider extends Component implements IDataProvider
|
||||
* Returns the number of data items in the current page.
|
||||
* @return integer the number of data items in the current page.
|
||||
*/
|
||||
public function getItemCount()
|
||||
public function getCount()
|
||||
{
|
||||
return count($this->getItems());
|
||||
}
|
||||
|
||||
@@ -22,17 +22,17 @@ interface IDataProvider
|
||||
/**
|
||||
* Returns the number of data items in the current page.
|
||||
* This is equivalent to `count($provider->getItems())`.
|
||||
* When [[pagination]] is false, this is the same as [[totalItemCount]].
|
||||
* When [[pagination]] is false, this is the same as [[totalCount]].
|
||||
* @return integer the number of data items in the current page.
|
||||
*/
|
||||
public function getItemCount();
|
||||
public function getCount();
|
||||
|
||||
/**
|
||||
* Returns the total number of data items.
|
||||
* When [[pagination]] is false, this is the same as [[itemCount]].
|
||||
* When [[pagination]] is false, this is the same as [[count]].
|
||||
* @return integer total number of possible data items.
|
||||
*/
|
||||
public function getTotalItemCount();
|
||||
public function getTotalCount();
|
||||
|
||||
/**
|
||||
* Returns the data items in the current page.
|
||||
|
||||
@@ -14,7 +14,7 @@ use yii\base\Object;
|
||||
* Pagination represents information relevant to pagination of data items.
|
||||
*
|
||||
* When data needs to be rendered in multiple pages, Pagination can be used to
|
||||
* represent information such as [[itemCount|total item count]], [[pageSize|page size]],
|
||||
* represent information such as [[totalCount|total item count]], [[pageSize|page size]],
|
||||
* [[page|current page]], etc. These information can be passed to [[yii\widgets\Pager|pagers]]
|
||||
* to render pagination buttons or links.
|
||||
*
|
||||
@@ -28,7 +28,7 @@ use yii\base\Object;
|
||||
* {
|
||||
* $query = Article::find()->where(array('status' => 1));
|
||||
* $countQuery = clone $query;
|
||||
* $pages = new Pagination(array('itemCount' => $countQuery->count()));
|
||||
* $pages = new Pagination(array('totalCount' => $countQuery->count()));
|
||||
* $models = $query->offset($pages->offset)
|
||||
* ->limit($pages->limit)
|
||||
* ->all();
|
||||
@@ -91,7 +91,7 @@ class Pagination extends Object
|
||||
/**
|
||||
* @var boolean whether to check if [[page]] is within valid range.
|
||||
* When this property is true, the value of [[page]] will always be between 0 and ([[pageCount]]-1).
|
||||
* Because [[pageCount]] relies on the correct value of [[itemCount]] which may not be available
|
||||
* Because [[pageCount]] relies on the correct value of [[totalCount]] which may not be available
|
||||
* in some cases (e.g. MongoDB), you may want to set this property to be false to disable the page
|
||||
* number validation. By doing so, [[page]] will return the value indexed by [[pageVar]] in [[params]].
|
||||
*/
|
||||
@@ -104,7 +104,7 @@ class Pagination extends Object
|
||||
/**
|
||||
* @var integer total number of items.
|
||||
*/
|
||||
public $itemCount = 0;
|
||||
public $totalCount = 0;
|
||||
|
||||
|
||||
/**
|
||||
@@ -113,10 +113,10 @@ class Pagination extends Object
|
||||
public function getPageCount()
|
||||
{
|
||||
if ($this->pageSize < 1) {
|
||||
return $this->itemCount > 0 ? 1 : 0;
|
||||
return $this->totalCount > 0 ? 1 : 0;
|
||||
} else {
|
||||
$itemCount = $this->itemCount < 0 ? 0 : (int)$this->itemCount;
|
||||
return (int)(($itemCount + $this->pageSize - 1) / $this->pageSize);
|
||||
$totalCount = $this->totalCount < 0 ? 0 : (int)$this->totalCount;
|
||||
return (int)(($totalCount + $this->pageSize - 1) / $this->pageSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user