當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。