public function execute(array $options = array())
    {
        $uow = $this->dm->getUnitOfWork();

        $results = $this->query->execute($options);

        // Convert the regular mongodb cursor to the odm cursor
        if ($results instanceof BaseCursor) {
            $cursor = $results->getMongoCursor();
            $results = new Cursor($cursor, $this->dm->getUnitOfWork(), $this->class);
            $results->hydrate($this->hydrate);
        }

        // GeoLocationFindQuery just returns an instance of ArrayIterator so we have to
        // iterator over it and hydrate each object.
        if ($this->query instanceof \Doctrine\MongoDB\Query\GeoLocationFindQuery && $this->hydrate) {
            foreach ($results as $key => $result) {
                $document = $result['obj'];
                if ($this->class->distance) {
                    $document[$this->class->distance] = $result['dis'];
                }
                $results[$key] = $uow->getOrCreateDocument($this->class->name, $document);
            }
            $results->reset();
        }

        if ($this->hydrate && ($this->query instanceof FindAndRemoveQuery || $this->query instanceof FindAndUpdateQuery) && is_array($results) && isset($results['_id'])) {
            // Convert a single document array to a document object
            $results = $uow->getOrCreateDocument($this->class->name, $results);
        }

        return $results;
    }
Beispiel #2
0
 /**
  * Execute the query and returns the results.
  *
  * @return mixed
  */
 public function execute()
 {
     $uow = $this->dm->getUnitOfWork();
     $results = parent::execute();
     // Convert the regular mongodb cursor to the odm cursor
     if ($results instanceof BaseCursor) {
         $cursor = $results->getMongoCursor();
         $results = new Cursor($cursor, $this->dm->getUnitOfWork(), $this->class);
         $results->hydrate($this->hydrate);
         $results->refresh($this->refresh);
     }
     $hints = array();
     if ($this->refresh) {
         $hints[self::HINT_REFRESH] = true;
     }
     // GeoLocationFindQuery just returns an instance of ArrayIterator so we have to
     // iterator over it and hydrate each object.
     if ($this->query['type'] === self::TYPE_GEO_LOCATION && $this->hydrate) {
         foreach ($results as $key => $result) {
             $document = $result['obj'];
             if ($this->class->distance) {
                 $document[$this->class->distance] = $result['dis'];
             }
             $results[$key] = $uow->getOrCreateDocument($this->class->name, $document, $hints);
         }
         $results->reset();
     }
     if ($this->hydrate && is_array($results) && isset($results['_id'])) {
         // Convert a single document array to a document object
         $results = $uow->getOrCreateDocument($this->class->name, $results, $hints);
     }
     return $results;
 }