Since: 1.0
Author: Jonathan H. Wage (jonwage@gmail.com)
 /**
  * @param Builder                $queryBuilder
  * @param ConditionNodeInterface $node
  * @param Expr                   $expr
  * @return null
  */
 protected function computeExpression(Builder $queryBuilder, ConditionNodeInterface $node, Expr $expr = null)
 {
     if (count($node->getFields()) == 0 && count($node->getChildren()) == 0) {
         return null;
     }
     $method = $node->getOperator() === ConditionNodeInterface::EXPR_AND ? 'addAnd' : 'addOr';
     $expression = null === $expr ? $queryBuilder : $expr;
     $count = 0;
     foreach ($node->getFields() as $condition) {
         if (null !== $condition) {
             /** @var ConditionInterface $condition */
             $expression->{$method}($condition->getExpression());
             $count++;
         }
     }
     foreach ($node->getChildren() as $child) {
         $subExpr = $queryBuilder->expr();
         $subCount = $this->computeExpression($queryBuilder, $child, $subExpr);
         if ($subCount > 0) {
             $expression->{$method}($subExpr);
             $count++;
         }
     }
     return $count;
 }
コード例 #2
0
 /**
  * filter
  *
  * Apply the query filter
  * 
  * @param  \Doctrine\MongoDB\Query\Builder $qb
  * @return \Doctrine\MongoDB\Query\Expr $expr
  */
 public function filter(Query\Builder $qb)
 {
     $qb->sort($this->fieldName, $this->fieldValue);
     if (null !== $this->spec) {
         return $this->spec->filter($qb);
     }
 }
コード例 #3
0
 /**
  * {inheritdoc}.
  */
 protected function applySorting(QueryBuilder $queryBuilder, array $sorting = null)
 {
     if (null === $sorting) {
         return;
     }
     foreach ($sorting as $property => $order) {
         $queryBuilder->sort($this->getPropertyName($property), $order);
     }
 }
コード例 #4
0
 /**
  * filter
  *
  * Filter the specification
  * 
  * @param  \Doctrine\MongoDB\Query\Builder $qb
  * @return \Doctrine\MongoDB\Query\Expr
  */
 public function filter(Query\Builder $qb)
 {
     $expr = $qb->expr();
     foreach ($this->specs as $spec) {
         if ($spec instanceof OdmSpecificationInterface) {
             $expr->addAnd($spec->filter($qb));
         }
     }
     return $expr;
 }
コード例 #5
0
 /**
  * @param \Doctrine\MongoDB\Query\Builder $queryBuilder
  * @param \Doctrine\ODM\MongoDB\Mapping\ClassMetadata $classMetadata
  * @return \Doctrine\MongoDB\Query\Builder
  */
 public function primeFields(Builder $queryBuilder, ClassMetadata $classMetadata)
 {
     $relationsConfig = $this->getRelations();
     foreach ($relationsConfig->getChildrenKeys() as $field) {
         if (!$this->canPrimeField($classMetadata, $field)) {
             continue;
         }
         $queryBuilder->field($field)->prime($this->createFieldPrimer([$field]));
     }
     return $queryBuilder;
 }
コード例 #6
0
 /**
  * Constructor.
  *
  * @param \Doctrine\MongoDB\Query\Builder $queryBuilder
  * @param null|\Staffim\DTOBundle\Collection\Pagination $pagination
  * @param null|\Staffim\DTOBundle\Collection\Sorting $sorting
  */
 public function __construct(Builder $queryBuilder, Pagination $pagination = null, Sorting $sorting = null)
 {
     $this->query = $queryBuilder->getQuery();
     $this->count = $this->query->count();
     if ($sorting || $pagination) {
         if ($sorting) {
             $queryBuilder->sort($sorting->fieldName, $sorting->order);
         }
         if ($pagination) {
             if ($pagination->limit) {
                 $queryBuilder->limit($pagination->limit);
             }
             if ($pagination->offset) {
                 $queryBuilder->skip($pagination->offset);
             }
             $this->pagination = $pagination;
         }
         $this->query = $queryBuilder->getQuery();
     }
 }
コード例 #7
0
 /**
  * @param QueryBuilder $queryBuilder
  * @param array        $sorting
  */
 protected function applySorting(QueryBuilder $queryBuilder, array $sorting = array())
 {
     foreach ($sorting as $property => $order) {
         $queryBuilder->sort($property, $order);
     }
 }
コード例 #8
0
 /**
  * filter
  *
  * Apply the specification filter
  * 
  * @param  \Doctrine\MongoDB\Query\Builder $qb
  * @return \Doctrine\MongoDB\Query\Expr
  */
 public function filter(Query\Builder $qb)
 {
     return $qb->expr()->field($this->fieldName)->gt($this->fieldValue);
 }
コード例 #9
0
ファイル: Builder.php プロジェクト: WilBenShu/digital_pilot
 /**
  * @param string $documentName
  * @return Builder
  */
 public function remove($documentName = null)
 {
     $this->setDocumentName($documentName);
     parent::remove();
     return $this;
 }
コード例 #10
0
 /**
  * filter
  *
  * Apply the query filter
  * 
  * @param  \Doctrine\MongoDB\Query\Builder $qb
  * @return \Doctrine\MongoDB\Query\Expr $expr
  */
 public function filter(Query\Builder $qb)
 {
     return $qb->expr()->sort($this->criteria);
 }
コード例 #11
0
 /**
  * Apply the query part to search for product where the completenesses
  * are missing. Apply only to the channel or product if provided.
  *
  * @param Builder          $productsQb
  * @param ProductInterface $product
  * @param ChannelInterface $channel
  */
 protected function applyFindMissingQuery(Builder $productsQb, ProductInterface $product = null, ChannelInterface $channel = null)
 {
     if (null !== $product) {
         $productsQb->field('_id')->equals($product->getId());
     } else {
         $combinations = $this->getChannelLocaleCombinations($channel);
         if (!empty($combinations)) {
             foreach ($combinations as $combination) {
                 $expr = new Expr();
                 $expr->field('normalizedData.completenesses.' . $combination)->exists(false);
                 $productsQb->addOr($expr);
             }
         }
     }
     $productsQb->field('family')->notEqual(null);
 }
コード例 #12
0
 /**
  * filter
  *
  * Apply the specification filter
  *
  * @param  \Doctrine\MongoDB\Query\Builder $qb
  * @return \Doctrine\MongoDB\Query\Expr
  */
 public function filter(Query\Builder $qb)
 {
     return $qb->expr()->field($this->fieldName)->includesReferenceTo($this->fieldValue);
 }
コード例 #13
0
 public function getQuery()
 {
     if ($this->type === self::TYPE_MAP_REDUCE) {
         $this->hydrate = false;
     }
     $query = $this->expr->getQuery();
     $query = $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name)->prepareQuery($query);
     $this->expr->setQuery($query);
     $query = parent::getQuery();
     return new Query($query, $this->dm, $this->class, $this->hydrate);
 }
コード例 #14
0
 /**
  * @inheritdoc
  */
 public function getObjects($offset, $limit)
 {
     return $this->qb->skip($offset)->limit($limit)->getQuery()->execute();
 }