Merge branch '3'

This commit is contained in:
Daniel Hensby 2017-01-10 13:08:47 +00:00
commit f3b6bb1470
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
3 changed files with 61 additions and 33 deletions

View File

@ -212,18 +212,23 @@ class GridFieldPaginator implements GridField_HTMLProvider, GridField_DataManipu
return null; return null;
} }
$totalPages = (int)ceil($totalRows/$this->itemsPerPage); $totalPages = 1;
$firstShownRecord = 1;
$lastShownRecord = $totalRows;
if ($itemsPerPage = $this->getItemsPerPage()) {
$totalPages = (int)ceil($totalRows / $itemsPerPage);
if ($totalPages == 0) { if ($totalPages == 0) {
$totalPages = 1; $totalPages = 1;
} }
$firstShownRecord = ($state->currentPage - 1) * $this->itemsPerPage + 1; $firstShownRecord = ($state->currentPage - 1) * $itemsPerPage + 1;
if ($firstShownRecord > $totalRows) { if ($firstShownRecord > $totalRows) {
$firstShownRecord = $totalRows; $firstShownRecord = $totalRows;
} }
$lastShownRecord = $state->currentPage * $this->itemsPerPage; $lastShownRecord = $state->currentPage * $itemsPerPage;
if ($lastShownRecord > $totalRows) { if ($lastShownRecord > $totalRows) {
$lastShownRecord = $totalRows; $lastShownRecord = $totalRows;
} }
}
// If there is only 1 page for all the records in list, we don't need to go further // If there is only 1 page for all the records in list, we don't need to go further
// to sort out those first page, last page, pre and next pages, etc // to sort out those first page, last page, pre and next pages, etc

View File

@ -291,8 +291,10 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
/** /**
* Construct a new DataObject. * Construct a new DataObject.
* *
* @param array|null $record This will be null for a new database record. Alternatively, you can pass an array of
* field values. Normally this constructor is only used by the internal systems that get objects from the database. * @param array|null $record Used internally for rehydrating an object from database content.
* Bypasses setters on this class, and hence should not be used
* for populating data on new records.
* @param boolean $isSingleton This this to true if this is a singleton() object, a stub for calling methods. * @param boolean $isSingleton This this to true if this is a singleton() object, a stub for calling methods.
* Singletons don't have their defaults set. * Singletons don't have their defaults set.
* @param DataModel $model * @param DataModel $model

View File

@ -2,20 +2,20 @@
namespace SilverStripe\Forms\Tests\GridField; namespace SilverStripe\Forms\Tests\GridField;
use SilverStripe\Control\Controller;
use SilverStripe\Dev\CSSContentParser;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldPageCount;
use SilverStripe\Forms\GridField\GridFieldPaginator;
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Player; use SilverStripe\Forms\Tests\GridField\GridFieldTest\Player;
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Team; use SilverStripe\Forms\Tests\GridField\GridFieldTest\Team;
use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataList; use SilverStripe\ORM\DataList;
use SilverStripe\Dev\CSSContentParser;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Control\Controller;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
use SilverStripe\Forms\GridField\GridFieldPaginator;
use SilverStripe\Forms\GridField\GridFieldPageCount;
use SilverStripe\Forms\GridField\GridField;
class GridFieldPaginatorTest extends FunctionalTest class GridFieldPaginatorTest extends FunctionalTest
{ {
@ -87,6 +87,27 @@ class GridFieldPaginatorTest extends FunctionalTest
$this->assertEquals(2, count($content->getBySelector('.pagination-records-number'))); $this->assertEquals(2, count($content->getBySelector('.pagination-records-number')));
} }
public function testUnlimitedRowCount()
{
$total = $this->list->count();
// set up the paginator
/** @var GridFieldPaginator $paginator */
$paginator = $this->gridField->getConfig()->getComponentByType(GridFieldPaginator::class);
$paginator->setThrowExceptionOnBadDataType(true);
$paginator->setItemsPerPage(1);
$paginator->getManipulatedData($this->gridField, $this->list);
$params = $paginator->getTemplateParameters($this->gridField)->toMap();
$this->assertFalse($params['OnlyOnePage']);
$this->assertEquals($total, $params['NumRecords']);
$paginator->setItemsPerPage(0);
$params = $paginator->getTemplateParameters($this->gridField)->toMap();
$this->assertTrue($params['OnlyOnePage']);
$this->assertEquals($total, $params['NumRecords']);
}
public function testPaginationAvoidsIllegalOffsets() public function testPaginationAvoidsIllegalOffsets()
{ {
$grid = $this->gridField; $grid = $this->gridField;