Merge branch 'master' of git://github.com/yiisoft/yii2 into 16966-add-array_expression-support-to-relation-data

This commit is contained in:
GHopper
2019-01-01 22:33:52 +03:00
4 changed files with 55 additions and 5 deletions

View File

@ -5,6 +5,7 @@ Yii Framework 2 Change Log
------------------------
- Bug #16966: Fix ArrayExpression support in related tables (GHopperMSK)
- Bug #16891: Fixed Pagination::totalCount initialized incorrectly (taobig)
- Bug #16028: Fix serialization of complex cache keys that contain non-UTF sequences (rugabarbo)
- Bug #16945: Fixed RBAC DbManager ruleName fetching on the case of PDO::ATTR_ORACLE_NULLS => PDO::NULL_TO_STRING (razonyang)
- Bug #16081: Fixed composite IN using just one column (rugabarbo)

View File

@ -46,6 +46,9 @@ abstract class BaseDataProvider extends Component implements DataProviderInterfa
public $id;
private $_sort;
/**
* @var Pagination|false $_pagination
*/
private $_pagination;
private $_keys;
private $_models;
@ -183,8 +186,6 @@ abstract class BaseDataProvider extends Component implements DataProviderInterfa
/**
* Returns the pagination object used by this data provider.
* Note that you should call [[prepare()]] or [[getModels()]] first to get correct values
* of [[Pagination::totalCount]] and [[Pagination::pageCount]].
* @return Pagination|false the pagination object. If this is false, it means the pagination is disabled.
*/
public function getPagination()
@ -193,6 +194,13 @@ abstract class BaseDataProvider extends Component implements DataProviderInterfa
$this->setPagination([]);
}
if (($this->_pagination !== false) && ($this->_pagination->totalCount === null)) {
if ($this->_totalCount === null) {
$this->setTotalCount($this->prepareTotalCount());
}
$this->_pagination->totalCount = $this->_totalCount;
}
return $this->_pagination;
}

View File

@ -124,9 +124,9 @@ class Pagination extends BaseObject implements Linkable
*/
public $validatePage = true;
/**
* @var int total number of items.
* @var int|null total number of items.
*/
public $totalCount = 0;
public $totalCount;
/**
* @var int the default page size. This property will be returned by [[pageSize]] when page size
* cannot be determined by [[pageSizeParam]] from [[params]].

View File

@ -170,7 +170,7 @@ abstract class ActiveDataProviderTest extends DatabaseTestCase
'query' => $query->from('order')->orderBy('id'),
]);
$pagination = $provider->getPagination();
$this->assertEquals(0, $pagination->getPageCount());
$this->assertEquals(1, $pagination->getPageCount());
$this->assertCount(3, $provider->getModels());
$this->assertEquals(1, $pagination->getPageCount());
@ -198,4 +198,45 @@ abstract class ActiveDataProviderTest extends DatabaseTestCase
$this->assertEquals(0, $pagination->getPageCount());
}
public function testValidateTotalCount()
{
$provider = new ActiveDataProvider([
'query' => Order::find()->orderBy('id'),
'totalCount' => 100,
'pagination' => [
],
]);
$this->assertSame(100, $provider->pagination->totalCount);
$provider = new ActiveDataProvider([
'query' => Order::find()->orderBy('id'),
'totalCount' => 100,
'pagination' => false,
]);
$this->assertSame(false, $provider->pagination);
}
public function testValidatePageCount()
{
$provider = new ActiveDataProvider([
'query' => Order::find()->orderBy('id'),
'totalCount' => 100,
'pagination' => [
'pageSize' => 101,
],
]);
$this->assertSame(1, $provider->pagination->pageCount);
$provider = new ActiveDataProvider([
'query' => Order::find()->orderBy('id'),
'totalCount' => 100,
'pagination' => [
'pageSize' => 1,
],
]);
$this->assertSame(100, $provider->pagination->pageCount);
}
}