vendor/beberlei/porpaginas/src/Porpaginas/Doctrine/ORM/ORMQueryPage.php line 69

Open in your IDE?
  1. <?php
  2. /**
  3.  * Porpaginas
  4.  *
  5.  * LICENSE
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this package in the file LICENSE.txt.
  9.  * If you did not receive a copy of the license and are unable to
  10.  * obtain it through the world-wide-web, please send an email
  11.  * to kontakt@beberlei.de so I can send you a copy immediately.
  12.  */
  13. namespace Porpaginas\Doctrine\ORM;
  14. use Porpaginas\Page;
  15. use Doctrine\ORM\Tools\Pagination\Paginator;
  16. use ArrayIterator;
  17. class ORMQueryPage implements Page
  18. {
  19.     /**
  20.      * @var \Doctrine\ORM\Tools\Pagination\Paginator
  21.      */
  22.     private $paginator;
  23.     /**
  24.      * @var array
  25.      */
  26.     private $result;
  27.     public function __construct(Paginator $paginator)
  28.     {
  29.         $this->paginator $paginator;
  30.     }
  31.     /**
  32.      * @return int
  33.      */
  34.     public function getCurrentOffset()
  35.     {
  36.         return $this->paginator->getQuery()->getFirstResult();
  37.     }
  38.     /**
  39.      * @return int
  40.      */
  41.     public function getCurrentPage()
  42.     {
  43.         return (int) floor($this->getCurrentOffset() / $this->getCurrentLimit()) + 1;
  44.     }
  45.     /**
  46.      * @return int
  47.      */
  48.     public function getCurrentLimit()
  49.     {
  50.         return $this->paginator->getQuery()->getMaxResults();
  51.     }
  52.     /**
  53.      * Return the number of results on the currrent page of the {@link Result}.
  54.      *
  55.      * @return int
  56.      */
  57.     public function count()
  58.     {
  59.         if ($this->result === null) {
  60.             $this->result iterator_to_array($this->paginator);
  61.         }
  62.         return count($this->result);
  63.     }
  64.     /**
  65.      * Return the number of ALL results in the paginatable of {@link Result}.
  66.      *
  67.      * @return int
  68.      */
  69.     public function totalCount()
  70.     {
  71.         return $this->paginator->count();
  72.     }
  73.     /**
  74.      * Return an iterator over selected windows of results of the paginatable.
  75.      *
  76.      * @return Iterator
  77.      */
  78.     public function getIterator()
  79.     {
  80.         if ($this->result) {
  81.             return new ArrayIterator($this->result);
  82.         }
  83.         return $this->paginator;
  84.     }
  85. }