• Модуль: webdav
  • Путь к файлу: ~/bitrix/modules/webdav/classes/iblock.php
  • Класс: CWebDavIblock
  • Вызов: CWebDavIblock::GetSectionsTree
function GetSectionsTree($options = array())
{
	static $dataType = 'SectionsTree';
	if(empty($options['prependPath']))
	{
		$options['prependPath'] = '';
	}
	$dataCache = $options;
	$dataCache['IBLOCK_ID'] = $this->IBLOCK_ID;
	$dataCache['ROOT_SECTION_ID'] = empty($this->arRootSection['ID'])? 0 : $this->arRootSection['ID'];
	$id = md5(serialize($dataCache));
	$sections = $this->_dataCache($dataType . $id);
	if ($sections === false)
	{
		$arElement = $this->GetObject($options, false, true);
		if ($arElement["not_found"])
		{
			$sections = array();
		}
		else
		{
			$arFilter = array("IBLOCK_ID" => $this->IBLOCK_ID);
			if (isset($options['not_check_permissions']))
				$arFilter['CHECK_PERMISSIONS'] = 'N';
			$bRootFounded = (empty($this->arRootSection) ? true : false);
			if ($arElement["item_id"] > 0 && !empty($arElement["dir_array"]))
			{
				$arFilter["LEFT_MARGIN"] = intval($arElement["dir_array"]["LEFT_MARGIN"]) + 1;
				$arFilter["RIGHT_MARGIN"] = intval($arElement["dir_array"]["RIGHT_MARGIN"]) - 1;
			}
			elseif (!empty($this->arRootSection))
			{
				$arFilter["LEFT_MARGIN"] = intval($this->arRootSection["LEFT_MARGIN"]) + 1;
				$arFilter["RIGHT_MARGIN"] = intval($this->arRootSection["RIGHT_MARGIN"]) - 1;
			}

			if(!empty($arElement["is_dir"]) && $arElement["item_id"])
			{
				list($contextType, $contextEntityId) = $this->getContextData();
				$sectionData = $this->getSectionDataForLinkAnalyze($arElement["item_id"], $arElement);
				$iblockId = $sectionData['IBLOCK_ID'];
				if(CWebDavSymlinkHelper::isLink($contextType, $contextEntityId, $sectionData))
				{
					$arFilter['IBLOCK_ID'] = $iblockId;
					$symlinkSectionData = CWebDavSymlinkHelper::getLinkData($contextType, $contextEntityId, $sectionData);
					if(!empty($symlinkSectionData[self::UF_LINK_SECTION_ID]) && $symlinkSectionData['ID'] == $arElement["item_id"])
					{
						$margins = CIBlockSection::GetList(array(), array(
							'ID' => $symlinkSectionData[self::UF_LINK_SECTION_ID],
							'IBLOCK_ID' => $symlinkSectionData[self::UF_LINK_IBLOCK_ID],
							'CHECK_PERMISSIONS' => 'N',
						), false, array('LEFT_MARGIN', 'RIGHT_MARGIN', 'IBLOCK_ID'))->fetch();
						if($margins)
						{
							$arFilter["LEFT_MARGIN"] = intval($margins["LEFT_MARGIN"]) + 1;
							$arFilter["RIGHT_MARGIN"] = intval($margins["RIGHT_MARGIN"]) - 1;
						}
					}
				}
			}

			$arResult = array();
			$db_res = CIBlockSection::GetTreeList($arFilter, array(
				'ID',
				'CREATED_BY',
				'MODIFIED_BY',
				'IBLOCK_ID',
				'IBLOCK_SECTION_ID',
				'NAME',
				'LEFT_MARGIN',
				'RIGHT_MARGIN',
				'DEPTH_LEVEL',
				'SOCNET_GROUP_ID',
				'IBLOCK_CODE',
				'TIMESTAMP_X',
			)); // TODO: add e_rights check
			$trashID = $this->GetMetaID('TRASH');
			if ($db_res && $res = $db_res->Fetch())
			{
				$deep = -1;
				$arPath = array();
				$arExclude = array();
				do
				{
					if ($this->MetaNames($res))
					{
						$res["DEPTH_LEVEL"] = intval($res["DEPTH_LEVEL"]);
						if(isset($arExclude[(int) $res["IBLOCK_SECTION_ID"]]) || $this->MetaSectionHide($res, !empty($options['NON_DROPPED_SECTION'])))
						{
							$arExclude[(int)$res["ID"]] = true;
						}
						else
						{
							if ($res["DEPTH_LEVEL"] > $deep)
							{
								$deep = $res["DEPTH_LEVEL"];
								array_push($arPath, mb_strtolower(htmlspecialcharsbx($res["NAME"])));
							}
							elseif ($res["DEPTH_LEVEL"] == $deep)
							{
								array_pop($arPath);
								array_push($arPath, mb_strtolower(htmlspecialcharsbx($res["NAME"])));
							}
							else
							{
								while ($res["DEPTH_LEVEL"] < $deep)
								{
									array_pop($arPath);
									$deep--;
								}
								array_pop($arPath);
								array_push($arPath, mb_strtolower(htmlspecialcharsbx($res["NAME"])));
							}

							$res["PATH"] = $options['prependPath'] . implode("/", $arPath);
							$arResult[$res["ID"]] = $res;
						}
					}
					else
					{
						$arExclude[(int)$res["ID"]] = true;
					}
				} while ($res = $db_res->Fetch());
			}
			$sections = $arResult;
		}
		$this->_dataCache($dataType . $id, $sections);
	}

	if(!empty($options['setERights']))
	{
		$sectionIds = array();
		foreach ($sections as $section)
		{
			$sectionIds[] = $section['ID'];
		}
		unset($section);

		$sectionRights = $this->GetPermissions('SECTION', $sectionIds, $this->IBLOCK_ID);
		foreach ($sections as &$section)
		{
			if (isset($sectionRights[$section['ID']]))
			{
				$section['E_RIGHTS'] = $sectionRights[$section['ID']];
			}
		}
		unset($section);
	}
	global $USER;
	if(!empty($options['SET_IS_SHARED']) && $USER->getId())
	{
		$querySelfSharedSections = BitrixWebdavFolderInviteTable::getList(array(
			'filter' => array(
				'USER_ID' => $USER->getId(),
				'!=INVITE_USER_ID' => $USER->getId(),
			),
			'select' => array('SECTION_ID', 'IBLOCK_ID'),
		));
		while($folderInvite = $querySelfSharedSections->fetch())
		{
			$selfSharedSections[$folderInvite['SECTION_ID']] = $folderInvite;
		}
		unset($folderInvite);

		foreach ($sections as &$section)
		{
			if(isset($selfSharedSections[$section['ID']]))
			{
				$section['IS_SHARED'] = true;
			}
		}
		unset($section);
	}

	return $sections;
}