• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/entity_query.php
  • Класс: CEntityQuery
  • Вызов: CEntityQuery::getFilterCswFields
protected function getFilterCswFields(&$filter)
{
	$fields = array();

	foreach ($filter as $filter_def => &$filter_match)
	{
		if ($filter_def === 'LOGIC')
		{
			continue;
		}

		if (!is_numeric($filter_def))
		{
			$csw_result = CSQLWhere::MakeOperation($filter_def);
			list($definition, ) = array_values($csw_result);

			$chain = $this->filter_chains[$definition];
			$last = $chain->getLastElement();

			$field_type = $last->getValue()->getDataType();

			// rewrite type & value for CSQLWhere
			if ($field_type == 'integer')
			{
				$field_type = 'int';
			}
			elseif ($field_type == 'boolean')
			{
				$field_type = 'string';

				if (is_scalar($filter_match))
				{
					$filter_match = $last->getValue()->normalizeValue($filter_match);
				}
			}
			elseif ($field_type == 'float')
			{
				$field_type = 'double';
			}

			//$is_having = $last->getValue() instanceof CExpressionEntityField && $last->getValue()->IsAggregated();

			// if back-reference found (Entity:REF)
			// if NO_DOUBLING mode enabled, then change getSQLDefinition to subquery exists(...)
			// and those chains should not be in joins if it is possible

			$callback = null;

			/*if (!$this->data_doubling && $chain->hasBackReference())
			{
				$field_type = 'callback';
				$init_query = $this;

				$callback = function ($field, $operation, $value) use ($init_query, $chain)
				{
					$init_entity = $init_query->getEntity();
					$init_table_alias = CBaseEntity::camel2snake($init_entity->getName()).$init_query->getTableAliasPostfix();

					$filter = array();

					// add primary linking with main query
					foreach ($init_entity->GetPrimaryArray() as $primary)
					{
						$filter['='.$primary] = new CSQLWhereExpression('?#', $init_table_alias.'.'.$primary);
					}

					// add value filter
					$filter[CSQLWhere::getOperationByCode($operation).$chain->getDefinition()] = $value;

					// build subquery
					$query_class = __CLASS__;
					$sub_query = new $query_class($init_entity);
					$sub_query->setFilter($filter);
					$sub_query->setTableAliasPostfix('_sub');

					return 'EXISTS(' . $sub_query->getQuery() . ')';
				};
			}*/

			$fields[$definition] = array(
				'TABLE_ALIAS' => 'table',
				'FIELD_NAME' => $chain->getSqlDefinition(),
				'FIELD_TYPE' => $field_type,
				'MULTIPLE' => '',
				'JOIN' => '',
				'CALLBACK' => $callback
			);
		}

		if (is_array($filter_match))
		{
			$fields = array_merge($fields, $this->getFilterCswFields($filter_match));
		}
	}

	return $fields;
}