vendor/pagerfanta/pagerfanta/src/Pagerfanta/Adapter/DoctrineORMAdapter.php line 79

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Pagerfanta package.
  4.  *
  5.  * (c) Pablo Díez <pablodip@gmail.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Pagerfanta\Adapter;
  11. use Doctrine\ORM\Tools\Pagination\Paginator as DoctrinePaginator;
  12. /**
  13.  * DoctrineORMAdapter.
  14.  *
  15.  * @author Christophe Coevoet <stof@notk.org>
  16.  */
  17. class DoctrineORMAdapter implements AdapterInterface
  18. {
  19.     /**
  20.      * @var \Doctrine\ORM\Tools\Pagination\Paginator
  21.      */
  22.     private $paginator;
  23.     /**
  24.      * Constructor.
  25.      *
  26.      * @param \Doctrine\ORM\Query|\Doctrine\ORM\QueryBuilder $query               A Doctrine ORM query or query builder.
  27.      * @param Boolean                                        $fetchJoinCollection Whether the query joins a collection (true by default).
  28.      * @param Boolean|null                                   $useOutputWalkers    Whether to use output walkers pagination mode
  29.      */
  30.     public function __construct($query$fetchJoinCollection true$useOutputWalkers null)
  31.     {
  32.         $this->paginator = new DoctrinePaginator($query$fetchJoinCollection);
  33.         $this->paginator->setUseOutputWalkers($useOutputWalkers);
  34.     }
  35.     /**
  36.      * Returns the query
  37.      *
  38.      * @return \Doctrine\ORM\Query
  39.      */
  40.     public function getQuery()
  41.     {
  42.         return $this->paginator->getQuery();
  43.     }
  44.     /**
  45.      * Returns whether the query joins a collection.
  46.      *
  47.      * @return Boolean Whether the query joins a collection.
  48.      */
  49.     public function getFetchJoinCollection()
  50.     {
  51.         return $this->paginator->getFetchJoinCollection();
  52.     }
  53.     /**
  54.      * {@inheritdoc}
  55.      */
  56.     public function getNbResults()
  57.     {
  58.         return count($this->paginator);
  59.     }
  60.     /**
  61.      * {@inheritdoc}
  62.      */
  63.     public function getSlice($offset$length)
  64.     {
  65.         $this->paginator
  66.             ->getQuery()
  67.             ->setFirstResult($offset)
  68.             ->setMaxResults($length);
  69.         return $this->paginator->getIterator();
  70.     }
  71. }