<? if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();
$newSection = [];
$sectionLvlOne = 0;
$sectionLvlTwo = 0;
$sectionLvlThree = 0;
$arFilter = array('IBLOCK_ID' => 1, 'ACTIVE' => 'Y');
$arSelect = array('IBLOCK_ID', 'ID', 'NAME', 'SECTION_PAGE_URL', 'PICTURE', 'DEPTH_LEVEL', 'IBLOCK_SECTION_ID', 'LEFT_MARGIN');
$rsSect = CIBlockSection::GetList(
array("DEPTH_LEVEL" => "ASC", "LEFT_MARGIN" => "ASC"),
$arFilter,
false,
$arSelect
);
$sections = array();
while ($arSect = $rsSect->GetNext()) {
$sections[] = $arSect;
}
// ПЕРВЫЙ УРОВЕНЬ ВЛОЖЕННОСТИ
foreach ($sections as $arSect) {
if ($arSect['DEPTH_LEVEL'] == 1) {
$newSection[$arSect['ID']] = $arSect;
}
}
// ВТОРОЙ УРОВЕНЬ ВЛОЖЕННОСТИ
foreach ($sections as $arSect) {
if ($arSect['DEPTH_LEVEL'] == 2) {
$sectionLvlOne = $arSect['IBLOCK_SECTION_ID'];
if (!isset($newSection[$sectionLvlOne]['SECOND_LVL'])) {
$newSection[$sectionLvlOne]['SECOND_LVL'] = array();
}
$newSection[$sectionLvlOne]['SECOND_LVL'][$arSect['ID']] = $arSect;
}
}
// ТРЕТИЙ УРОВЕНЬ ВЛОЖЕННОСТИ
$sections_level_3 = [];
foreach ($sections as $arSect) {
if ($arSect['DEPTH_LEVEL'] == 3) {
$sectionLvlTwo = $arSect['IBLOCK_SECTION_ID'];
if (!isset($sections_level_3[$sectionLvlTwo])) {
$sections_level_3[$sectionLvlTwo] = array();
}
$sectionLvlThree = $arSect['ID'];
$sections_level_3[$sectionLvlTwo][$sectionLvlThree] = $arSect;
}
}
foreach ($newSection as $newSectionKey => $newSectionItem) {
if (isset($newSectionItem['SECOND_LVL']) && is_array($newSectionItem['SECOND_LVL']) && count($newSectionItem['SECOND_LVL'])) {
foreach ($newSectionItem['SECOND_LVL'] as $second_level_id => $second_level_item) {
if (isset($sections_level_3[$second_level_id])) {
$newSection[$newSectionKey]['SECOND_LVL'][$second_level_id]['THIRD_LVL'] = $sections_level_3[$second_level_id];
}
}
}
}
$arResult['NEW_SECTIONS'] = $newSection;
global $USER;
if ($USER->IsAdmin()) {
//echo '<pre>'; print_r($arResult['NEW_SECTIONS']); '</pre>';
}
?>
if (isset($sections_level_3[$second_level_id]))
<? if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();
$newSection = [];
$sectionLvlOne = 0;
$sectionLvlTwo = 0;
$sectionLvlThree = 0;
$arFilter = array('IBLOCK_ID' => 1, 'ACTIVE' => 'Y');
$arSelect = array('IBLOCK_ID', 'ID', 'NAME', 'SECTION_PAGE_URL', 'DETAIL_PICTURE', 'DEPTH_LEVEL', 'IBLOCK_SECTION_ID', 'LEFT_MARGIN');
$rsSect = CIBlockSection::GetList(
array("DEPTH_LEVEL" => "ASC", "LEFT_MARGIN" => "ASC"), //сортировка
$arFilter, //фильтр
false, //выводить количество элементов - нет
$arSelect //выборка вывода
);
//while ($arSect = $rsSect->GetNext()) {
// if ($arSect['DEPTH_LEVEL'] == 1) {
// $newSection[$arSect['ID']] = $arSect;
// $sectionLvlOne = $arSect['ID'];
// }
// $arResult['NEW_SECTIONS'] = $newSection;
//}
$sections = array();
while ($arSect = $rsSect->GetNext()) {
$sections[] = $arSect;
}
foreach($sections as $arSect):
if ($arSect['DEPTH_LEVEL'] == 1) {
$newSection[$arSect['ID']] = $arSect;
$sectionLvlOne = $arSect['ID'];
}
endforeach;
foreach($sections as $arSect):
if ($arSect['DEPTH_LEVEL'] == 2) {
$newSection[$sectionLvlOne]['SECOND_LVL'][$arSect['ID']] = $arSect;
$sectionLvlTwo = $arSect['ID'];
}
endforeach;
foreach($sections as $arSect):
if ($arSect['DEPTH_LEVEL'] == 3) {
$newSection[$sectionLvlOne]['SECOND_LVL'][$sectionLvlTwo]['THIRD_LVL'][$arSect['ID']] = $arSect;
$sectionLvlThree = $arSect['ID'];
}
endforeach;
$arResult['NEW_SECTIONS'] = $newSection;
<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();
$newSection = [];
$sectionLvlOne = 0;
$sectionLvlTwo = 0;
$sectionLvlThree = 0;
$arFilter = array('IBLOCK_ID' => 1, 'ACTIVE' => 'Y');
$arSelect = array('IBLOCK_ID', 'ID', 'NAME', 'SECTION_PAGE_URL', 'DETAIL_PICTURE', 'DEPTH_LEVEL', 'IBLOCK_SECTION_ID', 'LEFT_MARGIN');
$rsSect = CIBlockSection::GetList(
array("DEPTH_LEVEL" => "ASC", "LEFT_MARGIN" => "ASC"), //сортировка
$arFilter, //фильтр
false, //выводить количество элементов - нет
$arSelect //выборка вывода
);
while ($arSect = $rsSect->GetNext()) {
if ($arSect['DEPTH_LEVEL'] == 1) {
$newSection[$arSect['ID']] = $arSect;
$sectionLvlOne = $arSect['ID'];
}
$arResult['NEW_SECTIONS'] = $newSection;
}
global $USER;
if ($USER->IsAdmin()) {
echo '<pre>'; print_r($arResult['NEW_SECTIONS']); '</pre>';
}
?>
// Получаем первые N элементов
$(".section-compact-list .section-compact-list__item:lt(12)").css({'display': 'flex'});
// Обрабатываем клик по кнопке "показать еще"
$(".catalog-btn_more").click(function (event) {
event.preventDefault();
// Выбираем все скрытые элементы
var $hidden = $(".section-compact-list .section-compact-list__item:hidden");
// Показываем N выбранных элементов из скрытых
$($hidden).slice(0, 12).css("display", "flex").hide().fadeIn(800);
// Проверяем что список закончился
if ($hidden.length <= 4) {
// Меняем кнопки
$(this).fadeOut(300);
$(".catalog-btn_cut").fadeIn(800);
}
});
// Обрабатываем клик по кнопке "скрыть"
$(".catalog-btn_cut").click(function (event) {
event.preventDefault();
// Выбираем первые N элементов, которые будем исклчючать и показывать
$firstElems = $(".section-compact-list .section-compact-list__item").slice(0, 12);
// Скрываем все элементы кроме выбранных
$(".section-compact-list .section-compact-list__item").not($firstElems).hide().fadeOut(800);
// Меняем кнопки
$(this).fadeOut(300);
$(".catalog-btn_more").fadeIn(800);
});