Your IP : 18.222.121.160
<?php
/*
* RusKlimat
* Вся работа с разделами каталога
*
* @author Alex
* @date 16/01/2018
*/
IncludeModuleLangFile(__FILE__);
class RusklimatSection extends RusklimatMain
{
public function __construct()
{
parent::__construct();
}
/*
* Получение всех разделов инфоблока и запись в массив по заданному ключу
*/
public function getSections($iblockId = false, $fields = false, $mainField = "XML_ID")
{
if(empty($iblockId))
throw new Exception('Empty $iblockId from getAllSections function');
if(is_array($fields))
$arSelect = array_merge($fields, array("XML_ID", "UF_*"));
else
$arSelect = false;
$arFilter = array("IBLOCK_ID" => $iblockId);
$res = CIBlockSection::GetList(Array("SORT"=>"ASC"), $arFilter, false, $arSelect);
while($arRes = $res->Fetch()){
$out[$arRes[$mainField]] = $arRes;
}
return $out;
}
/*
* Обновление разделов
* Ключ массива $arIn - Айдишник раздела
*/
public function updateSection($arIn = array())
{
if(empty($arIn))
throw new Exception('Empty $arIn from updateSection function');
$bs = new CIBlockSection;
foreach($arIn as $id => $arSec)
{
if(!empty($arSec))
{
$res = $bs->Update($id, $arSec, false);
$arResult["SUCCESS"][$id] = "Section ID [".$id."] - update!";
}
else
{
$arResult["ERROR"][$id] = "Section ID [".$id."] - empty array for update!";
}
}
return $arResult;
}
/*
* Функция добавления/обновления подготовленных данных по разделам
*/
function addUpdateSections($arData = array())
{
if(empty($arData))
throw new Exception('Empty array $arData from addUpdateSections function');
$bs = new CIBlockSection;
foreach($arData as $depth => $sections)
{
foreach($sections as $section_xml_id => $section)
{
if(empty($section["ID"]))
{
// add
$ID = $bs->Add($section);
if($ID>0)
$arResult["SUCCESS"][$section_xml_id] = "Section XML_ID [".$section_xml_id."] add!";
else
$arResult["ERROR"][$section_xml_id] = "Section XML_ID [".$section_xml_id."] NOT add! ".$bs->LAST_ERROR;
}
else
{
//UPDATE
$ID = $section["ID"];
unset($section["ID"]);
$res = $bs->Update($ID, $section);
if(!$res)
$arResult["ERROR"][$section_xml_id] = "Section XML_ID [".$section_xml_id."] NOT update! ".$bs->LAST_ERROR;
else
$arResult["SUCCESS"][$section_xml_id] = "Section XML_ID [".$section_xml_id."] update!";
}
}
}
return $arResult;
}
}