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);
     }
 }
 function it_does_not_try_to_join_attributes_when_finding_full_products_with_empty_attributes($em, QueryBuilder $queryBuilder, Expr $expr, AbstractQuery $query)
 {
     $expr->in('p.id', [42])->shouldBeCalled()->willReturn('product where clause');
     $expr->in('a.id', Argument::any())->shouldNotBeCalled();
     $queryBuilder->select(Argument::any())->shouldBeCalled()->willReturn($queryBuilder);
     $queryBuilder->addSelect(Argument::any())->shouldBeCalled()->willReturn($queryBuilder);
     $queryBuilder->from(Argument::any(), Argument::any())->shouldBeCalled()->willReturn($queryBuilder);
     $queryBuilder->leftJoin(Argument::any(), Argument::any())->shouldBeCalled()->willReturn($queryBuilder);
     $queryBuilder->where('product where clause')->shouldBeCalled()->willReturn($queryBuilder);
     $queryBuilder->andWhere(Argument::any())->shouldNotBeCalled();
     $em->createQueryBuilder()->willReturn($queryBuilder);
     $query->execute()->shouldBeCalled();
     $queryBuilder->expr()->willReturn($expr);
     $queryBuilder->getQuery()->willReturn($query);
     $this->getFullProducts([42]);
 }
 /**
  * {@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());
     }
 }
 function it_adds_a_in_filter_on_a_field_in_the_query($qb, Expr $expr)
 {
     $qb->getRootAlias()->willReturn('f');
     $qb->leftJoin('f.family', 'filterfamily')->willReturn($qb);
     $qb->andWhere('filterfamily.id IN (1, 2)')->willReturn($qb);
     $expr->in('filterfamily.id', [1, 2])->willReturn('filterfamily.id IN (1, 2)');
     $qb->expr()->willReturn($expr);
     $this->addFieldFilter('family', 'IN', [1, 2]);
 }
 function it_adds_a_in_filter_on_a_field_in_the_query($qb, Expr $expr)
 {
     $qb->getRootAlias()->willReturn('f');
     $qb->leftJoin('f.groups', Argument::any())->willReturn($qb);
     $qb->andWhere('filtergroups.id IN (1, 2)')->willReturn($qb);
     $expr->in(Argument::any(), [1, 2])->willReturn('filtergroups.id IN (1, 2)');
     $qb->expr()->willReturn($expr);
     $this->addFieldFilter('groups', 'IN', [1, 2]);
 }
 /**
  * {@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());
     }
 }
Beispiel #8
0
 /**
  * {@inheritdoc}
  */
 public function in($x, $y)
 {
     return $this->expr->in($x, $y);
 }
 /**
  * {@inheritdoc}
  */
 public function in($x, $y, $withParam = false)
 {
     return $this->expr->in($x, $withParam ? ':' . $y : $y);
 }
Beispiel #10
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);
     }
 }
Beispiel #11
0
 public function testInLiteralExpr()
 {
     $this->assertEquals("u.type IN('foo', 'bar')", (string) $this->_expr->in('u.type', array('foo', 'bar')));
 }