Добрый день.
Есть 3-х уровневое меню каталога. реализованное с помощью файла _ext.
При клике по пунктам 1 или 2 уровня каталога происходит переход в нужную категорию и меню остается "развернутым" на пункте по которому кликнули. Но если кликнуть по пункту 3-тьего уровня, то переходи происходит но пункт не остается активным и меню сворачивается до 2 уровня.
Подскажите, пожалуйста, как сделать так что бы оставался активным 3-тий уровень меню?
template.php
result_modifler.php
Есть 3-х уровневое меню каталога. реализованное с помощью файла _ext.
При клике по пунктам 1 или 2 уровня каталога происходит переход в нужную категорию и меню остается "развернутым" на пункте по которому кликнули. Но если кликнуть по пункту 3-тьего уровня, то переходи происходит но пункт не остается активным и меню сворачивается до 2 уровня.
Подскажите, пожалуйста, как сделать так что бы оставался активным 3-тий уровень меню?
template.php
| Код |
|---|
<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
/** @var array $arParams */
/** @var array $arResult */
/** @global CMain $APPLICATION */
/** @global CUser $USER */
/** @global CDatabase $DB */
/** @var CBitrixComponentTemplate $this */
/** @var string $templateName */
/** @var string $templateFile */
/** @var string $templateFolder */
/** @var string $componentPath */
/** @var CBitrixComponent $component */
$this->setFrameMode(true);
if (!function_exists('pathToNode')) {
function pathToNode($node_id, $tree, $max_level = 4) {
$path_nodes = array();
if ($max_level > 1) {
foreach ($tree as $id => $children) {
if (
is_array($children)
&& count(
$path_nodes = pathToNode($node_id, $children, $max_level - 1)
) > 0
) {
array_push($path_nodes, $id);
break;
}
}
} elseif (
array_key_exists($node_id, $tree)
|| in_array($node_id, $tree)
) {
$path_nodes[] = $node_id;
}
return array_reverse($path_nodes);
}
}
$selectedMenuItems = array();
foreach ($arResult["ALL_ITEMS"] as $itemID => $item) {
if ($item['SELECTED'] === true) {
$selectedMenuItems = pathToNode($itemID, $arResult['ALL_ITEMS_ID'], $item['DEPTH_LEVEL']);
break;
}
}
?>
<ul class="cd-accordion-menu"> <!-- first level-->
<? foreach ($arResult["MENU_STRUCTURE"] as $itemID => $arColumns): ?>
<? if (is_array($arColumns) && count($arColumns) > 0): ?> <!-- если есть дочерние элементы -->
<li class="has-children">
<input type="checkbox" name="group-<?=$itemID?>" id="group-<?=$itemID?>" <?=in_array($itemID, $selectedMenuItems) ? ' checked' : ''?>>
<label for="group-<?=$itemID?>">
<a href="<?=$arResult["ALL_ITEMS"][$itemID]["LINK"]?>" class="knopka">
<?=$arResult["ALL_ITEMS"][$itemID]["TEXT"]?>
</a>
</label>
<ul> <!-- второй уровень -->
<? foreach ($arColumns as $key => $arRow): ?>
<? foreach ($arRow as $itemIdLevel_2 => $arLevel_3): ?>
<? if (is_array($arLevel_3) && count($arLevel_3) > 0): ?> <!-- если есть дети 3-тьего уровня -->
<li class="has-children">
<!-- элементы второй уровень -->
<? var_dump(in_array($itemIdLevel_2, $selectedMenuItems));?>
<input type="checkbox" name="sub-group-<?=$itemIdLevel_2?>" id="sub-group-<?=$itemIdLevel_2?>"
<?=in_array($itemIdLevel_2, $selectedMenuItems) ? ' checked' : ''?>>
<label for="sub-group-<?=$itemIdLevel_2?>" >
<a href="<?=$arResult["ALL_ITEMS"][$itemIdLevel_2]["LINK"]?>" class="knopka_l">
<?=$arResult["ALL_ITEMS"][$itemIdLevel_2]["TEXT"]?>
</a>
</label>
<ul> <!-- third level-->
<? foreach ($arLevel_3 as $itemIdLevel_3): ?>
<li>
<!-- третий уровень -->
<input type="checkbox" name="sub-group-<?=$itemIdLevel_3?>" id="sub-group-<?=$itemIdLevel_3?>"
<?=in_array($itemIdLevel_3, $selectedMenuItems) ? ' checked' : ''?>>
<a href="<?=$arResult["ALL_ITEMS"][$itemIdLevel_3]["LINK"]/*ссылка*/?>" class="knopka_l">
<?=$arResult["ALL_ITEMS"][$itemIdLevel_3]["TEXT"]/*название */?>
</a>
</li>
<? endforeach; ?>
</ul>
</li>
<?else: ?> <!-- есил нет деток 3-его -->
<li>
<!-- второй уровень без подгрупп -->
<a href="<?=$arResult["ALL_ITEMS"][$itemIdLevel_2]["LINK"]?>" class="knopka">
<?=$arResult["ALL_ITEMS"][$itemIdLevel_2]["TEXT"]?>
</a>
</li>
<? endif; ?>
<? endforeach; ?>
<? endforeach; ?>
</ul>
</li>
<? else: ?>
<!-- пункты меню 1-ого уровня без дочерних элементов -->
<li><a href="<?=$arResult["ALL_ITEMS"][$itemID]["LINK"]?>" class="knopka_l" ><?=$arResult["ALL_ITEMS"][$itemID]["TEXT"]?></a></li>
<? endif; ?>
<? endforeach; ?> <!-- для 1 уровня -->
</ul> |
result_modifler.php
| Код |
|---|
<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
if (empty($arResult))
return;
if (isset($arParams["MENU_THEME"]) && !empty($arParams["MENU_THEME"]))
{
$arAvailableThemes = array();
$dir = trim(preg_replace("'[\\\\/]+'", "/", dirname(__FILE__)."/themes/"));
if (is_dir($dir) && $directory = opendir($dir))
{
while (($file = readdir($directory)) !== false)
{
if ($file != "." && $file != ".." && is_dir($dir.$file))
$arAvailableThemes[] = $file;
}
closedir($directory);
}
if ($arParams["MENU_THEME"] == "site")
{
$solution = COption::GetOptionString("main", "wizard_solution", "", SITE_ID);
if ($solution == "eshop")
{
$theme = COption::GetOptionString("main", "wizard_eshop_adapt_theme_id", "blue", SITE_ID);
$arParams["MENU_THEME"] = (in_array($theme, $arAvailableThemes)) ? $theme : "blue";
}
}
else
{
$arParams["MENU_THEME"] = (in_array($arParams["MENU_THEME"], $arAvailableThemes)) ? $arParams["MENU_THEME"] : "blue";
}
}
else
{
$arParams["MENU_THEME"] = "blue";
}
if(!function_exists("FillAllPicturesAndDescriptions"))
{
function FillAllPicturesAndDescriptions(&$arAllItems, $arMenuItemsIDs)
{
//find picture or description for the first level, if it hasn't
foreach ($arMenuItemsIDs as $itemIdLevel_1=>$arLevels2)
{
if (!$arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"] || !$arAllItems[$itemIdLevel_1]["PARAMS"]["description"])
{
foreach($arLevels2 as $itemIdLevel_2=>$arLevels3)
{
if (!$arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"] && $arAllItems[$itemIdLevel_2]["PARAMS"]["picture_src"])
{
$arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"] = $arAllItems[$itemIdLevel_2]["PARAMS"]["picture_src"];
}
if (!$arAllItems[$itemIdLevel_1]["PARAMS"]["description"] && $arAllItems[$itemIdLevel_2]["PARAMS"]["description"])
{
$arAllItems[$itemIdLevel_1]["PARAMS"]["description"] = $arAllItems[$itemIdLevel_2]["PARAMS"]["description"];
}
if ($arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"] && $arAllItems[$itemIdLevel_1]["PARAMS"]["description"])
break;
}
if (!$arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"] || !$arAllItems[$itemIdLevel_1]["PARAMS"]["description"])
{
foreach($arLevels2 as $itemIdLevel_2=>$arLevels3)
{
foreach($arLevels3 as $itemIdLevel_3)
{
if (!$arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"] && $arAllItems[$itemIdLevel_3]["PARAMS"]["picture_src"])
{
$arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"] = $arAllItems[$itemIdLevel_3]["PARAMS"]["picture_src"];
}
if (!$arAllItems[$itemIdLevel_1]["PARAMS"]["description"] && $arAllItems[$itemIdLevel_3]["PARAMS"]["description"])
{
$arAllItems[$itemIdLevel_1]["PARAMS"]["description"] = $arAllItems[$itemIdLevel_3]["PARAMS"]["description"];
}
if ($arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"] && $arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"])
break;
}
if ($arAllItems[$itemIdLevel_1]["PARAMS"]["picture_src"] && $arAllItems[$itemIdLevel_1]["PARAMS"]["description"])
break;
}
}
}
}
foreach($arAllItems as $itemID=>$arItem)
{
if ($arItem["DEPTH_LEVEL"] == "1")
{
if ($arItem["IS_PARENT"])
{
$pictureLevel_1 = $arItem["PARAMS"]["picture_src"];
$descriptionLevel_1 = $arItem["PARAMS"]["description"];
}
$arAllItems[$itemID] = $arItem;
}
elseif($arItem["DEPTH_LEVEL"] == "2")
{
/*if (!$arItem["PARAMS"]["picture_src"])
$arItem["PARAMS"]["picture_src"] = $pictureLevel_1; */
/*if (!$arItem["PARAMS"]["description"])
$arItem["PARAMS"]["description"] = $descriptionLevel_1; */
if ($arItem["IS_PARENT"])
{
$pictureLevel_2 = $arItem["PARAMS"]["picture_src"];
$descriptionLevel_2 = $arItem["PARAMS"]["description"];
}
$arAllItems[$itemID] = $arItem;
}
elseif($arItem["DEPTH_LEVEL"] == "3")
{
/*if (!$arItem["PARAMS"]["picture_src"])
$arItem["PARAMS"]["picture_src"] = $pictureLevel_2;
if (!$arItem["PARAMS"]["description"])
$arItem["PARAMS"]["description"] = $descriptionLevel_2; */
$arAllItems[$itemID] = $arItem;
}
}
}
}
$arSectionsInfo = array();
if (IsModuleInstalled("iblock"))
{
$arFilter = array(
"TYPE" => "catalog",
"SITE_ID" => SITE_ID,
"ACTIVE" => "Y"
);
$obCache = new CPHPCache();
if ($obCache->InitCache(36000, serialize($arFilter), "/iblock/menu"))
{
$arSectionsInfo = $obCache->GetVars();
}
elseif ($obCache->StartDataCache())
{
if (CModule::IncludeModule("iblock"))
{
$dbIBlock = CIBlock::GetList(array('SORT' => 'ASC', 'ID' => 'ASC'), $arFilter);
$dbIBlock = new CIBlockResult($dbIBlock);
$curIblockID = 0;
if ($arIBlock = $dbIBlock->GetNext())
{
$dbSections = CIBlockSection::GetList(array(), array("IBLOCK_ID" => $arIBlock["ID"]), false, array("ID", "SECTION_PAGE_URL", "PICTURE", "DESCRIPTION"));
while($arSections = $dbSections->GetNext())
{
$pictureSrc = CFile::GetFileArray($arSections["PICTURE"]);
if ($pictureSrc)
$arResizePicture = CFile::ResizeImageGet(
$arSections["PICTURE"],
array("width" => 240, 'height'=>700),
BX_RESIZE_IMAGE_PROPORTIONAL,
true
);
$arSectionsInfo[crc32($arSections["SECTION_PAGE_URL"])]["PICTURE"] = $pictureSrc ? $arResizePicture["src"] : false;
$arSectionsInfo[crc32($arSections["SECTION_PAGE_URL"])]["DESCRIPTION"] = $arSections["DESCRIPTION"];
}
if(defined("BX_COMP_MANAGED_CACHE"))
{
global $CACHE_MANAGER;
$CACHE_MANAGER->StartTagCache("/iblock/menu");
$CACHE_MANAGER->RegisterTag("iblock_id_".$arIBlock["ID"]);
$CACHE_MANAGER->EndTagCache();
}
}
}
$obCache->EndDataCache($arSectionsInfo);
}
}
$arMenuItemsIDs = array();
$arAllItems = array();
foreach($arResult as $key=>$arItem)
{
if($arItem["DEPTH_LEVEL"] > $arParams["MAX_LEVEL"])
{
unset($arResult[$key]);
continue;
}
$arItem["PARAMS"]["item_id"] = crc32($arItem["LINK"]);
$arItem["PARAMS"]["picture_src"] = $arSectionsInfo[$arItem["PARAMS"]["item_id"]]["PICTURE"];
$arItem["PARAMS"]["description"] = $arSectionsInfo[$arItem["PARAMS"]["item_id"]]["DESCRIPTION"];
if ($arItem["DEPTH_LEVEL"] == "1")
{
$arMenuItemsIDs[$arItem["PARAMS"]["item_id"]] = array();
if ($arItem["IS_PARENT"])
{
$curItemLevel_1 = $arItem["PARAMS"]["item_id"];
}
$arAllItems[$arItem["PARAMS"]["item_id"]] = $arItem;
}
elseif($arItem["DEPTH_LEVEL"] == "2")
{
$arMenuItemsIDs[$curItemLevel_1][$arItem["PARAMS"]["item_id"]] = array();
if ($arItem["IS_PARENT"])
{
$curItemLevel_2 = $arItem["PARAMS"]["item_id"];
}
$arAllItems[$arItem["PARAMS"]["item_id"]] = $arItem;
}
elseif($arItem["DEPTH_LEVEL"] == "3")
{
/*$arMenuItemsIDs[$curItemLevel_1][$curItemLevel_2][$arItem["PARAMS"]["item_id"]]= array(); */ // заменил
$arMenuItemsIDs[$curItemLevel_1][$curItemLevel_2][] = $arItem["PARAMS"]["item_id"];
$arAllItems[$arItem["PARAMS"]["item_id"]] = $arItem;
}
}
FillAllPicturesAndDescriptions($arAllItems, $arMenuItemsIDs);
$arMenuStructure = array();
foreach ($arMenuItemsIDs as $itemIdLevel_1=>$arLevels2)
{
$countItemsInRow = 18;
$arMenuStructure[$itemIdLevel_1] = array();
$countLevels2 = count($arLevels2);
if ($countLevels2 > 0)
{
for ($i=1; $i<=3; $i++)
{
$sumElementsInRow = 0;
foreach($arLevels2 as $itemIdLevel_2=>$arLevels3)
{
$sumElementsInRow+= count($arLevels3) + 1;
$arMenuStructure[$itemIdLevel_1][$i][$itemIdLevel_2] = $arLevels3;
if ($sumElementsInRow > $countItemsInRow)
$countItemsInRow = $sumElementsInRow;
unset($arLevels2[$itemIdLevel_2]);
$tmpCount = 0;
foreach($arLevels2 as $tmpItemIdLevel_2=>$arTmpLevels3)
{
$tmpCount+= 1 + count($arTmpLevels3);
}
if ($tmpCount <= $countItemsInRow*(3-$i) && $countItemsInRow<=$sumElementsInRow)
break;
}
}
}
}
$arResult = array();
$arResult["ALL_ITEMS"] = $arAllItems;
$arResult["ALL_ITEMS_ID"] = $arMenuItemsIDs;
$arResult["MENU_STRUCTURE"] = $arMenuStructure;
|