Beispiel #1
0
 /**
  * Required by interface IteratorAggregate.
  *
  * {@inheritdoc}
  */
 public function getIterator()
 {
     $query = $this->paginator->getQuery();
     $query->setFirstResult(null);
     $query->setMaxResults(null);
     return $this->paginator;
 }
Beispiel #2
0
 /**
  * @param Query|QueryBuilder $query
  * @param int $limit
  * @param int $currentPage
  */
 public function __construct($query, $limit, $currentPage = 1)
 {
     $this->paginator = new DoctrinePaginator($query);
     $this->totalCount = $this->paginator->count();
     $this->limit = $limit;
     $this->pagesCount = (int) ceil($this->totalCount / $this->limit);
     if ($this->pagesCount > 0 && $currentPage > $this->pagesCount) {
         $currentPage = $this->pagesCount;
     }
     $this->currentPage = $currentPage;
     $this->paginator->getQuery()->setFirstResult($this->limit * ($this->currentPage - 1))->setMaxResults($this->limit);
     $this->query = $query;
 }
 /**
  * Paginator Helper
  * Pass through a query object, current page & limit
  * the offset is calculated from the page and limit
  * returns an `Paginator` instance, which you can call the following on:
  * $paginator->getIterator()->count() # Total fetched (ie: `5` posts)
  * $paginator->count() # Count of ALL posts (ie: `20` posts)
  * $paginator->getIterator() # ArrayIterator
  * 
  * @param Doctrine\ORM\Query $dql
  *            DQL Query Object
  * @param integer $page
  *            Current page (defaults to 1)
  * @param integer $limit
  *            The total number per page (defaults to 5)
  * @return \Doctrine\ORM\Tools\Pagination\Paginator
  */
 public function paginate($dql, $page = 1, $limit = 15)
 {
     $paginator = new Paginator($dql);
     $paginator->getQuery()->setFirstResult($limit * ($page - 1))->setMaxResults($limit);
     // Limit
     return $paginator;
 }
 /**
  * @param string $collector
  * @param int    $page
  * @param int    $maxItemPerPage
  *
  * @return Paginator
  */
 public function findByCollector($collector, $page, $maxItemPerPage)
 {
     $query = $this->createQueryBuilder('c')->where('c.collector = :collector')->setParameter('collector', $collector)->getQuery();
     $paginator = new Paginator($query);
     $paginator->getQuery()->setFirstResult($maxItemPerPage * ($page - 1))->setMaxResults($maxItemPerPage);
     return $paginator;
 }
Beispiel #5
0
 /**
  * @param Query|QueryBuilder $query
  * @param int                $perPage
  * @param int                $page
  */
 public function __construct($query, $perPage, $page)
 {
     $paginator = new Paginator($query);
     $paginator->getQuery()->setFirstResult($perPage * ($page - 1))->setMaxResults($perPage);
     $this->resource = $paginator;
     $this->page = $page;
     $this->perPage = $perPage;
 }
Beispiel #6
0
 public function __construct(DoctrineOrmPaginator $paginator)
 {
     $this->paginator = $paginator;
     $this->query = $paginator->getQuery();
     $this->firstResult = $this->query->getFirstResult();
     $this->maxResults = $this->query->getMaxResults();
     $this->totalItems = count($paginator);
 }
 public function paginate($dql, $offset = 1, $limit = 10)
 {
     if ($limit > 100 || $limit <= 0) {
         $limit = 100;
     }
     $paginator = new Paginator($dql, false);
     $paginator->getQuery()->setMaxResults($limit)->setFirstResult(($offset - 1) * $limit);
     return $paginator;
 }
 public function findAllStartsWith($letter, $page, $per_page)
 {
     $query = $this->joinQuery();
     if ($letter != 'ALL') {
         $query->where('s.name LIKE :letter')->setParameter('letter', "{$letter}%");
     }
     $query->orderBy('s.name', 'ASC')->addOrderBy('p.name', 'ASC')->addOrderBy('i.imageName', 'ASC');
     $paginator = new Paginator($query, $fetchJoinCollection = true);
     $paginator->getQuery()->setFirstResult(($page - 1) * $per_page)->setMaxResults($per_page);
     return $paginator;
 }
