public function testCreateDataSet_pagination()
 {
     $request = $this->getBaseRequest();
     $request->displayStart = 100;
     $request->displayLength = 10;
     $dataSet = $this->dataSource->createDataSet($request);
     $this->assertEquals(100, $this->qb->getFirstResult());
     $this->assertEquals(10, $this->qb->getMaxResults());
 }
Example #2
0
 /**
  * It is possible to use query builder with additional columns.
  * In this case, only item at index [0] is returned, because
  * it should be an entity object.
  * @return array
  */
 public function getData()
 {
     $data = array();
     // Paginator is better if the query uses ManyToMany associations
     $result = $this->qb->getMaxResults() !== NULL || $this->qb->getFirstResult() !== NULL ? new Paginator($this->getQuery()) : $this->qb->getQuery()->getResult();
     foreach ($result as $item) {
         // Return only entity itself
         $data[] = is_array($item) ? $item[0] : $item;
     }
     return $data;
 }
Example #3
0
 public function run(QueryBuilder $queryBuilder, $callback, $limit = null)
 {
     if (!is_callable($callback)) {
         throw new ORMWalkerException('$callback is not callable');
     }
     if (!is_null($limit)) {
         $queryBuilder->setMaxResults($limit);
     } else {
         $limit = $queryBuilder->getMaxResults();
     }
     if (is_null($limit)) {
         $limit = PHP_INT_MAX;
     }
     $offset = 0;
     do {
         $rows = $queryBuilder->setFirstResult($offset)->getQuery()->getResult();
         call_user_func($callback, $rows, $offset, $limit);
         $offset += $limit;
     } while (count($rows) >= $limit);
 }
Example #4
0
 /**
  * It is possible to use query builder with additional columns.
  * In this case, only item at index [0] is returned, because
  * it should be an entity object.
  * @return array
  */
 public function getData()
 {
     // Paginator is better if the query uses ManyToMany associations
     $usePaginator = $this->qb->getMaxResults() !== NULL || $this->qb->getFirstResult() !== NULL;
     $data = array();
     if ($usePaginator) {
         $paginator = new Paginator($this->getQuery());
         // Convert paginator to the array
         foreach ($paginator as $result) {
             // Return only entity itself
             $data[] = is_array($result) ? $result[0] : $result;
         }
     } else {
         foreach ($this->qb->getQuery()->getResult() as $result) {
             // Return only entity itself
             $data[] = is_array($result) ? $result[0] : $result;
         }
     }
     return $data;
 }
Example #5
0
 /**
  * Determines whether the query builder has the maximum number of results specified.
  *
  * @param QueryBuilder $queryBuilder
  *
  * @return bool
  */
 public static function hasMaxResults(QueryBuilder $queryBuilder)
 {
     return null !== $queryBuilder->getMaxResults();
 }
Example #6
0
 /**
  * @return int
  */
 public function countPages()
 {
     return (int) ceil($this->count() / $this->builder->getMaxResults());
 }
 /**
  * {@inheritdoc}
  */
 public function getMaxResults()
 {
     return $this->queryBuilder->getMaxResults();
 }