Ejemplo n.º 1
0
 /**
  * Adds filter criteria to an already-prepared query.
  *
  * This method should be used once for query criteria and not be used for
  * nested expressions. It should be called after
  * {@link DocumentPerister::addDiscriminatorToPreparedQuery()}.
  *
  * @param array $preparedQuery
  * @return array
  */
 public function addFilterToPreparedQuery(array $preparedQuery)
 {
     /* If filter criteria exists for this class, prepare it and merge
      * over the existing query.
      *
      * @todo Consider recursive merging in case the filter criteria and
      * prepared query both contain top-level $and/$or operators.
      */
     if ($filterCriteria = $this->dm->getFilterCollection()->getFilterCriteria($this->class)) {
         $preparedQuery = $this->cm->merge($preparedQuery, $this->prepareQueryOrNewObj($filterCriteria));
     }
     return $preparedQuery;
 }
Ejemplo n.º 2
0
 /**
  * @param PersistentCollection $collection
  * @param array $groupedIds
  *
  * @throws \Doctrine\ODM\MongoDB\MongoDBException
  */
 private function loadActualDataForSortedReferenceManyCollectionByIds(PersistentCollection $collection, array $groupedIds)
 {
     $mapping = $collection->getMapping();
     $hints = $collection->getHints();
     foreach ($groupedIds as $className => $ids) {
         $class = $this->dm->getClassMetadata($className);
         $mongoCollection = $this->dm->getDocumentCollection($className);
         $criteria = $this->cm->merge(array('_id' => array('$in' => array_values($ids))), $this->dm->getFilterCollection()->getFilterCriteria($class), isset($mapping['criteria']) ? $mapping['criteria'] : array());
         $criteria = $this->uow->getDocumentPersister($className)->prepareQueryOrNewObj($criteria);
         $cursor = $mongoCollection->find($criteria);
         if (isset($mapping['sort'])) {
             $cursor->sort($mapping['sort']);
         }
         if (isset($mapping['limit'])) {
             $cursor->limit($mapping['limit']);
         }
         if (isset($mapping['skip'])) {
             $cursor->skip($mapping['skip']);
         }
         if (!empty($hints[Query::HINT_SLAVE_OKAY])) {
             $cursor->slaveOkay(true);
         }
         if (!empty($hints[Query::HINT_READ_PREFERENCE])) {
             $cursor->setReadPreference($hints[Query::HINT_READ_PREFERENCE], $hints[Query::HINT_READ_PREFERENCE_TAGS]);
         }
         $documents = $cursor->toArray(false);
         foreach ($documents as $documentData) {
             $docId = $documentData['_id'];
             $document = $this->uow->getById($docId, $class);
             $data = $this->hydratorFactory->hydrate($document, $documentData);
             $this->uow->setOriginalDocumentData($document, $data);
             $document->__isInitialized__ = true;
             $collection->add($document);
         }
     }
 }