[CODE] AddEventHandler('main','OnBuildGlobalMenu', array('BuildMenuHandler', 'OnBuildGlobalMenu'));
class BuildMenuHandler {
static $sections;
public function OnBuildGlobalMenu(&$arGlobalMenu, &$arModuleMenu) {
$obCache = new CPHPCache();
if ($obCache->InitCache(36000, 'buildmenusections', '/admin_menu/')) {
$res = $obCache->GetVars();
if (is_array($res['sections']) && count($res['sections']) > 0)
static::$sections = $res['sections'];
}
foreach ($arModuleMenu as &$arMenu) {
if ($arMenu['module_id'] == 'iblock') {
$arMenu = self::AddCntToMenuItem($arMenu);
}
}
if ($obCache->StartDataCache()) {
global $CACHE_MANAGER;
$CACHE_MANAGER->StartTagCache('/admin_menu/');
foreach (static::$sections as $iblockId => $section) {
$CACHE_MANAGER->RegisterTag('iblock_id_' . $iblockId);
}
$CACHE_MANAGER->EndTagCache();
$obCache->EndDataCache(array(
'sections' => static::$sections
));
}
}
public function GetSectionElementCnt($iblockId, $sectionId) {
if (!is_array(static::$sections[$iblockId])) {
static::$sections[$iblockId] = array();
$dbSection = CIBlockSection::GetList(array(), array('IBLOCK_ID' => $iblockId), true, array('ELEMENT_CNT', 'ID'));
while ($arSection = $dbSection->GetNext()) {
static::$sections[$iblockId][$arSection['ID']] = $arSection['ELEMENT_CNT'];
}
}
return static::$sections[$iblockId][$sectionId];
}
public function AddCntToMenuItem($arMenu) {
foreach ($arMenu['items'] as &$arItem) {
$exp = explode('/', $arItem['items_id']);
$iblockId = intval($exp[count($exp) - 2]);
$sectionId = intval($exp[count($exp) - 1]);
if ($iblockId > 0 && $sectionId > 0) {
$elementCnt = self::GetSectionElementCnt($iblockId, $sectionId);
$arItem['text'] .= ' (' . intval($elementCnt) . ')';
}
if (count($arItem['items']) > 0) {
$arItem = self::AddCntToMenuItem($arItem);
}
}
return $arMenu;
}
}[/CODE]
class BuildMenuHandler {
static $sections;
public function OnBuildGlobalMenu(&$arGlobalMenu, &$arModuleMenu) {
$obCache = new CPHPCache();
if ($obCache->InitCache(36000, 'buildmenusections', '/admin_menu/')) {
$res = $obCache->GetVars();
if (is_array($res['sections']) && count($res['sections']) > 0)
static::$sections = $res['sections'];
}
foreach ($arModuleMenu as &$arMenu) {
if ($arMenu['module_id'] == 'iblock') {
$arMenu = self::AddCntToMenuItem($arMenu);
}
}
if ($obCache->StartDataCache()) {
global $CACHE_MANAGER;
$CACHE_MANAGER->StartTagCache('/admin_menu/');
foreach (static::$sections as $iblockId => $section) {
$CACHE_MANAGER->RegisterTag('iblock_id_' . $iblockId);
}
$CACHE_MANAGER->EndTagCache();
$obCache->EndDataCache(array(
'sections' => static::$sections
));
}
}
public function GetSectionElementCnt($iblockId, $sectionId) {
if (!is_array(static::$sections[$iblockId])) {
static::$sections[$iblockId] = array();
$dbSection = CIBlockSection::GetList(array(), array('IBLOCK_ID' => $iblockId), true, array('ELEMENT_CNT', 'ID'));
while ($arSection = $dbSection->GetNext()) {
static::$sections[$iblockId][$arSection['ID']] = $arSection['ELEMENT_CNT'];
}
}
return static::$sections[$iblockId][$sectionId];
}
public function AddCntToMenuItem($arMenu) {
foreach ($arMenu['items'] as &$arItem) {
$exp = explode('/', $arItem['items_id']);
$iblockId = intval($exp[count($exp) - 2]);
$sectionId = intval($exp[count($exp) - 1]);
if ($iblockId > 0 && $sectionId > 0) {
$elementCnt = self::GetSectionElementCnt($iblockId, $sectionId);
$arItem['text'] .= ' (' . intval($elementCnt) . ')';
}
if (count($arItem['items']) > 0) {
$arItem = self::AddCntToMenuItem($arItem);
}
}
return $arMenu;
}
}[/CODE]