52 $this->
logic = static::LOGIC_AND;
70 if (!in_array(strtolower(
$logic), [static::LOGIC_AND, static::LOGIC_OR],
true))
89 $this->isNegative = $negative;
125 $this->conditions[] =
$filter[0];
132 $this->conditions[] =
$filter[0];
139 foreach (
$filter[0] as $condition)
142 call_user_func_array(array($this,
'where'), $condition);
151 list($column, $operator, $value) =
$filter;
156 list($column, $value) =
$filter;
173 if (!isset($operators[$operator]))
179 $this->conditions[] =
new Condition($column, $operator, $value);
196 $subFilter =
new static();
197 call_user_func_array(array($subFilter,
'where'),
$filter);
199 $this->conditions[] = $subFilter->negative();
218 list($column, $operator, $value) =
$filter;
222 list($column, $value) =
$filter;
234 $this->
where($column, $operator, $value);
248 $this->conditions[] =
new Condition($column,
'=',
null);
262 $this->conditions[] =
new Condition($column,
'<>',
null);
277 $this->conditions[] =
new Condition($column,
'in', $values);
293 $subFilter =
new static();
294 $this->conditions[] = $subFilter->whereIn($column, $values)->negative();
310 $this->conditions[] =
new Condition($column,
'between', array($valueMin, $valueMax));
327 $subFilter =
new static();
328 $this->conditions[] = $subFilter->whereBetween($column, $valueMin, $valueMax)->negative();
343 $this->conditions[] =
new Condition($column,
'like', $value);
359 $subFilter =
new static();
360 $this->conditions[] = $subFilter->whereLike($column, $value)->negative();
374 $this->conditions[] =
new Condition(
null,
'exists', $query);
392 $subFilter =
new static();
393 $this->conditions[] = $subFilter->whereExists($query)->negative();
412 $this->conditions[] =
new Condition($column,
'match', $value);
428 $subFilter =
new static();
429 $this->conditions[] = $subFilter->whereMatch($column, $value)->negative();
451 foreach ($this->conditions as $condition)
456 $subFilter = $condition;
457 $sql = $subFilter->getSql(
$chains);
459 if (count($subFilter->getConditions()) > 1)
467 $columnSqlDefinition =
null;
471 if ($condition->getColumn() !==
null)
473 $chain =
$chains[$condition->getDefinition()];
474 $columnSqlDefinition = $chain->getSqlDefinition();
477 $columnField = $chain->getLastElement()->getValue();
481 if (in_array($condition->getOperator(), array(
'in',
'between'),
true) && is_array($condition->getValue()))
484 $finalValue = $this->
convertValues($condition->getValue(), $columnField);
488 $finalValue = $this->
convertValue($condition->getValue(), $columnField);
493 $operator = $operators[$condition->getOperator()];
496 $sql = call_user_func(
497 array(
'Bitrix\Main\ORM\Query\Filter\Operator', $operator),
498 $columnSqlDefinition, $finalValue
506 $sql = join(
" ".strtoupper($this->
logic).
" ", $finalSql);
509 if ($this->isNegative)
511 $sql = count($finalSql) > 1 ?
"NOT ({$sql})" :
"NOT {$sql}";
539 $this->conditions[] = $condition;
553 return !empty($this->conditions);
566 foreach ($this->conditions as $k => $condition)
568 if ($condition === $currentCondition)
570 $this->conditions[$k] = $newCondition;
587 foreach ($this->conditions as $k => $_condition)
589 if ($condition === $_condition)
591 unset($this->conditions[$k]);
604 $this->conditions = [];
622 return $value->compile();
626 if ($value instanceof
Query)
628 return $value->getQuery();
634 return $value->getSql($this->chains);
646 $valueChain = $this->chains[$value->getDefinition()];
647 return $valueChain->getSqlDefinition();
650 return $field->convertValueToDb($value);
666 foreach ($values as $k => $value)
676 $newConditions = array();
678 foreach ($this->conditions as $condition)
680 $newConditions[] = clone $condition;
683 $this->conditions = $newConditions;