/** * @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; }
/** * 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); } }
/** * {inheritdoc}. */ protected function applySorting(QueryBuilder $queryBuilder, array $sorting = null) { if (null === $sorting) { return; } foreach ($sorting as $property => $order) { $queryBuilder->sort($this->getPropertyName($property), $order); } }
/** * 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; }
/** * @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; }
/** * 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(); } }
/** * @param QueryBuilder $queryBuilder * @param array $sorting */ protected function applySorting(QueryBuilder $queryBuilder, array $sorting = array()) { foreach ($sorting as $property => $order) { $queryBuilder->sort($property, $order); } }
/** * 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); }
/** * @param string $documentName * @return Builder */ public function remove($documentName = null) { $this->setDocumentName($documentName); parent::remove(); return $this; }
/** * 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); }
/** * 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); }
/** * 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); }
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); }
/** * @inheritdoc */ public function getObjects($offset, $limit) { return $this->qb->skip($offset)->limit($limit)->getQuery()->execute(); }