• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/location/tree.php
  • Класс: BitrixSaleLocationis
  • Вызов: is::addExtended
static function addExtended(array $data, array $additional = array())
{
	$rebalance = !isset($additional['REBALANCE']) || $additional['REBALANCE'] !== false;

	// determine LEFT_MARGIN, RIGHT_MARGIN and DEPTH_LEVEL
	if($data['PARENT_ID'] = intval($data['PARENT_ID']))
	{
		// if we have PARENT_ID set, just use it`s info
		$node = self::getNodeInfo($data['PARENT_ID']);

		$needResort = true;

		$data['LEFT_MARGIN'] = $node['RIGHT_MARGIN'];
		$data['RIGHT_MARGIN'] = $node['RIGHT_MARGIN'] + 1;
		$data['DEPTH_LEVEL'] = $node['DEPTH_LEVEL'] + 1;
		$data['PARENT_ID'] = $node['ID'];
	}
	else
	{
		// otherwise, we assume we have "virtual root node", that has LEFT_MARGIN == 0 and RIGHT_MARGIN == +INFINITY
		// it allows us to have actually a forest, not a tree

		$rm = self::getMaxMargin();
		$needResort = false;

		$data['LEFT_MARGIN'] = $rm > 1 ? $rm + 1 : 1;
		$data['RIGHT_MARGIN'] = $rm > 1 ? $rm + 2 : 2;

		$data['DEPTH_LEVEL'] = 1;
		$data['PARENT_ID'] = 0;
	}

	// process insert options: INSERT_AFTER and INSERT_BEFORE
	//self::processInsertInstruction($data);

	$addResult = parent::add($data);

	if($addResult->isSuccess() && $needResort && $rebalance)
		self::rebalance($node, $addResult->getId());

	return $addResult;
}