• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/entity_query.php
  • Класс: CEntityQuery
  • Вызов: CEntityQuery::addToSelectChain
protected function addToSelectChain($definition, $alias = '')
{
	if (is_array($definition))
	{
		// it is runtime field
		$this->registerRuntimeField($alias, $definition);
		$chain = $this->getRegisteredChain($alias);

		// add
		$this->registerChain('select', $chain);

		// recursively collect all "build_from" fields
		if ($chain->getLastElement()->getValue() instanceof CExpressionEntityField)
		{
			$this->collectExprChains($chain, array('hidden', 'select_expr'));
		}
	}
	else
	{
		// there is normal scalar field, or Reference, or Entity (all fields of)
		$chain = $this->getRegisteredChain($definition, true);
		$last_elem = $chain->getLastElement();

		// fill if element is not scalar
		$expand_entity = null;

		if ($last_elem->getValue() instanceof CReferenceEntityField)
		{
			$expand_entity = $last_elem->getValue()->getRefEntity();
		}
		elseif (is_array($last_elem->getValue()))
		{
			list($expand_entity, ) = $last_elem->getValue();
		}
		elseif ($last_elem->getValue() instanceof CBaseEntity)
		{
			$expand_entity = $last_elem->getValue();
		}

		if ($expand_entity)
		{
			// add all fields of entity
			foreach ($expand_entity->getFields() as $exp_field)
			{
				if (!($exp_field instanceof CReferenceEntityField))
				{
					if ($exp_field instanceof CExpressionEntityField)
					{
						// we should have own copy of build_from_chains to set join aliases there
						// actually is copy&paste from getChainByDefinition
						// it would be correct to form DEFINITIONs here and call getChainByDefinition for each
						$exp_field = clone $exp_field;
					}

					$exp_chain = clone $chain;
					$exp_chain->addElement(new CEntityQueryChainElement(
						$exp_field
					));

					// add
					$this->registerChain('select', $exp_chain);

					if ($exp_field instanceof CExpressionEntityField)
					{
						$this->collectExprChains($exp_chain, array('hidden', 'select_expr'));
					}
				}
			}
		}
		else
		{
			// scalar field that defined in entity
			$this->registerChain('select', $chain);

			// collect buildFrom fields (recursively)
			if ($chain->getLastElement()->getValue() instanceof CExpressionEntityField)
			{
				$this->collectExprChains($chain, array('hidden', 'select_expr'));
			}
		}
	}

	return $this;
}