Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getIterator()
 {
     $offset = $this->query->getFirstResult();
     $length = $this->query->getMaxResults();
     if ($this->fetchJoinCollection) {
         $subQuery = $this->cloneQuery($this->query);
         $subQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\\ORM\\Tools\\Pagination\\LimitSubqueryWalker'))->setFirstResult($offset)->setMaxResults($length);
         $ids = array_map('current', $subQuery->getScalarResult());
         $whereInQuery = $this->cloneQuery($this->query);
         // don't do this for an empty id array
         if (count($ids) > 0) {
             $namespace = WhereInWalker::PAGINATOR_ID_ALIAS;
             $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\\ORM\\Tools\\Pagination\\WhereInWalker'));
             $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, count($ids));
             $whereInQuery->setFirstResult(null)->setMaxResults(null);
             foreach ($ids as $i => $id) {
                 $i++;
                 $whereInQuery->setParameter("{$namespace}_{$i}", $id);
             }
         }
         $result = $whereInQuery->getResult($this->query->getHydrationMode());
     } else {
         $result = $this->cloneQuery($this->query)->setMaxResults($length)->setFirstResult($offset)->getResult($this->query->getHydrationMode());
     }
     return new \ArrayIterator($result);
 }
Exemplo n.º 2
0
 public function getResult()
 {
     $offset = $this->query->getFirstResult();
     $length = $this->query->getMaxResults();
     if ($this->fetchJoinCollection) {
         $subQuery = $this->cloneQuery($this->query);
         if ($this->useOutputWalker($subQuery)) {
             $subQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\\ORM\\Tools\\Pagination\\LimitSubqueryOutputWalker');
         } else {
             $this->appendTreeWalker($subQuery, 'Doctrine\\ORM\\Tools\\Pagination\\LimitSubqueryWalker');
         }
         $subQuery->setFirstResult($offset)->setMaxResults($length);
         $ids = array_map('current', $subQuery->getScalarResult());
         $whereInQuery = $this->cloneQuery($this->query);
         // don't do this for an empty id array
         if (count($ids) == 0) {
             return new \ArrayIterator(array());
         }
         $this->appendTreeWalker($whereInQuery, 'Doctrine\\ORM\\Tools\\Pagination\\WhereInWalker');
         $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, count($ids));
         $whereInQuery->setFirstResult(null)->setMaxResults(null);
         $whereInQuery->setParameter(WhereInWalker::PAGINATOR_ID_ALIAS, $ids);
         $whereInQuery->setCacheable($this->query->isCacheable());
         $result = $whereInQuery->getResult($this->query->getHydrationMode());
     } else {
         $result = $this->cloneQuery($this->query)->setMaxResults($length)->setFirstResult($offset)->setCacheable($this->query->isCacheable())->getResult($this->query->getHydrationMode());
     }
     return $result;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function getIterator()
 {
     $offset = $this->query->getFirstResult();
     $length = $this->query->getMaxResults();
     if ($this->fetchJoinCollection) {
         $subQuery = $this->cloneQuery($this->query);
         $subQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Pagerfanta\\Adapter\\DoctrineORM\\LimitSubqueryWalker'))->setFirstResult($offset)->setMaxResults($length);
         $ids = array_map('current', $subQuery->getScalarResult());
         $whereInQuery = $this->cloneQuery($this->query);
         // don't do this for an empty id array
         if (count($ids) > 0) {
             $namespace = 'pg_';
             $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Pagerfanta\\Adapter\\DoctrineORM\\WhereInWalker'));
             $whereInQuery->setHint('id.count', count($ids));
             $whereInQuery->setHint('pg.ns', $namespace);
             $whereInQuery->setFirstResult(null)->setMaxResults(null);
             foreach ($ids as $i => $id) {
                 $i++;
                 $whereInQuery->setParameter("{$namespace}_{$i}", $id);
             }
         }
         return new \ArrayIterator($whereInQuery->getResult($this->query->getHydrationMode()));
     }
     $result = $this->cloneQuery($this->query)->setMaxResults($length)->setFirstResult($offset)->getResult($this->query->getHydrationMode());
     return new \ArrayIterator($result);
 }
