本文整理汇总了PHP中Zend_Paginator::getPageRange方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Paginator::getPageRange方法的具体用法?PHP Zend_Paginator::getPageRange怎么用?PHP Zend_Paginator::getPageRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Paginator
的用法示例。
在下文中一共展示了Zend_Paginator::getPageRange方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPages
/**
* Returns an array of "local" pages given a page number and range.
*
* @param Zend_Paginator $paginator
* @param integer $pageRange (Optional) Page range
* @return array
*/
public function getPages(Zend_Paginator $paginator, $pageRange = null)
{
if ($pageRange === null) {
$pageRange = $paginator->getPageRange();
}
$pageNumber = $paginator->getCurrentPageNumber();
$pageCount = count($paginator);
if ($pageRange > $pageCount) {
$pageRange = $pageCount;
}
$delta = ceil($pageRange / 2);
if ($pageNumber - $delta > $pageCount - $pageRange) {
$lowerBound = $pageCount - $pageRange + 1;
$upperBound = $pageCount;
} else {
if ($pageNumber - $delta < 0) {
$delta = $pageNumber;
}
$offset = $pageNumber - $delta;
$lowerBound = $offset + 1;
$upperBound = $offset + $pageRange;
}
return $paginator->getPagesInRange($lowerBound, $upperBound);
}
示例2: testGetSetPageRange
public function testGetSetPageRange()
{
$this->_restorePaginatorDefaults();
$this->assertEquals(10, $this->_paginator->getPageRange());
$this->_paginator->setPageRange(15);
$this->assertEquals(15, $this->_paginator->getPageRange());
}
示例3: getPages
/**
* Returns an array of "local" pages given a page number and range.
*
* @param Zend_Paginator $paginator
* @param integer $pageRange (Optional) Page range
* @return array
*/
public function getPages(Zend_Paginator $paginator, $pageRange = null)
{
// This is unused
if ($pageRange === null) {
$pageRange = $paginator->getPageRange();
}
$pageNumber = $paginator->getCurrentPageNumber();
$pageCount = count($paginator);
$range = array();
if ($pageCount < 10) {
// Show all pages if we have less than 10.
for ($i = 1; $i < 10; $i++) {
if ($i > $pageCount) {
break;
}
$range[$i] = $i;
}
} else {
// More than 10 pages:
foreach (array(1, 2) as $i) {
$range[$i] = $i;
}
if ($pageNumber < 6) {
// We are on page 1-5 from
for ($i = 1; $i <= 7; $i++) {
$range[$i] = $i;
}
} else {
// Current page > 5
$range[] = '...';
// Less than 5 pages left
if ($pageCount - $pageNumber < 5) {
$start = 5 - ($pageCount - $pageNumber);
} else {
$start = 1;
}
for ($i = $pageNumber - $start; $i < $pageNumber + (4 - $start); $i++) {
if ($i > $pageCount) {
break;
}
$range[$i] = $i;
}
}
if ($pageNumber < $pageCount - 2) {
$range[] = '...';
}
foreach (array($pageCount - 1, $pageCount) as $i) {
$range[$i] = $i;
}
}
if (empty($range)) {
$range[] = 1;
}
return $range;
}
示例4: getPages
/**
* Returns an array of "local" pages given a page number and range.
*
* @param Zend_Paginator $paginator
* @param integer $pageRange Unused
* @return array
*/
public function getPages(Zend_Paginator $paginator, $pageRange = null)
{
$pageRange = $paginator->getPageRange();
$pageNumber = $paginator->getCurrentPageNumber();
$originalPageRange = $pageRange;
$pageRange = $pageRange * 2 - 1;
if ($originalPageRange + $pageNumber - 1 < $pageRange) {
$pageRange = $originalPageRange + $pageNumber - 1;
}
return parent::getPages($paginator, $pageRange);
}
示例5: testCastsIntegerValuesToInteger
/**
* @group ZF-4193
*/
public function testCastsIntegerValuesToInteger()
{
// Current page number
$this->_paginator->setCurrentPageNumber(3.3);
$this->assertTrue($this->_paginator->getCurrentPageNumber() == 3);
// Item count per page
$this->_paginator->setItemCountPerPage(3.3);
$this->assertTrue($this->_paginator->getItemCountPerPage() == 3);
// Page range
$this->_paginator->setPageRange(3.3);
$this->assertTrue($this->_paginator->getPageRange() == 3);
}
示例6: getPages
/**
* Returns an array of "local" pages given a page number and range.
*
* @param Zend_Paginator $paginator
* @param integer $pageRange Unused
* @return array
*/
public function getPages(Zend_Paginator $paginator, $pageRange = null)
{
$pageRange = $paginator->getPageRange();
$pageNumber = $paginator->getCurrentPageNumber();
$delta = $pageNumber % $pageRange;
if ($delta == 0) {
$delta = $pageRange;
}
$offset = $pageNumber - $delta;
$lowerBound = $offset + 1;
$upperBound = $offset + $pageRange;
return $paginator->getPagesInRange($lowerBound, $upperBound);
}
示例7: getPages
/**
* Create the page object used in View - paginator method
* @access public
* @return object
*/
public function getPages()
{
$pages = new stdClass();
$pageCount = $this->_paginator->count();
$pages->pageCount = $pageCount;
$pages->itemCountPerPage = $this->_itemCountPerPage;
$pages->first = 1;
$pages->current = (int) $this->_currentPage;
$pages->last = $pageCount;
// Previous and next
if ($this->_currentPage - 1 > 0) {
$pages->previous = $this->_currentPage - 1;
}
if ($this->_currentPage + 1 <= $pageCount) {
$pages->next = $this->_currentPage + 1;
}
// Pages in range
$pageRange = $this->_paginator->getPageRange();
if ($pageRange > $pageCount) {
$pageRange = $pageCount;
}
$delta = ceil($pageRange / 2);
if ($this->_currentPage - $delta > $pageCount - $pageRange) {
$lowerBound = $pageCount - $pageRange + 1;
$upperBound = $pageCount;
} else {
if ($this->_currentPage - $delta < 0) {
$delta = $this->_currentPage;
}
$offset = $this->_currentPage - $delta;
$lowerBound = $offset + 1;
$upperBound = $offset + $pageRange;
}
$pages->pagesInRange = $this->_paginator->getPagesInRange($lowerBound, $upperBound);
$pages->firstPageInRange = min($pages->pagesInRange);
$pages->lastPageInRange = max($pages->pagesInRange);
// Item numbers
if ($this->_currentItems == null) {
$this->getCurrentItems();
}
if ($this->_currentItems !== null) {
$pages->currentItemCount = $this->_paginator->getCurrentItemCount();
$pages->itemCountPerPage = $this->_paginator->getItemCountPerPage();
$pages->totalItemCount = $this->_paginator->getTotalItemCount();
$pages->firstItemNumber = ($this->_currentPage - 1) * $this->_paginator->getItemCountPerPage() + 1;
$pages->lastItemNumber = $pages->firstItemNumber + $pages->currentItemCount - 1;
}
return $pages;
}
示例8: getPages
/**
* Returns an array of "local" pages given a page number and range.
*
* @param Zend_Paginator $paginator
* @param integer $pageRange (Optional) Page range
* @return array
*/
public function getPages(Zend_Paginator $paginator, $pageRange = null)
{
if ($pageRange === null) {
$pageRange = $paginator->getPageRange();
}
$pageNumber = $paginator->getCurrentPageNumber();
$pageCount = count($paginator);
$range = array();
if ($pageCount < 15) {
for ($i = 1; $i < 15; $i++) {
if ($i > $pageCount) {
break;
}
$range[$i] = $i;
}
} else {
foreach (array(1, 2) as $i) {
$range[$i] = $i;
}
if ($pageNumber > 8) {
$range[] = '...';
$start = 5;
if ($pageCount - $pageNumber < 8) {
$start = 9 - ($pageCount - $pageNumber);
}
for ($i = $pageNumber - $start; $i < $pageNumber + (10 - $start); $i++) {
if ($i > $pageCount) {
break;
}
$range[$i] = $i;
}
} else {
for ($i = 3; $i <= 10; $i++) {
$range[$i] = $i;
}
}
if ($pageNumber < $pageCount - 7) {
$range[] = '...';
foreach (array($pageCount - 1, $pageCount) as $i) {
$range[$i] = $i;
}
}
}
if (empty($range)) {
$range[] = 1;
}
return $range;
}