Ejemplo n.º 1
1
 public function comparisonData()
 {
     $cb = new CriteriaBuilder();
     $qb = new QueryBuilder();
     return array(array($cb->eq('field', 'value'), $qb->eq('o.field', ':field'), new Parameter('field', 'value')), array($cb->neq('field', 'value'), $qb->neq('o.field', ':field'), new Parameter('field', 'value')), array($cb->eq('field', null), $qb->isNull('o.field')), array($cb->neq('field', null), $qb->isNotNull('o.field')), array($cb->isNull('field'), $qb->isNull('o.field')), array($cb->gt('field', 'value'), $qb->gt('o.field', ':field'), new Parameter('field', 'value')), array($cb->gte('field', 'value'), $qb->gte('o.field', ':field'), new Parameter('field', 'value')), array($cb->lt('field', 'value'), $qb->lt('o.field', ':field'), new Parameter('field', 'value')), array($cb->lte('field', 'value'), $qb->lte('o.field', ':field'), new Parameter('field', 'value')), array($cb->in('field', array('value')), $qb->in('o.field', ':field'), new Parameter('field', array('value'))), array($cb->notIn('field', array('value')), $qb->notIn('o.field', ':field'), new Parameter('field', array('value'))), array($cb->eq('object.field', 'value'), $qb->eq('o.object.field', ':object_field'), new Parameter('object_field', 'value')));
 }
 /**
  * {@inheritdoc}
  */
 protected function doWalkComparison($fieldName, $operator, $placeholder)
 {
     switch ($operator) {
         case Comparison::IN:
             return $this->expr->in($fieldName, $placeholder);
         case Comparison::NIN:
             return $this->expr->notIn($fieldName, $placeholder);
         case Comparison::EQ:
         case Comparison::IS:
             if ($placeholder === null) {
                 return $this->expr->isNull($fieldName);
             }
             return $this->expr->eq($fieldName, $placeholder);
         case Comparison::NEQ:
             if ($placeholder === null) {
                 return $this->expr->isNotNull($fieldName);
             }
             return $this->expr->neq($fieldName, $placeholder);
         case Comparison::CONTAINS:
             return $this->expr->like($fieldName, $placeholder);
         default:
             $operator = self::convertComparisonOperator($operator);
             if ($operator) {
                 return new Expr\Comparison($fieldName, $operator, $placeholder);
             }
             throw new \RuntimeException("Unknown comparison operator: " . $operator);
     }
 }
Ejemplo n.º 3
0
 /**
  * {@inheritDoc}
  */
 public function walkComparison(Comparison $comparison)
 {
     $parameterName = str_replace('.', '_', $comparison->getField());
     $parameter = new Parameter($parameterName, $this->walkValue($comparison->getValue()));
     $placeholder = ':' . $parameterName;
     switch ($comparison->getOperator()) {
         case Comparison::IN:
             $this->parameters[] = $parameter;
             return $this->expr->in($this->rootAlias . '.' . $comparison->getField(), $placeholder);
         case Comparison::NIN:
             $this->parameters[] = $parameter;
             return $this->expr->notIn($this->rootAlias . '.' . $comparison->getField(), $placeholder);
         case Comparison::EQ:
         case Comparison::IS:
             if ($this->walkValue($comparison->getValue()) === null) {
                 return $this->expr->isNull($this->rootAlias . '.' . $comparison->getField());
             }
             $this->parameters[] = $parameter;
             return $this->expr->eq($this->rootAlias . '.' . $comparison->getField(), $placeholder);
         case Comparison::NEQ:
             if ($this->walkValue($comparison->getValue()) === null) {
                 return $this->expr->isNotNull($this->rootAlias . '.' . $comparison->getField());
             }
             $this->parameters[] = $parameter;
             return $this->expr->neq($this->rootAlias . '.' . $comparison->getField(), $placeholder);
         default:
             $operator = self::convertComparisonOperator($comparison->getOperator());
             if ($operator) {
                 $this->parameters[] = $parameter;
                 return new Expr\Comparison($this->rootAlias . '.' . $comparison->getField(), $operator, $placeholder);
             }
             throw new \RuntimeException("Unknown comparison operator: " . $comparison->getOperator());
     }
 }
