Beispiel #1
0
 /**
  * Add filtering onto specified column
  * @param string column name
  * @param string filter
  * @param string|array operation mode
  * @param string chain type (if third argument is array)
  * @throws \InvalidArgumentException
  * @return IDataSource
  */
 public function filter($column, $operation = IDataSource::EQUAL, $value = NULL, $chainType = NULL)
 {
     if (!$this->hasColumn($column)) {
         throw new \InvalidArgumentException('Trying to filter data source by unknown column.');
     }
     if (is_array($operation)) {
         if ($chainType !== self::CHAIN_AND && $chainType !== self::CHAIN_OR) {
             throw new \InvalidArgumentException('Invalid chain operation type.');
         }
         $conds = array();
         foreach ($operation as $t) {
             $this->validateFilterOperation($t);
             if ($t === self::IS_NULL || $t === self::IS_NOT_NULL) {
                 $conds[] = array('%n', $this->mapping[$column], $t);
             } else {
                 $modifier = is_double($value) ? dibi::FLOAT : dibi::TEXT;
                 if ($operation === self::LIKE || $operation === self::NOT_LIKE) {
                     $value = DataSources\Utils\WildcardHelper::formatLikeStatementWildcards($value);
                 }
                 $conds[] = array('%n', $this->mapping[$column], $t, '%' . $modifier, $value);
             }
         }
         if ($chainType === self::CHAIN_AND) {
             foreach ($conds as $cond) {
                 $this->df->where($cond);
             }
         } elseif ($chainType === self::CHAIN_OR) {
             $this->df->where('%or', $conds);
         }
     } else {
         $this->validateFilterOperation($operation);
         if ($operation === self::IS_NULL || $operation === self::IS_NOT_NULL) {
             $this->qb->where('%n', $this->mapping[$column], $operation);
         } else {
             $modifier = is_double($value) ? dibi::FLOAT : dibi::TEXT;
             if ($operation === self::LIKE || $operation === self::NOT_LIKE) {
                 $value = DataSources\Utils\WildcardHelper::formatLikeStatementWildcards($value);
             }
             $this->df->where('%n', $this->mapping[$column], $operation, '%' . $modifier, $value);
         }
     }
     return $this;
 }
Beispiel #2
0
 /**
  * Filter items in data source
  * @param string $column
  * @param string $operation
  * @param string $value
  * @param string $chainType
  * @return QueryBuilder
  */
 public function filter($column, $operation = self::EQUAL, $value = NULL, $chainType = NULL)
 {
     if (!$this->hasColumn($column)) {
         throw new \InvalidArgumentException('Trying to filter data source by unknown column.');
     }
     $nextParamId = count($this->qb->getParameters()) + 1;
     if (is_array($operation)) {
         if ($chainType !== self::CHAIN_AND && $chainType !== self::CHAIN_OR) {
             throw new \InvalidArgumentException('Invalid chain operation type.');
         }
         $conds = array();
         foreach ($operation as $t) {
             $this->validateFilterOperation($t);
             if ($t === self::IS_NULL || $t === self::IS_NOT_NULL) {
                 $conds[] = "{$this->mapping[$column]} {$t}";
             } else {
                 $conds[] = "{$this->mapping[$column]} {$t} ?{$nextParamId}";
                 $this->qb->setParameter($nextParamId++, $t === self::LIKE || $t === self::NOT_LIKE ? WildcardHelper::formatLikeStatementWildcards($value) : $value);
             }
         }
         if ($chainType === self::CHAIN_AND) {
             foreach ($conds as $cond) {
                 $this->qb->andWhere($cond);
             }
         } elseif ($chainType === self::CHAIN_OR) {
             $this->qb->andWhere(new Expr\Orx($conds));
         }
     } else {
         $this->validateFilterOperation($operation);
         if ($operation === self::IS_NULL || $operation === self::IS_NOT_NULL) {
             $this->qb->andWhere("{$this->mapping[$column]} {$operation}");
         } else {
             $this->qb->andWhere("{$this->mapping[$column]} {$operation} ?{$nextParamId}");
             $this->qb->setParameter($nextParamId, $operation === self::LIKE || $operation === self::NOT_LIKE ? WildcardHelper::formatLikeStatementWildcards($value) : $value);
         }
     }
     return $this;
 }