Answer the question
In order to leave comments, you need to log in
How to get the number of elements?
Good afternoon. Menu component code, result_modifier.php file
<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
if (!empty($arResult))
{
$obCache = new CPHPCache();
if ($obCache->InitCache($arParams['CACHE_TIME'], serialize($arFilter), "/template/menu"))
{
$arFormatted = $obCache->GetVars();
}
elseif ($obCache->StartDataCache())
{
\Bitrix\Main\Loader::includeModule("iblock");
if(defined("BX_COMP_MANAGED_CACHE"))
{
global $CACHE_MANAGER;
$CACHE_MANAGER->StartTagCache("/template/menu");
}
$arSections = array();
$arFilter = array('<=DEPTH_LEVEL'=> '3', 'ELEMENT_SUBSECTIONS' => 'Y');
$res = CIBlockSection::GetList(Array(), $arFilter, true);
while($arRes = $res->GetNext())
{
if(!$iblock_id) $iblock_id = $arRes['IBLOCK_ID'];
$arSections[$arRes['NAME'].'_'.$arRes['DEPTH_LEVEL'].'_'.$arRes['SECTION_PAGE_URL']] = $arRes;
$debug[] = $arRes;
}
$top_key = -1;
$sub_key = -1;
foreach($arResult as $key => $arItem):
$arItem['PARAMS']['ELEMENT_CNT'] = $arSections[$arItem['TEXT'].'_'.$arItem['DEPTH_LEVEL'].'_'.$arItem['LINK']]['ELEMENT_CNT'];
switch ($arItem["DEPTH_LEVEL"]):
case 1:
$top_key++;
$arFormatted[$top_key] = $arItem;
$sub_key = -1;
break;
case 2:
$sub_key++;
$arFormatted[$top_key]["ITEMS"][$sub_key] = $arItem;
break;
case 3:
if($sub_key >= 0)
{
$arFormatted[$top_key]["ITEMS"][$sub_key]["ITEMS"][] = $arItem;
}
break;
endswitch;
endforeach;
if(defined("BX_COMP_MANAGED_CACHE"))
{
if($iblock_id)$CACHE_MANAGER->RegisterTag("iblock_id_".$iblock_id);
$CACHE_MANAGER->EndTagCache();
}
$obCache->EndDataCache($arFormatted);
}
$arResult = $arFormatted;
}
echo "<pre style='text-align:left;'>";print_r($arResult);echo "</pre>";
?>
Answer the question
In order to leave comments, you need to log in
First, stop copulating the dead. For each task there is a separate tool, with strictly defined canons. What you do in result_modifier.php is done through the menu extension and the bitrix:menu.sections component .
Secondly, the number of active elements is obtained through the add. operations within an iteration. See reference literature: coder-diary.ru/programming/bitrix-kolichestvo-akti...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question