• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/location/import/import.php
  • Класс: BitrixSaleLocationImportis
  • Вызов: is::determineLayoutToImport
public function determineLayoutToImport()
{
	$lay = $this->getRemoteLayout(true);

	$parentness = array();
	foreach($lay as $data)
		$parentness[$data['PARENT_CODE']] += 1;

	$bundles = array_flip($this->data['settings']['sets']);

	$selectedLayoutParts = array();
	foreach($bundles as $bundle => $void)
	{
		if(!isset($lay[$bundle]))
			throw new MainSystemException('Unknown bundle passed in request');

		// obtaining intermediate chain parts
		$chain = array();

		$currentBundle = $bundle;
		$i = -1;
		while($currentBundle)
		{
			$i++;

			if($i > 50) // smth is really bad
				throw new MainSystemException('Too deep recursion got when building chains. Layout file is broken');

			if(isset($lay[$currentBundle]))
			{
				$chain[] = $currentBundle;
				if(strlen($lay[$currentBundle]['PARENT_CODE']))
				{
					$currentBundle = $lay[$currentBundle]['PARENT_CODE'];

					if(!isset($lay[$currentBundle]))
						throw new MainSystemException('Unknown parent bundle found ('.$currentBundle.'). Layout file is broken');
				}
				else
					$currentBundle = false;
			}
		}

		if(is_array($chain) && !empty($chain))
		{
			$chain = array_reverse($chain);

			// find first occurance of selected bundle in the chain
			$subChain = array();
			foreach($chain as $i => $node)
			{
				if(isset($bundles[$node]))
				{
					$subChain = array_slice($chain, $i);
					break;
				}
			}

			if(!empty($subChain))
				$selectedLayoutParts = array_merge($selectedLayoutParts, $subChain);
		}
	}

	//$this->data['settings']['layout'] = $lay;
	$selectedLayoutParts = array_unique($selectedLayoutParts);

	$this->data['settings']['bundles'] = array('endpoints' => array(), 'allpoints' => $selectedLayoutParts);

	foreach($selectedLayoutParts as $bCode)
	{
		if(!isset($parentness[$bCode]))
			$this->data['settings']['bundles']['endpoints'][] = $bCode;
		//else
		//	$this->data['settings']['bundles']['middlepoints'][] = $bCode;
	}
	unset($this->data['settings']['sets']);
}