Exemplo n.º 4
0
 /**
  * SelectExpression ::=
  *      IdentificationVariable | StateFieldPathExpression |
  *      (AggregateExpression | "(" Subselect ")" | FunctionDeclaration) [["AS"] AliasResultVariable]
  *
  * @return \Doctrine\ORM\Query\AST\SelectExpression
  */
 public function SelectExpression()
 {
     $expression = null;
     $fieldAliasIdentificationVariable = null;
     $peek = $this->_lexer->glimpse();
     // First we recognize for an IdentificationVariable (DQL class alias)
     if ($peek['value'] != '.' && $peek['value'] != '(' && $this->_lexer->lookahead['type'] === Lexer::T_IDENTIFIER) {
         $expression = $this->IdentificationVariable();
     } else {
         if (($isFunction = $this->_isFunction()) !== false || $this->_isSubselect()) {
             if ($isFunction) {
                 if ($this->_isAggregateFunction($this->_lexer->lookahead['type'])) {
                     $expression = $this->AggregateExpression();
                 } else {
                     $expression = $this->FunctionDeclaration();
                 }
             } else {
                 $this->match(Lexer::T_OPEN_PARENTHESIS);
                 $expression = $this->Subselect();
                 $this->match(Lexer::T_CLOSE_PARENTHESIS);
             }
             if ($this->_lexer->isNextToken(Lexer::T_AS)) {
                 $this->match(Lexer::T_AS);
             }
             if ($this->_lexer->isNextToken(Lexer::T_IDENTIFIER)) {
                 $token = $this->_lexer->lookahead;
                 $fieldAliasIdentificationVariable = $this->AliasResultVariable();
                 // Include AliasResultVariable in query components.
                 $this->_queryComponents[$fieldAliasIdentificationVariable] = array('resultVariable' => $expression, 'nestingLevel' => $this->_nestingLevel, 'token' => $token);
             }
         } else {
             // Deny hydration of partial objects if doctrine.forcePartialLoad query hint not defined
             if ($this->_query->getHydrationMode() == Query::HYDRATE_OBJECT && !$this->_query->getHint(Query::HINT_FORCE_PARTIAL_LOAD)) {
                 throw DoctrineException::partialObjectsAreDangerous();
             }
             $expression = $this->StateFieldPathExpression();
         }
     }
     return new AST\SelectExpression($expression, $fieldAliasIdentificationVariable);
 }
 /**
  * @param Query $query
  *
  * @return string
  */
 public function getQueryCacheKey(Query $query)
 {
     $hints = $query->getHints();
     ksort($hints);
     return md5($query->getDql() . var_export($query->getParameters(), true) . var_export($hints, true) . '&firstResult=' . $query->getFirstResult() . '&maxResult=' . $query->getMaxResults() . '&hydrationMode=' . $query->getHydrationMode());
 }
Exemplo n.º 6
0
 public function fetch(Query $query, $mode = self::FETCH_ALL)
 {
     if ($mode == self::FETCH_ALL) {
         if ($query->getMaxResults() !== null && $query->getHydrationMode() != self::HYDRATE_SINGLE_SCALAR) {
             return (new Paginator($query))->getIterator()->getArrayCopy();
         } else {
             return $query->execute();
         }
     } else {
         if ($mode == self::FETCH_ALL_PAGED) {
             return new Paginator($query);
         } else {
             if ($mode == self::FETCH_ONE) {
                 $query->setMaxResults(1);
                 if ($query->getHydrationMode() != self::HYDRATE_SINGLE_SCALAR) {
                     return (new Paginator($query))->getIterator()->current();
                 } else {
                     return $query->getOneOrNullResult();
                 }
             } else {
                 if ($mode == self::FETCH_ONE_UNIQUE) {
                     return $query->getOneOrNullResult();
                 }
             }
         }
     }
 }