Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
…endframework#6809-empty-zend-paginator-first-page-starts-with-1' into develop

Close zendframework/zendframework#6808
Close zendframework/zendframework#6809
  • Loading branch information
Ocramius committed Dec 5, 2014
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -916,10 +916,13 @@ protected function _createPages($scrollingStyle = null)
// Item numbers
if ($this->getCurrentItems() !== null) {
$pages->currentItemCount = $this->getCurrentItemCount();
$pages->itemCountPerPage = $this->getItemCountPerPage();
$pages->totalItemCount = $this->getTotalItemCount();
$pages->firstItemNumber = (($currentPageNumber - 1) * $this->getItemCountPerPage()) + 1;
$pages->lastItemNumber = $pages->firstItemNumber + $pages->currentItemCount - 1;
$pages->firstItemNumber = $pages->totalItemCount
? (($currentPageNumber - 1) * $pages->itemCountPerPage) + 1
: 0;
$pages->lastItemNumber = $pages->totalItemCount
? $pages->firstItemNumber + $pages->currentItemCount - 1
: 0;
}

return $pages;
Expand Down
28 changes: 28 additions & 0 deletions test/PaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,4 +791,32 @@ public function testGetCacheId()

$this->assertEquals($outputGetCacheId, 'Zend_Paginator_1_' . $outputGetCacheInternalId);
}

/**
* @group 6808
* @group 6809
*/
public function testItemCountsForEmptyItemSet()
{
$paginator = new Paginator\Paginator(new Adapter\ArrayAdapter(array()));
$paginator->setCurrentPageNumber(1);

$expected = new stdClass();
$expected->pageCount = 0;
$expected->itemCountPerPage = 10;
$expected->first = 1;
$expected->current = 1;
$expected->last = 0;
$expected->pagesInRange = array(1 => 1);
$expected->firstPageInRange = 1;
$expected->lastPageInRange = 1;
$expected->currentItemCount = 0;
$expected->totalItemCount = 0;
$expected->firstItemNumber = 0;
$expected->lastItemNumber = 0;

$actual = $paginator->getPages();

$this->assertEquals($expected, $actual);
}
}

0 comments on commit ed09153

Please sign in to comment.