コード例 #1
0
 /**
  * {@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);
     }
 }
コード例 #2
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());
     }
 }
コード例 #3
0
ファイル: ExpressionBuilder.php プロジェクト: php-lug/lug
 /**
  * {@inheritdoc}
  */
 public function like($x, $y)
 {
     return $this->expr->like($x, $y);
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function like($x, $y, $withParam = false)
 {
     return $this->expr->like($x, $withParam ? ':' . $y : $y);
 }
コード例 #5
0
 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->contains('field', 'value'), $qb->like('o.field', ':field'), new Parameter('field', '%value%')), array($cb->eq('object.field', 'value'), $qb->eq('o.object.field', ':object_field'), new Parameter('object_field', 'value')), array($cb->eq('p.field', 'value'), $qb->eq('p.field', ':p_field'), new Parameter('p_field', 'value')), array($cb->eq('p.object.field', 'value'), $qb->eq('p.object.field', ':p_object_field'), new Parameter('p_object_field', 'value')));
 }
コード例 #6
0
ファイル: ExpressionBuilder.php プロジェクト: webowy/doctrine
 /**
  * @param $field
  * @param $value
  * @return \Doctrine\ORM\Query\Expr\Comparison
  */
 public function likeRight($field, $value)
 {
     return parent::like($field, $value);
 }
コード例 #7
0
ファイル: FilterOperator.php プロジェクト: ekyna/table
 /**
  * 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);
     }
 }
コード例 #8
0
 /**
  * @param string $x
  * @param mixed  $y
  *
  * @return \Doctrine\ORM\Query\Expr\Comparison
  * @author  Dominic Tubach <*****@*****.**>
  */
 public function like($x, $y)
 {
     return parent::like($x, $y . " ESCAPE '\\'");
 }
コード例 #9
0
ファイル: ExprTest.php プロジェクト: selimcr/servigases
 public function testLikeExpr()
 {
     $this->assertEquals('a.description LIKE :description', (string) $this->_expr->like('a.description', ':description'));
 }
コード例 #10
-1
ファイル: Filter.php プロジェクト: rezix/ZfcDatagrid
 /**
  * @param  DatagridFilter            $filter
  * @throws \InvalidArgumentException
  */
 public function applyFilter(DatagridFilter $filter)
 {
     $qb = $this->getQueryBuilder();
     $expr = new Expr();
     $column = $filter->getColumn();
     $colString = $column->getSelectPart1();
     if ($column->getSelectPart2() != '') {
         $colString .= '.' . $column->getSelectPart2();
     }
     if ($column instanceof Column\Select && $column->hasFilterSelectExpression()) {
         $colString = sprintf($column->getFilterSelectExpression(), $colString);
     }
     $values = $filter->getValues();
     $wheres = [];
     foreach ($values as $key => $value) {
         $valueParameterName = ':' . str_replace('.', '', $column->getUniqueId() . $key);
         switch ($filter->getOperator()) {
             case DatagridFilter::LIKE:
                 $wheres[] = $expr->like($colString, $valueParameterName);
                 $qb->setParameter($valueParameterName, '%' . $value . '%');
                 break;
             case DatagridFilter::LIKE_LEFT:
                 $wheres[] = $expr->like($colString, $valueParameterName);
                 $qb->setParameter($valueParameterName, '%' . $value);
                 break;
             case DatagridFilter::LIKE_RIGHT:
                 $wheres[] = $expr->like($colString, $valueParameterName);
                 $qb->setParameter($valueParameterName, $value . '%');
                 break;
             case DatagridFilter::NOT_LIKE:
                 $wheres[] = $expr->notLike($colString, $valueParameterName);
                 $qb->setParameter($valueParameterName, '%' . $value . '%');
                 break;
             case DatagridFilter::NOT_LIKE_LEFT:
                 $wheres[] = $expr->notLike($colString, $valueParameterName);
                 $qb->setParameter($valueParameterName, '%' . $value);
                 break;
             case DatagridFilter::NOT_LIKE_RIGHT:
                 $wheres[] = $expr->notLike($colString, $valueParameterName);
                 $qb->setParameter($valueParameterName, $value . '%');
                 break;
             case DatagridFilter::EQUAL:
                 $wheres[] = $expr->eq($colString, $valueParameterName);
                 $qb->setParameter($valueParameterName, $value);
                 break;
             case DatagridFilter::NOT_EQUAL:
                 $wheres[] = $expr->neq($colString, $valueParameterName);
                 $qb->setParameter($valueParameterName, $value);
                 break;
             case DatagridFilter::GREATER_EQUAL:
                 $wheres[] = $expr->gte($colString, $valueParameterName);
                 $qb->setParameter($valueParameterName, $value);
                 break;
             case DatagridFilter::GREATER:
                 $wheres[] = $expr->gt($colString, $valueParameterName);
                 $qb->setParameter($valueParameterName, $value);
                 break;
             case DatagridFilter::LESS_EQUAL:
                 $wheres[] = $expr->lte($colString, $valueParameterName);
                 $qb->setParameter($valueParameterName, $value);
                 break;
             case DatagridFilter::LESS:
                 $wheres[] = $expr->lt($colString, $valueParameterName);
                 $qb->setParameter($valueParameterName, $value);
                 break;
             case DatagridFilter::BETWEEN:
                 $minParameterName = ':' . str_replace('.', '', $colString . '0');
                 $maxParameterName = ':' . str_replace('.', '', $colString . '1');
                 $wheres[] = $expr->between($colString, $minParameterName, $maxParameterName);
                 $qb->setParameter($minParameterName, $values[0]);
                 $qb->setParameter($maxParameterName, $values[1]);
                 break 2;
             default:
                 throw new \InvalidArgumentException('This operator is currently not supported: ' . $filter->getOperator());
                 break;
         }
     }
     if (count($wheres) > 0) {
         $orWhere = $qb->expr()->orX();
         $orWhere->addMultiple($wheres);
         $qb->andWhere($orWhere);
     }
 }