Example #1
0
 /**
  * @param int|null
  * @return \ArrayIterator
  */
 public function getIterator($hydrationMode = NULL)
 {
     if ($this->iterator !== NULL) {
         return $this->iterator;
     }
     if ($hydrationMode !== NULL) {
         $this->query->setHydrationMode($hydrationMode);
     }
     $this->frozen = TRUE;
     if ($this->fetchJoinCollection && ($this->query->getMaxResults() > 0 || $this->query->getFirstResult() > 0)) {
         $this->iterator = $this->createPaginatedQuery($this->query)->getIterator();
     } else {
         $this->iterator = new \ArrayIterator($this->query->getResult(NULL));
     }
     if ($this->repository && $this->queryObject) {
         $this->queryObject->queryFetched($this->repository, $this->iterator);
     }
     return $this->iterator;
 }
Example #2
0
 /**
  * @param int $hydrationMode
  * @throws QueryException
  * @return \ArrayIterator
  */
 public function getIterator($hydrationMode = ORM\AbstractQuery::HYDRATE_OBJECT)
 {
     if ($this->iterator !== NULL) {
         return $this->iterator;
     }
     $this->query->setHydrationMode($hydrationMode);
     try {
         $this->frozen = TRUE;
         if ($this->fetchJoinCollection && ($this->query->getMaxResults() > 0 || $this->query->getFirstResult() > 0)) {
             $this->iterator = $this->createPaginatedQuery($this->query)->getIterator();
         } else {
             $this->iterator = new \ArrayIterator($this->query->getResult(NULL));
         }
         if ($this->queryObject !== NULL && $this->repository !== NULL) {
             $this->queryObject->postFetch($this->repository, $this->iterator);
         }
         return $this->iterator;
     } catch (ORMException $e) {
         throw new QueryException($e, $this->query, $e->getMessage());
     }
 }
 /**
  * @return Query
  * @throws \LogicException If source of a query is not valid
  */
 protected function getQuery()
 {
     if (null === $this->query) {
         if ($this->source instanceof Query) {
             $this->query = $this->cloneQuery($this->source);
         } elseif ($this->source instanceof QueryBuilder) {
             $this->query = $this->source->getQuery();
         } else {
             throw new \LogicException('Unexpected source');
         }
         unset($this->source);
         // initialize cloned query
         $this->maxResults = $this->query->getMaxResults();
         if (!$this->maxResults || $this->requestedBufferSize < $this->maxResults) {
             $this->query->setMaxResults($this->requestedBufferSize);
         }
         if (null !== $this->requestedHydrationMode) {
             $this->query->setHydrationMode($this->requestedHydrationMode);
         }
         $this->firstResult = (int) $this->query->getFirstResult();
     }
     return $this->query;
 }
 /**
  * Loads all translations with all translatable
  * fields from the given entity
  * 
  * @link https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/translatable.md#entity-domain-object
  *
  * @param Query   $query
  * @param string  $locale
  * @param string  $result = {'array', 'object'}
  * @param boolean $INNER_JOIN
  * @param boolean $FALLBACK
  * @param boolean $lazy_loading
  *      
  * @return Query   
  * @access public
  * @author Etienne de Longeaux <*****@*****.**>
  */
 public function setTranslatableHints(Query $query, $locale, $INNER_JOIN = false, $FALLBACK = true, $lazy_loading = true)
 {
     // BE CARFULL ::: Strange Issue with Query Hint and APC
     $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
     // if you use memcache or apc. You should set locale and other options like fallbacks to query through hints. Otherwise the query will be cached with a first used locale
     $query->setHint(\Gedmo\Translatable\TranslatableListener::HINT_TRANSLATABLE_LOCALE, $locale);
     // take locale from session or request etc.
     if ($INNER_JOIN) {
         $query->setHint(\Gedmo\Translatable\TranslatableListener::HINT_INNER_JOIN, $INNER_JOIN);
         // will use INNER joins for translations instead of LEFT joins, so that in case if you do not want untranslated records in your result set for instance.
     }
     if (!$lazy_loading) {
         // to avoid lazy-loading.
         $query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true);
     }
     $query->setHint(\Gedmo\Translatable\TranslatableListener::HINT_FALLBACK, $FALLBACK);
     // fallback to default values in case if record is not translated
     //        $config = $this->container->get('doctrine')->getManager()->getConfiguration();
     //        if ($config->getCustomHydrationMode(TranslationWalker::HYDRATE_OBJECT_TRANSLATION) === null) {
     //            $config->addCustomHydrationMode(
     //                TranslationWalker::HYDRATE_OBJECT_TRANSLATION,
     //                'Gedmo\\Translatable\\Hydrator\\ORM\\ObjectHydrator'
     //            );
     //        }
     $query->setHydrationMode(\Gedmo\Translatable\Query\TreeWalker\TranslationWalker::HYDRATE_OBJECT_TRANSLATION);
     $query->setHint(Query::HINT_REFRESH, true);
     return $query;
 }