• Модуль: report
  • Путь к файлу: ~/bitrix/modules/report/classes/general/report.php
  • Класс: CReport
  • Вызов: CReport::generateChains
static function generateChains($strChains, $initEntity, $initKey)
{
	$chains = array();

	foreach ($strChains as $k => $v)
	{
		if (is_array($v))
		{
			// catalog here
			$key = empty($initKey) ? $k : $initKey . '.' .$k;

			try
			{
				$chain = EntityQueryChain::getChainByDefinition($initEntity, $key);
				$lastElem = $chain->getLastElement();

				if ($lastElem->getValue() instanceof EntityReferenceField || is_array($lastElem->getValue()))
				{
					// reference to another entity
					$v = self::generateChains($v, $initEntity, $key);
					$v['__CHAIN__'] = $chain;
				}
				else
				{
					throw new BitrixMainSystemException('', 100);
				}
			}
			catch (Exception $e)
			{
				// try to recognize virtual category
				if ($e->getCode() == 100)
				{
					// `getChainByDefinition` field not found, there is  virtual category
					$v = self::generateChains($v, $initEntity, $initKey);
				}
				else
				{
					throw $e;
				}
			}
		}
		else
		{
			// normal field
			// collect chain path FLD1.FLD2.FLD3
			$key = empty($initKey) ? '' : $initKey . '.';

			$key = $key.$v;
			$v = EntityQueryChain::getChainByDefinition($initEntity, $key);
		}

		// replace key
		$chains[$key] = $v;
	}

	return $chains;
}