Beispiel #9
0
 /**
  * Generate paginated output
  *
  * @param \Doctrine\ORM\QueryBuilder $qb
  * @param int                        $limit
  * @param int                        $offset
  *
  * @return \FOS\RestBundle\View\View
  */
 protected function paginate(\Doctrine\ORM\QueryBuilder $qb, $limit = null, $offset = null)
 {
     if ($offset != null && intval($offset) > 0) {
         $qb->setFirstResult($offset);
     }
     if ($limit != null && intval($limit) > 0) {
         $qb->setMaxResults($limit);
     }
     $paginator = new Paginator($qb, $fetchJoinCollection = true);
     $view = $this->createView($paginator->getQuery()->getResult());
     $view->setHeader('X-Pagination-Total-Results', count($paginator));
     return $view;
 }
Beispiel #10
0
 public static function paginate($query, &$pageSize = 10, &$currentPage = 1)
 {
     $pageSize = (int) $pageSize;
     $currentPage = (int) $currentPage;
     if ($pageSize < 1) {
         $pageSize = 10;
     }
     if ($currentPage < 1) {
         $currentPage = 1;
     }
     $paginator = new Paginator($query);
     $paginator->getQuery()->setFirstResult($pageSize * ($currentPage - 1))->setMaxResults($pageSize);
     return $paginator;
 }
 /**
  * recuperer les transactions d un compte et entres 2 dates
  * @param type $oAccount
  * @param type $sDateBegin
  * @param type $sDateEnd
  * @return null
  */
 public function findByAccount($oAccount, $sDateBegin, $sDateEnd, $oCategory = null, $sWording = null, $sOperation = null, $nFirstResult = null, $nPerPage = null)
 {
     try {
         if (is_null($nPerPage)) {
             $nPerPage = self::PER_PAGE;
         }
         $sOperator = null;
         if (!is_null($sOperation)) {
             $sOperator = '<';
             if ($sOperation == self::CREDIT) {
                 $sOperator = '>';
             }
         }
         $oQB = $this->createQueryBuilder('t');
         $oQB->innerJoin('t.account', 'a');
         $oQB->innerJoin('t.category', 'c');
         $oQB->OrderBy('t.date', 'ASC');
         $oQB->where('t.account = :account')->setParameter('account', $oAccount);
         $oQB->andWhere('t.date >= :date_b ')->setParameter('date_b', $sDateBegin);
         $oQB->andWhere('t.date <= :date_f ')->setParameter('date_f', $sDateEnd);
         if (!is_null($sOperator)) {
             $oQB->andWhere('t.amount ' . $sOperator . ' :val')->setParameter('val', 0);
         }
         if (!is_null($oCategory)) {
             $oQB->andWhere('t.category = :category')->setParameter('category', $oCategory);
         }
         if (!is_null($sWording)) {
             $oQB->andWhere('t.wording LIKE :word')->setParameter('word', '%' . $sWording . '%');
         }
         $oQB->addSelect('c');
         $oQB->addSelect('a');
         $nTotalResult = count($oQB->getQuery()->getResult());
         if (!is_null($nFirstResult)) {
             $oQB->setFirstResult($nFirstResult);
             $oQB->setMaxResults($nPerPage);
             $paginator = new Paginator($oQB->getQuery(), $fetchJoinCollection = true);
             return array('TotalRecordCount' => $nTotalResult, 'Records' => $paginator->getQuery()->getResult());
         }
         return $oQB->getQuery()->getResult();
     } catch (NoResultException $ex) {
         return null;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getSlice($offset, $length)
 {
     $this->paginator->getQuery()->setFirstResult($offset)->setMaxResults($length);
     return $this->paginator->getIterator();
 }
Beispiel #13
0
 /**
  * {@inheritDoc}
  *
  * @api
  */
 public function getItems($offset, $limit)
 {
     $this->paginator->getQuery()->setFirstResult($offset)->setMaxResults($limit);
     return iterator_to_array($this->paginator->getIterator());
 }
 public function searchUsers($filters)
 {
     $entityManager = $this->getEntityManager();
     $query = $entityManager->createQueryBuilder();
     if ($filters['fields']) {
         $fields = 'partial u.{' . implode($this->getFieldsAndOrFilter($filters['fields']), ',') . '}';
     } else {
         $fields = 'partial u.{' . implode($this->getFieldsAndOrFilter(), ',') . '}';
     }
     $query->select($fields);
     $query->from('Api:User', 'u');
     if ($filters['query']) {
         foreach ($filters['query'] as $q) {
             if ($q['operator'] == '=' || $q['operator'] == 'LIKE') {
                 $query->andWhere('u.' . $q['field'] . ' ' . $q['operator'] . ' :' . $q['field']);
                 $query->setParameter($q['field'], $q['values']);
             } elseif ($q['operator'] == 'IN') {
                 $query->andWhere('u.' . $q['field'] . ' ' . $q['operator'] . ' (:' . $q['field'] . ')');
                 $query->setParameter($q['field'], $q['values']);
             } elseif ($q['operator'] == 'BETWEEN') {
                 $query->andWhere('u.' . $q['field'] . ' ' . $q['operator'] . ' :' . $q['field'] . 'A AND :' . $q['field'] . 'B');
                 $query->setParameter($q['field'] . 'A', $q['values'][0]);
                 $query->setParameter($q['field'] . 'B', $q['values'][1]);
             }
         }
     }
     if ($filters['sort']) {
         foreach ($filters['sort'] as $key => $value) {
             $query->addOrderBy('u.' . $key, $value);
         }
     }
     if ($filters['offset']) {
         $query->setFirstResult($filters['offset']);
     }
     if ($filters['limit']) {
         $query->setMaxResults($filters['limit']);
     } else {
         $query->setMaxResults(10);
     }
     $paginator = new Paginator($query, true);
     $results = $paginator->getQuery()->getResult(Query::HYDRATE_ARRAY);
     return ['metadata' => ['total_rows' => count($paginator), 'result_rows' => count($results)], 'results' => $results];
 }
 private function paginate($query, $offset, $limit)
 {
     $paginator = new Paginator($query);
     $paginator->getQuery()->setFirstResult($offset)->setMaxResults($limit);
     return $paginator;
 }
 /**
  * @param DoctrinePaginator $doctrinePaginator
  * @param VisualPaginator $visualPaginator
  * @param int $itemsPerPage
  * @return array
  */
 public static function apply(DoctrinePaginator $doctrinePaginator, VisualPaginator $visualPaginator, $itemsPerPage = 50) : array
 {
     $visualPaginator->setItems($doctrinePaginator->count(), $itemsPerPage);
     $doctrinePaginator->getQuery()->setFirstResult($visualPaginator->getOffset())->setMaxResults($visualPaginator->getLimit());
     return iterator_to_array($doctrinePaginator);
 }
Beispiel #17
0
 public function paginate($query, $page, $limit)
 {
     $paginator = new Paginator($query);
     $paginator->getQuery()->setFirstResult($limit * ($page - 1))->setMaxResults($limit);
     return $paginator;
 }
 /**
  *
  * {@inheritdoc}
  *
  */
 public function getItems($offset, $itemCountPerPage)
 {
     $this->paginator->getQuery()->setFirstResult($offset)->setMaxResults($itemCountPerPage);
     return $this->paginator->getIterator();
 }
 /**
  * @param int $limitPerPage
  * @return $this
  */
 public function setLimitPerPage($limitPerPage)
 {
     $this->limitPerPage = $limitPerPage;
     $this->doctrinePaginator->getQuery()->setMaxResults($limitPerPage);
     return $this;
 }
 /**
  * 
  * @return \Doctrine\ORM\Query
  */
 private function getQuery()
 {
     return $this->paginator->getQuery();
 }
Beispiel #21
0
 /**
  * @return int
  */
 public function getCurrentLimit()
 {
     return $this->paginator->getQuery()->getMaxResults();
 }
Beispiel #22
0
 /**
  * @param Paginator $paginator
  * @param Criteria $criteria
  *
  * @return array
  */
 private function getPageResult(Paginator $paginator, Criteria $criteria)
 {
     return $paginator->getQuery()->setFirstResult($criteria->getRowsPerPage() * ($criteria->getPage() - 1))->setMaxResults($criteria->getRowsPerPage())->getResult();
 }
 /**
  * Public pagination method
  *
  * @\Mmoreram\ControllerExtraBundle\Annotation\Paginator(
  *      class = {
  *          "factory" = "Mmoreram\ControllerExtraBundle\Tests\FakeBundle\Factory\FakeFactory",
  *          "method" = "createNonStatic",
  *          "static" = false
  *      },
  *      page = 1,
  *      limit = 10,
  *      orderBy = {
  *          { "x", "createdAt", "ASC" },
  *          { "x", "id", "ASC" }
  *      },
  *      wheres = {
  *          { "x", "enabled" , "=", true }
  *      },
  *      leftJoins = {
  *          { "x", "relation", "r" },
  *          { "x", "relation2", "r2" },
  *          { "x", "relation5", "r5", true },
  *      },
  *      innerJoins = {
  *          { "x", "relation3", "r3" },
  *          { "x", "relation4", "r4", true },
  *      },
  *      notNulls = {
  *          {"x", "address1"},
  *          {"x", "address2"},
  *      },
  *      nulls = {
  *          {"x", "city"},
  *      }
  * )
  *
  * @\Mmoreram\ControllerExtraBundle\Annotation\JsonResponse()
  */
 public function paginatorAction(Paginator $paginator)
 {
     $dql = $paginator->getQuery()->getDQL();
     return array('dql' => $dql);
 }
 /**
  * @param Request $request
  * @param array $parameters
  * @param Paginator $paginator
  * @param array $serializerGroups
  * @return View
  */
 public function createView(Request $request, array $parameters, Paginator $paginator, array $serializerGroups = [])
 {
     return $this->create($request, $parameters, $paginator->getQuery()->getResult(), $paginator->count(), $serializerGroups);
 }
Beispiel #25
0
 /**
  * @param  String $dql
  * @param  Integer $page
  * @param  Integer $limit
  * @return Paginator
  */
 private function paginate($dql, $page, $limit)
 {
     $paginator = new Paginator($dql);
     $paginator->getQuery()->setFirstResult($limit * $page - 1)->setMaxResults($limit);
     return $paginator;
 }
 /**
  * @param Query|QueryBuilder $dql
  * @param bool $returnArray
  * @return Paginator
  * @throws EntityNotFoundException
  */
 protected function customPaginate($dql, $returnArray = true)
 {
     $paginator = new Paginator($dql);
     $query = $paginator->getQuery()->setFirstResult($this->limit * ($this->page() - 1))->setMaxResults($this->limit);
     //        if ($returnArray) {
     //            $query->setHydrationMode(Query::HYDRATE_ARRAY);
     //        }
     $total = count($paginator);
     $page = $this->page();
     $from = ($this->page - 1) * $this->limit + 1;
     $to = min($total, $from + $this->limit - 1);
     $next = $total > $to ? "/?page=" . ($page + 1) : null;
     $prev = $from > 1 ? "/?page=" . ($page - 1) : null;
     //        if (empty($paginator->getIterator()->getArrayCopy())) {
     //            throw new EntityNotFoundException;
     //        }
     $result = $paginator->getQuery()->getResult();
     if (empty($result)) {
         throw new EntityNotFoundException();
     }
     foreach ($result as $key => $value) {
         if (is_object($value)) {
             $result[$key] = $value->toArray($this->with);
         }
     }
     $this->data['pagination']['total'] = $total;
     $this->data['pagination']['to'] = $to;
     $this->data['pagination']['from'] = $from;
     $this->data['pagination']['per_page'] = $this->limit;
     $this->data['pagination']['current_page'] = $this->page();
     $this->data['pagination']['next_page_url'] = $next;
     $this->data['pagination']['prev_page_url'] = $prev;
     $this->data['data'] = $result;
     return $this->data;
 }