Ejemplo n.º 4
0
 /**
  * {@inheritDoc}
  */
 public function walkComparison(Comparison $comparison)
 {
     if (!isset($this->queryAliases[0])) {
         throw new QueryException('No aliases are set before invoking walkComparison().');
     }
     $field = $this->queryAliases[0] . '.' . $comparison->getField();
     foreach ($this->queryAliases as $alias) {
         if (strpos($comparison->getField() . '.', $alias . '.') === 0) {
             $field = $comparison->getField();
             break;
         }
     }
     $parameterName = str_replace('.', '_', $comparison->getField());
     foreach ($this->parameters as $parameter) {
         if ($parameter->getName() === $parameterName) {
             $parameterName .= '_' . count($this->parameters);
             break;
         }
     }
     $parameter = new Parameter($parameterName, $this->walkValue($comparison->getValue()));
     $placeholder = ':' . $parameterName;
     switch ($comparison->getOperator()) {
         case Comparison::IN:
             $this->parameters[] = $parameter;
             return $this->expr->in($field, $placeholder);
         case Comparison::NIN:
             $this->parameters[] = $parameter;
             return $this->expr->notIn($field, $placeholder);
         case Comparison::EQ:
         case Comparison::IS:
             if ($this->walkValue($comparison->getValue()) === null) {
                 return $this->expr->isNull($field);
             }
             $this->parameters[] = $parameter;
             return $this->expr->eq($field, $placeholder);
         case Comparison::NEQ:
             if ($this->walkValue($comparison->getValue()) === null) {
                 return $this->expr->isNotNull($field);
             }
             $this->parameters[] = $parameter;
             return $this->expr->neq($field, $placeholder);
         case Comparison::CONTAINS:
             $parameter->setValue('%' . $parameter->getValue() . '%', $parameter->getType());
             $this->parameters[] = $parameter;
             return $this->expr->like($field, $placeholder);
         default:
             $operator = self::convertComparisonOperator($comparison->getOperator());
             if ($operator) {
                 $this->parameters[] = $parameter;
                 return new Expr\Comparison($field, $operator, $placeholder);
             }
             throw new \RuntimeException("Unknown comparison operator: " . $comparison->getOperator());
     }
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function notIn($x, $y)
 {
     return $this->expr->notIn($x, $y);
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function notIn($x, $y, $withParam = false)
 {
     return $this->expr->notIn($x, $withParam ? ':' . $y : $y);
 }
Ejemplo n.º 7
0
 /**
  * Builds the orm expression.
  *
  * @param string $property
  * @param string $operator
  * @param string $parameter
  * @return Expr\Comparison|Expr\Func
  */
 public static function buildExpression($property, $operator, $parameter = null)
 {
     self::isValid($operator, true);
     $expr = new Expr();
     switch (intval($operator)) {
         case self::NOT_EQUAL:
             return $expr->neq($property, $parameter);
         case self::LOWER_THAN:
             return $expr->lt($property, $parameter);
         case self::LOWER_THAN_OR_EQUAL:
             return $expr->lte($property, $parameter);
         case self::GREATER_THAN:
             return $expr->gt($property, $parameter);
         case self::GREATER_THAN_OR_EQUAL:
             return $expr->gte($property, $parameter);
         case self::IN:
             return $expr->in($property, $parameter);
         case self::NOT_IN:
             return $expr->notIn($property, $parameter);
         case self::LIKE:
             return $expr->like($property, $parameter);
         case self::NOT_LIKE:
             return $expr->notLike($property, $parameter);
         case self::START_WITH:
             return $expr->like($property, $parameter);
         case self::NOT_START_WITH:
             return $expr->notLike($property, $parameter);
         case self::END_WITH:
             return $expr->like($property, $parameter);
         case self::NOT_END_WITH:
             return $expr->notLike($property, $parameter);
         case self::IS_NULL:
             return $expr->isNull($property);
         case self::IS_NOT_NULL:
             return $expr->isNotNull($property);
         default:
             return $expr->eq($property, $parameter);
     }
 }
Ejemplo n.º 8
0
 public function testNotInLiteralExpr()
 {
     $this->assertEquals("u.type NOT IN('foo', 'bar')", (string) $this->_expr->notIn('u.type', array('foo', 'bar')));
 }
 function it_adds_a_not_in_filter_to_the_query($qb, $attrValidatorHelper, AttributeInterface $attribute, EntityManager $em, QueryBuilder $notInQb, Expr $expr, Expr\Func $notInFunc, Expr\Func $inFunc, Expr\Func $whereFunc)
 {
     $attrValidatorHelper->validateLocale($attribute, Argument::any())->shouldBeCalled();
     $attrValidatorHelper->validateScope($attribute, Argument::any())->shouldBeCalled();
     $attribute->getId()->willReturn(42);
     $attribute->isLocalizable()->willReturn(false);
     $attribute->isScopable()->willReturn(false);
     $attribute->getBackendType()->willReturn('options');
     $attribute->getCode()->willReturn('options_code');
     $qb->getRootAlias()->willReturn('r');
     $expr->notIn(Argument::containingString('filterOoptions_code'), [10, 12])->shouldBeCalled()->willReturn($notInFunc);
     $qb->innerJoin(Argument::cetera())->willReturn($qb);
     $qb->getEntityManager()->willReturn($em);
     $qb->getRootEntities()->willReturn(['ProductClassName']);
     $em->createQueryBuilder()->willReturn($notInQb);
     $notInQb->select(Argument::containingString('.id'))->shouldBeCalled()->willReturn($notInQb);
     $notInQb->from('ProductClassName', Argument::any(), Argument::containingString('.id'))->shouldBeCalled()->willReturn($notInQb);
     $notInQb->getRootAlias()->willReturn('ep');
     $notInQb->innerJoin('ep.values', Argument::containingString('filteroptions_code'), 'WITH', Argument::any())->shouldBeCalled()->willReturn($notInQb);
     $notInQb->innerJoin(Argument::containingString('filteroptions_code'), Argument::containingString('filterOoptions_code'))->shouldBeCalled()->willReturn($notInQb);
     $notInQb->expr()->willReturn($expr);
     $expr->in(Argument::containingString('.id'), [10, 12])->shouldBeCalled()->willReturn($inFunc);
     $notInQb->where($inFunc)->shouldBeCalled();
     $notInQb->getDQL()->willReturn('excluded products DQL');
     $qb->expr()->willReturn($expr);
     $expr->notIn('r.id', 'excluded products DQL')->shouldBeCalled()->willReturn($whereFunc);
     $qb->andWhere($whereFunc)->shouldBeCalled();
     $this->addAttributeFilter($attribute, 'NOT IN', [10, 12], null, null, ['field' => 'options_code.id']);
 }