Fixed returned range bug(s)
This commit is contained in:
parent
c6e2086798
commit
e01809d19a
@ -81,7 +81,12 @@ class Doctrine_Pager_Range_Sliding extends Doctrine_Pager_Range
|
|||||||
*/
|
*/
|
||||||
protected function _setChunkLength($chunkLength)
|
protected function _setChunkLength($chunkLength)
|
||||||
{
|
{
|
||||||
$this->_chunkLength = $chunkLength;
|
$chunkLength = (int) $chunkLength;
|
||||||
|
if (!$chunkLength) {
|
||||||
|
$chunkLength = 1;
|
||||||
|
} else {
|
||||||
|
$this->_chunkLength = $chunkLength;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -95,25 +100,29 @@ class Doctrine_Pager_Range_Sliding extends Doctrine_Pager_Range
|
|||||||
public function rangeAroundPage()
|
public function rangeAroundPage()
|
||||||
{
|
{
|
||||||
$pager = $this->getPager();
|
$pager = $this->getPager();
|
||||||
$page = $pager->getPage();
|
$page = $pager->getPage();
|
||||||
|
$pages = $pager->getLastPage();
|
||||||
|
|
||||||
// Define initial assignments for StartPage and EndPage
|
$chunk = $this->getChunkLength();
|
||||||
$startPage = $page - floor($this->getChunkLength() - 1) / 2;
|
if ($chunk > $pages) {
|
||||||
$endPage = ($startPage + $this->getChunkLength()) - 1;
|
$chunk = $pages;
|
||||||
|
|
||||||
// Check for EndPage out-range
|
|
||||||
if ($endPage > $pager->getLastPage()) {
|
|
||||||
$offset = $endPage - $pager->getLastPage();
|
|
||||||
|
|
||||||
$endPage = $pager->getLastPage();
|
|
||||||
$startPage = $startPage - $offset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for StartPage out-range
|
$chunkStart = $page - (floor($chunk / 2));
|
||||||
if ($startPage < $pager->getFirstPage()) {
|
$chunkEnd = $page + (ceil($chunk / 2)-1);
|
||||||
$startPage = $pager->getFirstPage();
|
|
||||||
|
if ($chunkStart < 1) {
|
||||||
|
$adjust = 1 - $chunkStart;
|
||||||
|
$chunkStart = 1;
|
||||||
|
$chunkEnd = $chunkEnd + $adjust;
|
||||||
|
}
|
||||||
|
if ($chunkEnd > $pages) {
|
||||||
|
$adjust = $chunkEnd - $pages;
|
||||||
|
$chunkStart = $chunkStart - $adjust;
|
||||||
|
$chunkEnd = $pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
return range($startPage, $endPage);
|
return range($chunkStart, $chunkEnd);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user