Last active
March 14, 2025 13:17
-
-
Save EscApp2/05875965d15b3c0500cfa66b35c6d1f3 to your computer and use it in GitHub Desktop.
getElementInComplexComponent VARIABLES getSectionInComplexComponent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
if(!function_exists('getElementInComplexComponent')){ | |
function getElementInComplexComponent($arResult, $arParams, $arSelect = array()){ | |
$arFilter = array( | |
"IBLOCK_ID" => $arParams["IBLOCK_ID"], | |
"ACTIVE" => "Y", | |
"GLOBAL_ACTIVE" => "Y", | |
); | |
if (0 < intval($arResult["VARIABLES"]["SECTION_ID"])) | |
$arFilter["SECTION_ID"] = $arResult["VARIABLES"]["SECTION_ID"]; | |
elseif ('' != $arResult["VARIABLES"]["SECTION_CODE"]) | |
$arFilter["=SECTION_CODE"] = $arResult["VARIABLES"]["SECTION_CODE"]; | |
if (0 < intval($arResult["VARIABLES"]["ELEMENT_ID"])) | |
$arFilter["ID"] = $arResult["VARIABLES"]["ELEMENT_ID"]; | |
elseif ('' != $arResult["VARIABLES"]["ELEMENT_CODE"]) | |
$arFilter["=CODE"] = $arResult["VARIABLES"]["ELEMENT_CODE"]; | |
if(!is_array($arSelect)){ | |
$arSelect = array($arSelect); | |
} | |
$arSelect = array_merge( array('ID','NAME','CODE','IBLOCK_ID'), $arSelect); | |
$arSelect = array_unique($arSelect); | |
$obCache = new CPHPCache(); | |
if ($obCache->InitCache(36000, serialize($arFilter).serialize($arSelect), "/iblock/element_in_complex")) | |
{ | |
$arCurSection = $obCache->GetVars(); | |
} | |
elseif ($obCache->StartDataCache()) | |
{ | |
$arCurSection = array(); | |
if (\Bitrix\Main\Loader::includeModule("iblock")) | |
{ | |
if(!function_exists('GetIBlockElementsDataV6')) { | |
$dbRes = CIBlockElement::GetList( | |
array(), | |
$arFilter, | |
false, | |
false, | |
$arSelect); | |
if (defined("BX_COMP_MANAGED_CACHE")) { | |
global $CACHE_MANAGER; | |
$CACHE_MANAGER->StartTagCache("/iblock/element_in_complex"); | |
if ($arRes = $dbRes->GetNextElement()) { | |
$arCurSection = $arRes->GetFields(); | |
$arCurSection['PROPERTIES'] = $arRes->GetProperties(); | |
$CACHE_MANAGER->RegisterTag("iblock_id_" . $arParams["IBLOCK_ID"]); | |
} | |
$CACHE_MANAGER->EndTagCache(); | |
} else { | |
if ($arRes = $dbRes->GetNextElement()) { | |
$arCurSection = $arRes->GetFields(); | |
$arCurSection['PROPERTIES'] = $arRes->GetProperties(); | |
} else { | |
$arCurSection = array(); | |
} | |
} | |
}else{ | |
$arSelect[] = 'PROPERTY_*'; | |
$arElements = GetIBlockElementsDataV6($arFilter,$arParams["IBLOCK_ID"],$arSelect); | |
if($arElements){ | |
$arElement = array_values($arElements)[0]; | |
if (defined("BX_COMP_MANAGED_CACHE")) { | |
global $CACHE_MANAGER; | |
$CACHE_MANAGER->StartTagCache("/iblock/element_in_complex"); | |
if ($arElement) { | |
$arCurSection = $arElement; | |
$CACHE_MANAGER->RegisterTag("iblock_id_" . $arParams["IBLOCK_ID"]); | |
} | |
$CACHE_MANAGER->EndTagCache(); | |
} else { | |
if ($arElement) { | |
$arCurSection = $arElement; | |
} | |
} | |
} | |
} | |
} | |
$obCache->EndDataCache($arCurSection); | |
} | |
if (!isset($arCurSection)) | |
$arCurSection = array(); | |
return $arCurSection; | |
} | |
} | |
if(!function_exists('getSectionInComplexComponent')){ | |
function getSectionInComplexComponent($arResult, $arParams, $arSelect = array()){ | |
$arFilter = array( | |
"IBLOCK_ID" => $arParams["IBLOCK_ID"], | |
"ACTIVE" => "Y", | |
"GLOBAL_ACTIVE" => "Y", | |
); | |
if (0 < intval($arResult["VARIABLES"]["SECTION_ID"])) | |
$arFilter["ID"] = $arResult["VARIABLES"]["SECTION_ID"]; | |
elseif ('' != $arResult["VARIABLES"]["SECTION_CODE"]) | |
$arFilter["=CODE"] = $arResult["VARIABLES"]["SECTION_CODE"]; | |
if(!is_array($arSelect)){ | |
$arSelect = array($arSelect); | |
} | |
$arSelect = array_merge( array('ID','NAME','CODE','IBLOCK_ID'), $arSelect); | |
$arSelect = array_unique($arSelect); | |
$obCache = new CPHPCache(); | |
if ($obCache->InitCache(36000, serialize($arFilter).serialize($arSelect), "/iblock/section_in_complex")) | |
{ | |
$arCurSection = $obCache->GetVars(); | |
} | |
elseif ($obCache->StartDataCache()) | |
{ | |
$arCurSection = array(); | |
if (\Bitrix\Main\Loader::includeModule("iblock")) | |
{ | |
$dbRes = CIBlockSection::GetList(array(), $arFilter, false, $arSelect); | |
if(defined("BX_COMP_MANAGED_CACHE")) | |
{ | |
global $CACHE_MANAGER; | |
$CACHE_MANAGER->StartTagCache("/iblock/section_in_complex"); | |
if ($arCurSection = $dbRes->Fetch()) | |
$CACHE_MANAGER->RegisterTag("iblock_id_".$arParams["IBLOCK_ID"]); | |
$CACHE_MANAGER->EndTagCache(); | |
} | |
else | |
{ | |
if(!$arCurSection = $dbRes->Fetch()) | |
$arCurSection = array(); | |
} | |
} | |
$obCache->EndDataCache($arCurSection); | |
} | |
if (!isset($arCurSection)) | |
$arCurSection = array(); | |
return $arCurSection; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment