Skip to content

Instantly share code, notes, and snippets.

@alexstep
Created October 4, 2012 10:27
Show Gist options
  • Save alexstep/3832776 to your computer and use it in GitHub Desktop.
Save alexstep/3832776 to your computer and use it in GitHub Desktop.
bitrix: sections tree
/* Получаем и кешируем информацию о разделах(sections) */
// должен быть подключен CModule::IncludeModule("iblock");
!!!!!!! $_sections_iblock_id = .укажи id инфоблока
$obCache = new CPHPCache;
if($obCache->InitCache(24*60, 'list_sections', '/cache_path/' ){
$vars = $obCache->GetVars();
$sections = $vars["sections"];
$sections_by_code = $vars["sections_by_code"];
} else if($obCache->StartDataCache()) {
$sections = array();
$sections_by_code = array(); $sections_by_id = array();
$db_list = CIBlockSection::GetList(
Array('ID'=>'ASC'),
Array('IBLOCK_ID'=>$_sections_iblock_id, 'GLOBAL_ACTIVE'=>'Y'),
true
);
while($sec = $db_list->GetNext()) {
$sections_by_code[$sec["CODE"]]["ID"] = $sec["ID"];
$sections[$sec["ID"]] = $sec;
/*$sections[$sec["ID"]]["ID"] = $sec["ID"];
$sections[$sec["ID"]]["IBLOCK_SECTION_ID"] = $sec["IBLOCK_SECTION_ID"];
$sections[$sec["ID"]]["CODE"] = $sec["CODE"];
$sections[$sec["ID"]]["NAME"] = $sec["NAME"];
$sections[$sec["ID"]]["PICTURE"] = $sec["PICTURE"];
$sections[$sec["ID"]]["DESCRIPTION"] = $sec["DESCRIPTION"];*/
if(intval($sections[$sec["IBLOCK_SECTION_ID"]]["ID"])>0){
if(is_array($sections[$sec["IBLOCK_SECTION_ID"]]['subsections'])){
$sections[$sec["IBLOCK_SECTION_ID"]]['subsections'][] = $sec["ID"];
} else {
$sections[$sec["IBLOCK_SECTION_ID"]]['subsections'] = array($sec["ID"]);
}
}
}
$obCache->EndDataCache(array("sections" => $sections, "sections_by_code" => $sections_by_code));
}
/* print_r($sections);
print_r($sections_by_code);*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment