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

	foreach ($reference as $k => $v)
	{
		if ($k === 'LOGIC')
		{
			$new[$k] = $v;
			continue;
		}

		if (is_numeric($k))
		{
			// subfilter, recursive call
			$new[$k] = $this->prepareJoinReference($v, $alias_this, $alias_ref);
		}
		else
		{
			// key
			$csw_result = CSQLWhere::MakeOperation($k);
			list($field, ) = array_values($csw_result);

			if (strpos($field, 'this.') === 0)
			{
				$k = str_replace('this.', $this->DB->escL.$alias_this.$this->DB->escR.'.'.$this->DB->escL, $k);
				$k .= $this->DB->escR;
			}
			elseif (strpos($field, 'ref.') === 0)
			{
				$k = str_replace('ref.', $this->DB->escL.$alias_ref.$this->DB->escR.'.'.$this->DB->escL, $k);
				$k .= $this->DB->escR;
			}
			else
			{
				throw new Exception();
			}

			// value
			if (is_array($v))
			{
				// field = expression
				$v = new CSQLWhereExpression($v[0], array_slice($v, 1));
			}
			else
			{
				// field = field
				if (strpos($v, 'this.') === 0)
				{
					$field_def = str_replace('this.', $alias_this.'.', $v);
				}
				elseif (strpos($v, 'ref.') === 0)
				{
					$field_def = str_replace('ref.', $alias_ref.'.', $v);
				}

				$v = new CSQLWhereExpression('?#', $field_def);
			}

			$new[$k] = $v;
		}
	}

	return $new;
}