<?php
namespace lib;
use CAllcorp3StroyCache;
class CAllcorp3StroyMod
{
public static function getChilds2($input, &$start = 0, $level = 0){
static $arIblockItemsMD5 = array();
if(!$level){
$lastDepthLevel = 1;
if($input && is_array($input)){
foreach($input as $i => $arItem){
if($arItem['DEPTH_LEVEL'] > $lastDepthLevel){
if($i > 0){
$input[$i - 1]['IS_PARENT'] = 1;
}
}
$lastDepthLevel = $arItem['DEPTH_LEVEL'];
}
}
}
$childs = array();
$count = count($input);
for($i = $start; $i < $count; ++$i){
$item = $input[$i];
if(!isset($item)){
continue;
}
if($level > $item['DEPTH_LEVEL'] - 1){
break;
}
else{
if(!empty($item['IS_PARENT'])){
$i++;
$item['CHILD'] = self::getChilds2($input, $i, $level+1);
$i--;
}
$childs[] = $item;
}
}
$start = $i;
if(is_array($childs)){
foreach($childs as $j => $item){
if($item['PARAMS']){
$md5 = md5($item['TEXT'].$item['LINK'].$item['SELECTED'].$item['PERMISSION'].$item['ITEM_TYPE'].$item['IS_PARENT'].serialize($item['ADDITIONAL_LINKS']).serialize($item['PARAMS']));
if(isset($arIblockItemsMD5[$md5][$item['PARAMS']['DEPTH_LEVEL']])){
if(isset($arIblockItemsMD5[$md5][$item['PARAMS']['DEPTH_LEVEL']][$level]) || ($item['DEPTH_LEVEL'] === 1 && !$level)){
unset($childs[$j]);
continue;
}
}
if(!isset($arIblockItemsMD5[$md5])){
$arIblockItemsMD5[$md5] = array($item['PARAMS']['DEPTH_LEVEL'] => array($level => true));
}
else{
$arIblockItemsMD5[$md5][$item['PARAMS']['DEPTH_LEVEL']][$level] = true;
}
}
}
}
if($GLOBALS['arTheme']['USE_REGIONALITY']['VALUE'] === 'Y' && $GLOBALS['arTheme']['USE_REGIONALITY']['DEPENDENT_PARAMS']['REGIONALITY_FILTER_ITEM']['VALUE'] === 'Y' && $GLOBALS['arRegion']){
if(is_array($childs)){
foreach($childs as $i => $item){
if($item['PARAMS'] && isset($item['PARAMS']['LINK_REGION'])){
if($item['PARAMS']['LINK_REGION']){
if(!in_array($GLOBALS['arRegion']['ID'], $item['PARAMS']['LINK_REGION'])){
unset($childs[$i]);
}
}
else{
unset($childs[$i]);
}
}
}
}
}
if(!$level){
$arIblockItemsMD5 = array();
}
return $childs;
}
public static function getSectionChilds($PSID, &$arSections, &$arSectionsByParentSectionID, &$arItemsBySectionID, &$aMenuLinksExt, $bMenu = false){
if($arSections && is_array($arSections)){
foreach($arSections as $arSection){
if($arSection['IBLOCK_SECTION_ID'] == $PSID){
$bCheck = false;
if (!$bMenu) {
$arItem = array(
$arSection['NAME'],
$arSection['SECTION_PAGE_URL'],
array(),
array(
'FROM_IBLOCK' => 1,
'DEPTH_LEVEL' => $arSection['DEPTH_LEVEL'],
'SORT' => $arSection['SORT'],
'UF_TOP_SEO' => $arSection['UF_TOP_SEO'],
'SHOW_IN_MENU' => $arSection['UF_SHOW_IN_MENU'],
'ICON' => $arSection['UF_SECTION_ICON'] ?? $arSection['UF_ICON'] ?? false,
'TRANSPARENT_PICTURE' => $arSection['UF_TRANSPARENT_PICTURE'] ?? false,
)
);
$arItem[3]['UF_TOP_SEO'] = $arSection['UF_TOP_SEO'];
$arItem[3]['IS_PARENT'] = (isset($arItemsBySectionID[$arSection['ID']]) || isset($arSectionsByParentSectionID[$arSection['ID']]) ? 1 : 0);
if($arSection["PICTURE"])
$arItem[3]["PICTURE"]=$arSection["PICTURE"];
if($arSection["UF_REGION"])
$arItem[3]["LINK_REGION"]=$arSection["UF_REGION"];
$bCheck = ($arItem[3]['IS_PARENT']);
} else {
$arItem = array(
'TEXT' => $arSection['NAME'],
'LINK' => $arSection['SECTION_PAGE_URL'],
array(),
'PARAMS' => array(
'FROM_IBLOCK' => 1,
'DEPTH_LEVEL' => $arSection['DEPTH_LEVEL'],
'SORT' => $arSection['SORT'],
'ID' => $arSection['ID'],
'IBLOCK_ID' => $arSection['IBLOCK_ID'],
'UF_TOP_SEO' => $arSection['UF_TOP_SEO'],
'UF_SHOW_IN_MENU' => $arSection['UF_SHOW_IN_MENU'],
'SHOW_IN_MENU' => $arSection['UF_SHOW_IN_MENU'],
'ICON' => $arSection['UF_SECTION_ICON'] ?? $arSection['UF_ICON'] ?? false,
'TRANSPARENT_PICTURE' => $arSection['UF_TRANSPARENT_PICTURE'] ?? false,
),
'DEPTH_LEVEL' => $arSection['DEPTH_LEVEL']
);
$arItem['PARAMS']['UF_TOP_SEO'] = $arSection['UF_TOP_SEO'];
$arItem['PARAMS']['UF_SHOW_IN_MENU'] = $arSection['UF_SHOW_IN_MENU'];
$arItem['PARAMS']['SHOW_IN_MENU'] = $arSection['UF_SHOW_IN_MENU'];
$arItem['PARAMS']['IS_PARENT'] = $arItem['IS_PARENT'] = (isset($arItemsBySectionID[$arSection['ID']]) || isset($arSectionsByParentSectionID[$arSection['ID']]) ? 1 : 0);
if($arSection["PICTURE"])
$arItem['PARAMS']["PICTURE"]=$arSection["PICTURE"];
if($arSection["UF_REGION"])
$arItem['PARAMS']["LINK_REGION"]=$arSection["UF_REGION"];
$bCheck = ($arItem['PARAMS']['IS_PARENT']);
}
$aMenuLinksExt[] = $arItem;
if($bCheck){
// subsections
self::getSectionChilds($arSection['ID'], $arSections, $arSectionsByParentSectionID, $arItemsBySectionID, $aMenuLinksExt, $bMenu);
// section elements
if($arItemsBySectionID[$arSection['ID']] && is_array($arItemsBySectionID[$arSection['ID']])){
foreach($arItemsBySectionID[$arSection['ID']] as $arItem){
if(is_array($arItem['DETAIL_PAGE_URL'])){
if(isset($arItem['CANONICAL_PAGE_URL'])){
$arItem['DETAIL_PAGE_URL'] = $arItem['CANONICAL_PAGE_URL'];
}
else{
$arItem['DETAIL_PAGE_URL'] = $arItem['DETAIL_PAGE_URL'][key($arItem['DETAIL_PAGE_URL'])];
}
}
$arTmpLink = array();
if($arItem['LINK_REGION']){
$arTmpLink['LINK_REGION'] = (array)$arItem['LINK_REGION'];
}elseif(array_key_exists('PROPERTY_LINK_REGION_VALUE', $arItem)){
$arTmpLink['LINK_REGION'] = (array)$arItem['PROPERTY_LINK_REGION_VALUE'];
}
$aMenuLinksExt[] = array(
$arItem['NAME'],
$arItem['DETAIL_PAGE_URL'],
array(),
array_merge(
array(
'FROM_IBLOCK' => 1,
'DEPTH_LEVEL' => ($arSection['DEPTH_LEVEL'] + 1),
'IS_ITEM' => 1,
'SORT' => $arItem['SORT']
),
$arTmpLink
)
);
}
}
}
}
}
}
}
public static function getMenuChildsExt($arParams, &$aMenuLinksExt, $bMenu = false)
{
if ($handler = \Aspro\Functions\CAsproAllcorp3Stroy::getCustomFunc(__FUNCTION__)) {
call_user_func_array($handler, [$arParams, &$aMenuLinksExt, $bMenu]);
return;
}
$catalog_id = \Bitrix\Main\Config\Option::get('aspro.allcorp3stroy', 'CATALOG_IBLOCK_ID', CAllcorp3StroyCache::$arIBlocks[SITE_ID]['aspro_allcorp3stroy_catalog']['aspro_allcorp3stroy_catalog'][0]);
$bIsCatalog = $arParams['IBLOCK_ID'] == $catalog_id;
$arParams['CATALOG_IBLOCK_ID'] = $catalog_id;
$arParams['IS_CATALOG_IBLOCK'] = $bIsCatalog;
foreach(GetModuleEvents(ALLCORP3STROY_MODULE_ID, 'BeforeAsproGetMenuChildsExt', true) as $arEvent) // event for manipulation store quantity block
ExecuteModuleEventEx($arEvent, array($arParams, &$aMenuLinksExt, $bMenu));
$arSectionFilter = array(
'IBLOCK_ID' => $arParams['IBLOCK_ID'],
'ACTIVE' => 'Y',
'GLOBAL_ACTIVE' => 'Y',
'ACTIVE_DATE' => 'Y',
'<DEPTH_LEVEL' => \Bitrix\Main\Config\Option::get("aspro.allcorp3stroy", "MAX_DEPTH_MENU", 2),
);
$arSectionSelect = array(
'ID',
'SORT',
'ACTIVE',
'IBLOCK_ID',
'NAME',
'SECTION_PAGE_URL',
'DEPTH_LEVEL',
'IBLOCK_SECTION_ID',
'PICTURE',
'UF_REGION',
'UF_TOP_SEO',
'UF_SHOW_IN_MENU',
'UF_SECTION_ICON',
'UF_ICON',
'UF_TRANSPARENT_PICTURE',
);
if($bIsCatalog) {
// $arSectionFilter = array_merge($arSectionFilter, array( ));
$arSectionSelect = array_merge($arSectionSelect, array( 'UF_MENU_BANNER', 'UF_MENU_BRANDS', 'UF_CATALOG_ICON', ));
}
if(array_key_exists('SECTION_FILTER', $arParams) && $arParams['SECTION_FILTER']) {
$arSectionFilter = array_merge($arSectionFilter, $arParams['SECTION_FILTER']);
}
if(array_key_exists('SECTION_SELECT', $arParams) && $arParams['SECTION_SELECT']) {
$arSectionSelect = array_merge($arSectionSelect, $arParams['SECTION_SELECT']);
}
if($arParams['MENU_PARAMS']['MENU_SHOW_SECTIONS'] == 'Y')
{
$arSections = CAllcorp3StroyCache::CIBlockSection_GetList(array('SORT' => 'ASC', 'NAME' => 'ASC', 'CACHE' => array('TAG' => CAllcorp3StroyCache::GetIBlockCacheTag($arParams['IBLOCK_ID']), 'MULTI' => 'Y')), $arSectionFilter, false, $arSectionSelect);
$arSectionsByParentSectionID = CAllcorp3StroyCache::GroupArrayBy($arSections, array('MULTI' => 'Y', 'GROUP' => array('IBLOCK_SECTION_ID')));
}
if(!$bIsCatalog) {
if($arParams['MENU_PARAMS']['MENU_SHOW_ELEMENTS'] == 'Y'){
$arElementFilter = array(
'IBLOCK_ID' => $arParams['IBLOCK_ID'],
'ACTIVE' => 'Y',
'SECTION_GLOBAL_ACTIVE' => 'Y',
'ACTIVE_DATE' => 'Y',
'INCLUDE_SUBSECTIONS' => 'Y',
);
$arElementSelect = array(
'ID',
'SORT',
'ACTIVE',
'IBLOCK_ID',
'NAME',
'DETAIL_PAGE_URL',
'DEPTH_LEVEL',
'IBLOCK_SECTION_ID',
'PROPERTY_LINK_REGION',
);
if(array_key_exists('ELEMENT_FILTER', $arParams) && $arParams['ELEMENT_FILTER']) {
$arSectionFilter = array_merge($arSectionFilter, $arParams['ELEMENT_FILTER']);
}
if(array_key_exists('ELEMENT_SELECT', $arParams) && $arParams['ELEMENT_SELECT']) {
$arSectionSelect = array_merge($arSectionSelect, $arParams['ELEMENT_SELECT']);
}
$arItems = CAllcorp3StroyCache::CIBlockElement_GetList(array('SORT' => 'ASC', 'NAME' => 'ASC', 'CACHE' => array('TAG' => CAllcorp3StroyCache::GetIBlockCacheTag($arParams['IBLOCK_ID']), 'MULTI' => 'Y')), $arElementFilter, false, false, $arElementSelect);
/*filter by region*/
global $arRegion;
if($arItems)
{
foreach($arItems as $key => $arItem)
{
$arTmpProp = array();
$rsPropRegion = CIBlockElement::GetProperty($arItem['IBLOCK_ID'], $arItem['ID'], array('sort' => 'asc'), Array('CODE'=>'LINK_REGION'));
while($arPropRegion = $rsPropRegion->Fetch())
{
if($arPropRegion['VALUE'])
$arTmpProp[] = $arPropRegion['VALUE'];
}
$arItems[$key]['LINK_REGION'] = $arTmpProp;
}
}
if($arParams['MENU_PARAMS']['MENU_SHOW_SECTIONS'] == 'Y'){
$arItemsBySectionID = CAllcorp3StroyCache::GroupArrayBy($arItems, array('MULTI' => 'Y', 'GROUP' => array('IBLOCK_SECTION_ID')));
}
else{
$arItemsRoot = CAllcorp3StroyCache::CIBlockElement_GetList(array('SORT' => 'ASC', 'NAME' => 'ASC', 'CACHE' => array('TAG' => CAllcorp3StroyCache::GetIBlockCacheTag($arParams['IBLOCK_ID']), 'MULTI' => 'Y')), array('IBLOCK_ID' => $arParams['IBLOCK_ID'], 'ACTIVE' => 'Y', 'ACTIVE_DATE' => 'Y', 'SECTION_ID' => 0));
$arItems = array_merge((array)$arItems, (array)$arItemsRoot);
}
}
}
foreach(GetModuleEvents(ALLCORP3STROY_MODULE_ID, 'OnAsproGetMenuChildsExt', true) as $arEvent) // event for manipulation store quantity block
ExecuteModuleEventEx($arEvent, array($arParams, &$aMenuLinksExt, $bMenu));
if($arSections) {
self::getSectionChilds(false, $arSections, $arSectionsByParentSectionID, $arItemsBySectionID, $aMenuLinksExt, $bMenu);
}
if(!$bIsCatalog) {
if($arItems && $arParams['MENU_PARAMS']['MENU_SHOW_SECTIONS'] != 'Y'){
foreach($arItems as $arItem){
$arExtParam = array('FROM_IBLOCK' => 1, 'DEPTH_LEVEL' => 1, 'SORT' => $arItem['SORT']);
if(isset($arItem['LINK_REGION']))
$arExtParam['LINK_REGION'] = $arItem['LINK_REGION'];
$aMenuLinksExt[] = array($arItem['NAME'], $arItem['DETAIL_PAGE_URL'], array(), $arExtParam);
}
}
}
foreach(GetModuleEvents(ALLCORP3STROY_MODULE_ID, 'AfterAsproGetMenuChildsExt', true) as $arEvent) // event for manipulation store quantity block
ExecuteModuleEventEx($arEvent, array($arParams, &$aMenuLinksExt, $bMenu));
}
} |