<?
//Регистрация обработчиков
AddEventHandler("iblock", "OnAfterIBlockElementAdd", Array("IBlockElement", "OnAfterIBlockElementAddHandler"));
class IBlockElement
{
// создаем обработчик события "OnAfterIBlockElementAdd"
function OnAfterIBlockElementAddHandler(&$arFields)
{
if($arFields["ID"]>0 && $arFields['IBLOCK_ID'] == 2){
$elementID = $arFields['ID'];
$videoID = $arFields['PROPERTY_VALUES'][2]['n0']['VALUE'];
if(CModule::IncludeModule("iblock")){
$arOreder = array(
'SORT' => 'ASC'
);
$arFilter = array(
'ID' => $videoID,
'ACTIVE' => 'Y',
'IBLOCK_ID' => 3
);
$arSelectFields = array(
'ID',
'NAME',
'DETAIL_PICTURE',
'PROPERTY_FILE'
);
$cdbVideo = CIBlockElement::GetList($arOreder, $arFilter, false, false, $arSelectFields);
$arVideoValues = $cdbVideo->GetNext();
$arVideo = CFile::GetFileArray($arVideoValues['PROPERTY_FILE_VALUE']);
$arScreen = CFile::GetFileArray($arVideoValues['DETAIL_PICTURE']);
$Element = new CIBlockElement;
$arLoadElementArray = array(
"DETAIL_PICTURE" => $arScreen,
"PREVIEW_PICTURE" => $arScreen
);
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/log.txt', "\n\n". 'Update from:->'.(int)$elementID, FILE_APPEND);
$updateResult = $Element->Update((int)$elementID, $arLoadElementArray, false, false, true);
if($updateResult){
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/log.txt', "\n\n".var_export($arScreen, true), FILE_APPEND);
}else{
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/log.txt', "\n\n".$updateResult->LAST_ERROR(), FILE_APPEND);
};
}
}
}
}
?>
|