createQuery() public method

Create a Query for the view in the specified design document.
public createQuery ( string $designDocName, string $viewName ) : ODMQuery
$designDocName string
$viewName string
return Doctrine\ODM\CouchDB\View\ODMQuery
Exemplo n.º 1
0
 public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 {
     if (count($criteria) == 1) {
         foreach ($criteria as $field => $value) {
             $query = $this->dm->createQuery('doctrine_repositories', 'equal_constraint')->setKey(array($this->documentType, $field, $value))->setIncludeDocs(true)->toArray(true);
             if ($limit) {
                 $query->setLimit($limit);
             }
             if ($offset) {
                 $query->setSkip($offset);
             }
             return $query->execute();
         }
     } else {
         $ids = array();
         $num = 0;
         foreach ($criteria as $field => $value) {
             $ids[$num] = array();
             $result = $this->dm->createNativeQuery('doctrine_repositories', 'equal_constraint')->setKey(array($this->documentType, $field, $value))->execute();
             foreach ($result as $doc) {
                 $ids[$num][] = $doc['id'];
             }
             $num++;
         }
         $mergeIds = $ids[0];
         for ($i = 1; $i < $num; $i++) {
             $mergeIds = array_intersect($mergeIds, $ids[$i]);
         }
         return $this->findMany(array_values($mergeIds), $limit, $offset);
     }
 }
 /**
  * @param string $designDocumentName
  * @param string $constraint
  * @param string $type
  * @return \Doctrine\CouchDB\View\AbstractQuery
  */
 public function createQuery($designDocumentName = 'doctrine_repositories', $constraint = 'equal_constraint', $type = NULL)
 {
     switch ($type) {
         case 'lucene':
             return $this->documentManager->createLuceneQuery($designDocumentName, $constraint);
         case 'native':
             return $this->documentManager->createNativeQuery($designDocumentName, $constraint);
         default:
             return $this->documentManager->createQuery($designDocumentName, $constraint);
     }
 }