• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/location/admin/locationhelper.php
  • Класс: BitrixSaleLocationAdminLocationHelper
  • Вызов: LocationHelper::getLocationSubMenu
static function getLocationSubMenu()
{
	// how it works: every time when we call for the next sub-level, we must
	// obtain not sublevel itself, but a whole parent-tree of it

	$queryParams = self::unPackItemsQueryString();

	$requiredToShow = false;
	// three situations:
	// 1) node id comes in $_REQUEST['admin_mnu_menu_id'] parameter when user walks along left menu tree
	$id = false;
	if(self::checkRequestIsMenuRequest())
	{
		$requiredToShow = true;
		$id = $queryParams['ID'];
	}
	if(!$id)
	{
		// 2) node id comes in $_REQUEST['id'] or in $_REQUEST['parent_id'] when user enters self::LIST_PAGE_URL or self::EDIT_PAGE_URL page
		$page = $GLOBALS['APPLICATION']->GetCurPage();
		if($page == '/bitrix/admin/'.self::LIST_PAGE_URL || $page == '/bitrix/admin/'.self::EDIT_PAGE_URL)
		{
			$requiredToShow = true;

			$parentId = (int)($_REQUEST['PARENT_ID'] ?? 0);
			if ($parentId <= 0)
			{
				$parentId = (int)($_REQUEST['parent_id'] ?? 0);
			}
			if ($parentId > 0)
			{
				$id = $parentId;
			}
		}
	}
	// 3) there is no node id at all

	$tree = array();
	if($requiredToShow)
	{
		$parameters = array(
			'select' => array(
				'ID',
				'LOCATION_NAME' => 'NAME.NAME',
				'DEPTH_LEVEL',
				'PARENT_ID',
				'CHILD_CNT'
			),
			'filter' => array(
				'=NAME.LANGUAGE_ID' => LANGUAGE_ID
			),
			'order' => array(
				'LOCATION_NAME' => 'asc' // result always come sorted by LEFT_MARGIN, we must resort it by NAME
			)
		);

		if($id)
		{
			try
			{
				$res = LocationLocationTable::getParentTree($id, $parameters, array('SHOW_CHILDREN' => true));
			}
			catch(MainSystemException $e)
			{
				return array();
			}
		}
		else
		{
			$res = LocationLocationTable::getChildren(false, $parameters);
		}

		$index = array();
		while($item = $res->Fetch())
		{
			$index[$item['PARENT_ID']][$item['ID']] = array(
				'NAME' => htmlspecialcharsbx($item['LOCATION_NAME']),
				'PARENT_ID' => intval($item['PARENT_ID']),
				'CHILD_CNT' => intval($item['CHILD_CNT'])
			);
		}

		unset($res);
		unset($item);

		self::appendMenuChildren($tree, 0, $index, $queryParams);
	}

	return $tree;
}