• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/location/tree.php
  • Класс: BitrixSaleLocationTree
  • Вызов: Tree::getParentTree
static function getParentTree($primary, $parameters = array(), $behaviour = array('SHOW_CHILDREN' => true, 'START_FROM' => false))
{
	$primary = Assert::expectIntegerPositive($primary, '$primary');

	if(!is_array($behaviour))
		$behaviour = array();
	if(!isset($behaviour['SHOW_CHILDREN']))
		$behaviour['SHOW_CHILDREN'] = true;
	if(!isset($behaviour['START_FROM']))
		$behaviour['START_FROM'] = false;

	if(empty($parameters))
		$parameters = array();

	$startFrom = intval($behaviour['START_FROM']);
	$showChildren = $behaviour['SHOW_CHILDREN'];

	if(!$startFrom)
	{
		$conditions[] = array(
			'DEPTH_LEVEL' => 1
		);
	}

	// todo: combine (1) and (2) in one query, check perfomance change

	// (1)
	$res = self::getPathToNode($primary, array(
		'select' => array('ID')
	));

	$started = !$startFrom;
	while($item = $res->Fetch())
	{
		if($item['ID'] == $startFrom)
			$started = true;

		if(!$started)
			continue;

		if(!$showChildren && $item['ID'] == $primary)
			continue;

		$conditions[] = array(
			'PARENT_ID' => $item['ID']
		);
	}

	$conditions['LOGIC'] = 'OR';

	$parameters['filter'][] = $conditions;

	if(!is_array($parameters['order']) || empty($parameters['order']))
		$parameters['order'] = array('LEFT_MARGIN' => 'asc');

	// (2)
	return self::getList($parameters);
}