Browse Source

method renaming.

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
111e7b3f60
  1. 18
      framework/yii/data/ActiveDataProvider.php
  2. 20
      framework/yii/data/ArrayDataProvider.php
  3. 2
      framework/yii/data/DataProvider.php
  4. 8
      framework/yii/data/IDataProvider.php
  5. 14
      framework/yii/data/Pagination.php

18
framework/yii/data/ActiveDataProvider.php

@ -53,7 +53,7 @@ use yii\db\Connection;
class ActiveDataProvider extends DataProvider 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. * if it is not explicitly set.
*/ */
public $query; public $query;
@ -98,29 +98,29 @@ class ActiveDataProvider extends DataProvider
/** /**
* Returns the number of data items in the current page. * Returns the number of data items in the current page.
* This is equivalent to `count($provider->items)`. * 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, * @param boolean $refresh whether to recalculate the item count. If true,
* this will cause re-fetching of [[items]]. * this will cause re-fetching of [[items]].
* @return integer the number of data items in the current page. * @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)); return count($this->getItems($refresh));
} }
/** /**
* Returns the total number of data items. * Returns the total number of data items.
* When [[pagination]] is false, this returns the same value as [[itemCount]]. * When [[pagination]] is false, this returns the same value as [[count]].
* If [[totalItemCount]] is not explicitly set, it will be calculated * If [[totalCount]] is not explicitly set, it will be calculated
* using [[query]] with a COUNT query. * using [[query]] with a COUNT query.
* @param boolean $refresh whether to recalculate the item count * @param boolean $refresh whether to recalculate the item count
* @return integer total number of possible data items. * @return integer total number of possible data items.
* @throws InvalidConfigException * @throws InvalidConfigException
*/ */
public function getTotalItemCount($refresh = false) public function getTotalCount($refresh = false)
{ {
if ($this->getPagination() === false) { if ($this->getPagination() === false) {
return $this->getItemCount($refresh); return $this->getCount($refresh);
} elseif ($this->_count === null || $refresh) { } elseif ($this->_count === null || $refresh) {
if (!$this->query instanceof Query) { if (!$this->query instanceof Query) {
throw new InvalidConfigException('The "query" property must be an instance of Query or its subclass.'); 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. * Sets the total number of data items.
* @param integer $value 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->_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.'); throw new InvalidConfigException('The "query" property must be an instance of Query or its subclass.');
} }
if (($pagination = $this->getPagination()) !== false) { if (($pagination = $this->getPagination()) !== false) {
$pagination->itemCount = $this->getTotalItemCount(); $pagination->totalCount = $this->getTotalCount();
$this->query->limit($pagination->getLimit())->offset($pagination->getOffset()); $this->query->limit($pagination->getLimit())->offset($pagination->getOffset());
} }
if (($sort = $this->getSort()) !== false) { if (($sort = $this->getSort()) !== false) {

20
framework/yii/data/ArrayDataProvider.php

@ -67,34 +67,34 @@ class ArrayDataProvider extends DataProvider
*/ */
public $allItems; public $allItems;
private $_count; private $_totalCount;
/** /**
* Returns the total number of data items. * Returns the total number of data items.
* @return integer total number of possible data items. * @return integer total number of possible data items.
* @throws InvalidConfigException * @throws InvalidConfigException
*/ */
public function getTotalItemCount() public function getTotalCount()
{ {
if ($this->getPagination() === false) { if ($this->getPagination() === false) {
return $this->getItemCount(); return $this->getCount();
} elseif ($this->_count === null) { } elseif ($this->_totalCount === null) {
if ($this->allItems !== null) { if ($this->allItems !== null) {
$this->_count = count($this->allItems); $this->_totalCount = count($this->allItems);
} else { } 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. * Sets the total number of data items.
* @param integer $value 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; private $_items;
@ -116,7 +116,7 @@ class ArrayDataProvider extends DataProvider
} }
if (($pagination = $this->getPagination()) !== false) { if (($pagination = $this->getPagination()) !== false) {
$pagination->itemCount = $this->getTotalItemCount(); $pagination->totalCount = $this->getTotalCount();
$items = array_slice($items, $pagination->getOffset(), $pagination->getLimit()); $items = array_slice($items, $pagination->getOffset(), $pagination->getLimit());
} }

2
framework/yii/data/DataProvider.php

@ -96,7 +96,7 @@ abstract class DataProvider extends Component implements IDataProvider
* Returns the number of data items in the current page. * Returns the number of data items in the current page.
* @return integer 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()); return count($this->getItems());
} }

8
framework/yii/data/IDataProvider.php

@ -22,17 +22,17 @@ interface IDataProvider
/** /**
* Returns the number of data items in the current page. * Returns the number of data items in the current page.
* This is equivalent to `count($provider->getItems())`. * 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. * @return integer the number of data items in the current page.
*/ */
public function getItemCount(); public function getCount();
/** /**
* Returns the total number of data items. * 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. * @return integer total number of possible data items.
*/ */
public function getTotalItemCount(); public function getTotalCount();
/** /**
* Returns the data items in the current page. * Returns the data items in the current page.

14
framework/yii/data/Pagination.php

@ -14,7 +14,7 @@ use yii\base\Object;
* Pagination represents information relevant to pagination of data items. * Pagination represents information relevant to pagination of data items.
* *
* When data needs to be rendered in multiple pages, Pagination can be used to * 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]] * [[page|current page]], etc. These information can be passed to [[yii\widgets\Pager|pagers]]
* to render pagination buttons or links. * to render pagination buttons or links.
* *
@ -28,7 +28,7 @@ use yii\base\Object;
* { * {
* $query = Article::find()->where(array('status' => 1)); * $query = Article::find()->where(array('status' => 1));
* $countQuery = clone $query; * $countQuery = clone $query;
* $pages = new Pagination(array('itemCount' => $countQuery->count())); * $pages = new Pagination(array('totalCount' => $countQuery->count()));
* $models = $query->offset($pages->offset) * $models = $query->offset($pages->offset)
* ->limit($pages->limit) * ->limit($pages->limit)
* ->all(); * ->all();
@ -91,7 +91,7 @@ class Pagination extends Object
/** /**
* @var boolean whether to check if [[page]] is within valid range. * @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). * 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 * 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]]. * 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. * @var integer total number of items.
*/ */
public $itemCount = 0; public $totalCount = 0;
/** /**
@ -113,10 +113,10 @@ class Pagination extends Object
public function getPageCount() public function getPageCount()
{ {
if ($this->pageSize < 1) { if ($this->pageSize < 1) {
return $this->itemCount > 0 ? 1 : 0; return $this->totalCount > 0 ? 1 : 0;
} else { } else {
$itemCount = $this->itemCount < 0 ? 0 : (int)$this->itemCount; $totalCount = $this->totalCount < 0 ? 0 : (int)$this->totalCount;
return (int)(($itemCount + $this->pageSize - 1) / $this->pageSize); return (int)(($totalCount + $this->pageSize - 1) / $this->pageSize);
} }
} }

Loading…
Cancel
Save