• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/entity_query.php
  • Класс: CEntityQuery
  • Вызов: CEntityQuery::divideFilter
protected function divideFilter()
{
	// divide filter to where and having

	$logic = isset($this->filter['LOGIC']) ? $this->filter['LOGIC'] : 'AND';

	if ($logic == 'OR')
	{
		// if has aggr then move all to having
		if ($this->checkFilterAggregation($this->filter))
		{
			$this->where = array();
			$this->where_chains = array();

			$this->having = $this->filter;
			$this->having_chains = $this->filter_chains;
		}
		else
		{
			$this->where = $this->filter;
			$this->where_chains = $this->filter_chains;

			$this->having = array();
			$this->having_chains = array();
		}
	}
	elseif ($logic == 'AND')
	{
		// we can separate root filters
		foreach ($this->filter as $k => $sub_filter)
		{
			if ($k === 'LOGIC')
			{
				$this->where[$k] = $sub_filter;
				$this->having[$k] = $sub_filter;

				continue;
			}

			$tmp_filter = array($k => $sub_filter);

			if ($this->checkFilterAggregation($tmp_filter))
			{
				$this->having[$k] = $sub_filter;
				$this->setFilterChains($tmp_filter, 'having');
			}
			else
			{
				$this->where[$k] = $sub_filter;
				$this->setFilterChains($tmp_filter, 'where');
			}
		}
	}

	// collect "build_from" fields from having
	foreach ($this->having_chains as $chain)
	{
		if ($chain->getLastElement()->getValue() instanceof CExpressionEntityField)
		{
			$this->collectExprChains($chain, array('hidden', 'having_expr'));
		}
	}
}