/**
  * @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
 /**
  * @param DoctrineQueryBuilderAdapter $queryBuilder
  * @param ConditionNodeInterface      $node
  * @return Composite|CompositeExpression|null
  */
 protected function computeExpression(DoctrineQueryBuilderAdapter $queryBuilder, ConditionNodeInterface $node)
 {
     if (count($node->getFields()) == 0 && count($node->getChildren()) == 0) {
         return null;
     }
     $method = $node->getOperator() == ConditionNodeInterface::EXPR_AND ? 'andX' : 'orX';
     $expression = $queryBuilder->{$method}();
     foreach ($node->getFields() as $condition) {
         if (null !== $condition) {
             /** @var ConditionInterface $condition */
             $expression->add($condition->getExpression());
             $this->parameters = array_merge($this->parameters, $condition->getParameters());
         }
     }
     foreach ($node->getChildren() as $child) {
         $subExpr = $this->computeExpression($queryBuilder, $child);
         if (null !== $subExpr && $subExpr->count()) {
             $expression->add($subExpr);
         }
     }
     return $expression->count() ? $expression : null;
 }