• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_webdav_helper.php
  • Класс: \CCrmWebDavHelper
  • Вызов: CCrmWebDavHelper::EnsureSharedFileSectionCreated
static function EnsureSharedFileSectionCreated($blockID, $typeID, $siteID = SITE_ID)
{
	$blockID = intval($blockID);
	if($blockID <= 0)
	{
		return 0;
	}

	$typeID = intval($typeID);
	if(!CCrmWebDavFileType::IsDefined($typeID))
	{
		return 0;
	}
	$key = "IBLOCK_SECTION_ID_{$typeID}";

	$siteID = strval($siteID);
	if($siteID === '')
	{
		return 0;
	}

	if(!isset(self::$SHARED_FILES_INFO[$siteID]))
	{
		self::$SHARED_FILES_INFO[$siteID] = array();
	}
	$info = self::$SHARED_FILES_INFO[$siteID];

	$blockSectionID = 0;
	if(isset($info[$key]))
	{
		$blockSectionID = $info[$key];
	}
	else
	{
		$xmlID = CCrmWebDavFileType::GetSectionXmlID($typeID);
		$blockSection = new CIBlockSection();
		$dbSections = $blockSection->GetList(array(), array('XML_ID' => $xmlID, 'IBLOCK_ID'=> $blockID, 'CHECK_PERMISSIONS' => 'N'), false, array('ID'));
		$arSection = $dbSections->Fetch();
		if(is_array($arSection))
		{
			$blockSectionID = intval($arSection['ID']);
		}

		if($blockSectionID <= 0)
		{
			$dbSite = CSite::GetByID($siteID);
			$arSite = $dbSite->Fetch();
			IncludeModuleLangFile(__FILE__, $arSite && isset($arSite['LANGUAGE_ID']) ? $arSite['LANGUAGE_ID'] : false);

			$blockSectionID = $blockSection->Add(
				array(
					'IBLOCK_ID' => $blockID,
					'ACTIVE' => 'Y',
					'NAME' => CCrmWebDavFileType::GetSectionName($typeID),
					'IBLOCK_SECTION_ID' => 0,
					'CHECK_PERMISSIONS' => 'N',
					'XML_ID' => $xmlID
				)
			);
		}

		self::$SHARED_FILES_INFO[$siteID][$key] = $blockSectionID;
	}

	return $blockSectionID;
}