当前位置: 首页>>代码示例>>PHP>>正文


PHP Paginator::getPageRange方法代码示例

本文整理汇总了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);
    }
开发者ID:niallmccrudden,项目名称:zf2,代码行数:37,代码来源:Sliding.php

示例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);
 }
开发者ID:rajanlamic,项目名称:IntTest,代码行数:15,代码来源:PaginatorTest.php

示例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);
 }
开发者ID:KBO-Techo-Dev,项目名称:MagazinePro-zf25,代码行数:20,代码来源:Jumping.php

示例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);
 }
开发者ID:leonardovn86,项目名称:zf2_basic2013,代码行数:20,代码来源:Elastic.php

示例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;
 }
开发者ID:spoorey,项目名称:hangman,代码行数:46,代码来源:WordController.php

示例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]);
 }
开发者ID:iteaoffice,项目名称:contact,代码行数:29,代码来源:ContactController.php


注:本文中的Zend\Paginator\Paginator::getPageRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。