- Модуль: intranet
- Путь к файлу: ~/bitrix/modules/intranet/classes/general/utils.php
- Класс: CIntranetUtils
- Вызов: CIntranetUtils::getSubStructure
static function getSubStructure($sectionId, $depth = false)
{
global $CACHE_MANAGER;
static $structures;
if (empty($structures[intval($sectionId)][intval($depth)]))
{
$iblockId = COption::GetOptionInt('intranet', 'iblock_structure', false);
if ($iblockId <= 0)
return;
$cacheDir = '/intranet/structure/branches';
$cacheId = 'intranet|structure|'.$iblockId.'|branch|'.intval($sectionId).'|'.intval($depth);
$obCache = new CPHPCache();
if ($obCache->InitCache(30*86400, $cacheId, $cacheDir))
{
$subStructure = $obCache->GetVars();
}
else
{
$obCache->StartDataCache();
$CACHE_MANAGER->StartTagCache($cacheDir);
$CACHE_MANAGER->RegisterTag('iblock_id_'.$iblockId);
$CACHE_MANAGER->RegisterTag('intranet_users');
$CACHE_MANAGER->RegisterTag('intranet_department_structure');
$subStructure = array(
'TREE' => array(),
'DATA' => array(),
);
$arFilter = array(
'IBLOCK_ID' => $iblockId,
'ACTIVE' => 'Y'
);
if ($sectionId > 0)
{
if ($depth == 1)
{
$arFilter['SECTION_ID'] = $sectionId;
}
else
{
$dbSection = CIBlockSection::GetList(
array('LEFT_MARGIN' => 'ASC'),
array('IBLOCK_ID' => $iblockId, 'ID' => $sectionId, 'ACTIVE' => 'Y'),
false,
array('DEPTH_LEVEL', 'LEFT_MARGIN', 'RIGHT_MARGIN')
);
if (!empty($dbSection) && ($currentSection = $dbSection->fetch()))
{
$arFilter['>=LEFT_MARGIN'] = $currentSection['LEFT_MARGIN'];
$arFilter['<=RIGHT_MARGIN'] = $currentSection['RIGHT_MARGIN'];
$arFilter['>DEPTH_LEVEL'] = $currentSection['DEPTH_LEVEL'];
if ($depth > 0)
$arFilter['<=DEPTH_LEVEL'] = $currentSection['DEPTH_LEVEL'] + $depth;
}
}
}
else if ($depth > 0)
{
$arFilter['<=DEPTH_LEVEL'] = $depth;
}
$dbSections = CIBlockSection::GetList(
array('LEFT_MARGIN' => 'ASC'),
$arFilter,
false,
array('ID', 'NAME', 'IBLOCK_SECTION_ID', 'UF_HEAD')
);
if (!empty($dbSections))
{
while ($section = $dbSections->fetch())
{
if (empty($section['IBLOCK_SECTION_ID']))
$section['IBLOCK_SECTION_ID'] = 0;
if (!isset($subStructure['TREE'][$section['IBLOCK_SECTION_ID']]))
$subStructure['TREE'][$section['IBLOCK_SECTION_ID']] = array();
$subStructure['TREE'][$section['IBLOCK_SECTION_ID']][] = $section['ID'];
$subStructure['DATA'][$section['ID']] = array(
'ID' => $section['ID'],
'NAME' => $section['NAME'],
'IBLOCK_SECTION_ID' => $section['IBLOCK_SECTION_ID'],
'UF_HEAD' => $section['UF_HEAD']
);
}
}
$CACHE_MANAGER->EndTagCache();
$obCache->EndDataCache($subStructure);
}
if (!is_array($structures))
$structures = array();
if (!isset($structures[intval($sectionId)]) || !is_array($structures[intval($sectionId)]))
$structures[intval($sectionId)] = array();
$structures[intval($sectionId)][intval($depth)] = $subStructure;
}
return $structures[intval($sectionId)][intval($depth)];
}