本文整理汇总了PHP中Zend\Paginator\Paginator::getPageRange方法的典型用法代码示例。如果您正苦于以下问题:PHP Paginator::getPageRange方法的具体用法?PHP Paginator::getPageRange怎么用?PHP Paginator::getPageRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Paginator\Paginator
的用法示例。
在下文中一共展示了Paginator::getPageRange方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPages
/**
* Returns an array of "local" pages given a page number and range.
*
* @param \Zend\Paginator\Paginator $paginator
* @param integer $pageRange (Optional) Page range
* @return array
*/
public function getPages(\Zend\Paginator\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: 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);
}
示例3: getPages
/**
* Returns an array of "local" pages given a page number and range.
*
* @param Paginator $paginator
* @param int $pageRange Unused
* @return array
*/
public function getPages(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);
}
示例4: getPages
/**
* Returns an array of "local" pages given a page number and range.
*
* @param Paginator $paginator
* @param int $pageRange Unused
* @return array
*/
public function getPages(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;
} elseif ($originalPageRange + $pageNumber - 1 > count($paginator)) {
$pageRange = $originalPageRange + count($paginator) - $pageNumber;
}
return parent::getPages($paginator, $pageRange);
}
示例5: indexAction
public function indexAction()
{
/** @var QueryBuilder $qb */
$qb = $this->getObjectManager()->createQueryBuilder();
$qb->select('w')->from(Word::class, 'w');
$form = new WordSearchForm();
$form->setData($this->params()->fromQuery());
$form->setInputFilter(new WordSearchInputFilter());
// it doesn't matter if the form is not valid, as we would fill in default values anyway. This is just to avoid the default error messages
$form->isValid();
// set query, direction and order for the querybuilder
$direction = strtolower($form->getData()['d']);
$direction = $direction == 'desc' ? 'desc' : 'asc';
$orderBy = strtolower($form->getData()['o']);
switch ($orderBy) {
case 'created':
$order = 'createdAt';
break;
case 'updated':
$order = 'updatedAt';
break;
default:
$orderBy = $order = 'word';
break;
}
$qb->orderBy('w.' . $order, $direction);
// no need to avoid SQL injection, as doctrine does this for us
$query = $form->getData()['q'];
$qb->where('w.word LIKE :query')->setParameter('query', '%' . $query . '%');
$itemsPerPage = 50;
// set up the paginator
$adapter = new DoctrineAdapter(new ORMPaginator($qb->getQuery()));
$paginator = new Paginator($adapter);
$paginator->setDefaultItemCountPerPage(50);
$page = (int) $this->params()->fromQuery('p');
if ($page != null) {
$paginator->setCurrentPageNumber($page);
} else {
$paginator->setCurrentPageNumber(1);
}
$pages = $paginator->getTotalItemCount() / $itemsPerPage;
$paginator->setPageRange($pages);
$viewModel = new ViewModel();
$viewModel->setVariables(['words' => $paginator->getCurrentItems(), 'pageCount' => $paginator->getPageRange() + 1, 'currentPage' => $paginator->getCurrentPageNumber(), 'orderBy' => $orderBy, 'direction' => $direction, 'query' => $query, 'form' => $form]);
return $viewModel;
}
示例6: searchAction
/**
* @return ViewModel
*/
public function searchAction()
{
$searchService = $this->getContactSearchService();
$page = $this->params('page', 1);
$form = new SearchResult();
$data = array_merge(['query' => '*', 'facet' => []], $this->getRequest()->getQuery()->toArray());
if ($this->getRequest()->isGet()) {
$searchService->setSearch($data['query']);
if (isset($data['facet'])) {
foreach ($data['facet'] as $facetField => $values) {
$quotedValues = [];
foreach ($values as $value) {
$quotedValues[] = sprintf("\"%s\"", $value);
}
$searchService->addFilterQuery($facetField, implode(' ' . SolariumQuery::QUERY_OPERATOR_OR . ' ', $quotedValues));
}
}
$form->addSearchResults($searchService->getQuery()->getFacetSet(), $searchService->getResultSet()->getFacetSet());
$form->setData($data);
}
$paginator = new Paginator(new SolariumPaginator($searchService->getSolrClient(), $searchService->getQuery()));
$paginator->setDefaultItemCountPerPage($page === 'all' ? PHP_INT_MAX : 16);
$paginator->setCurrentPageNumber($page);
$paginator->setPageRange(ceil($paginator->getTotalItemCount() / $paginator->getDefaultItemCountPerPage()));
return new ViewModel(['form' => $form, 'paginator' => $paginator, 'queryParams' => http_build_query($data), 'routeName' => $this->getEvent()->getRouteMatch()->getMatchedRouteName(), 'params' => $this->getEvent()->getRouteMatch()->getParams(), 'currentPage' => $page, 'lastPage' => $paginator->getPageRange(), 'showAlwaysFirstAndLast' => true]);
}