Last active
April 7, 2021 07:08
-
-
Save ggrachdev/41c5cd774dc97d2852a637f353552888 to your computer and use it in GitHub Desktop.
Bitrix получить данные всех полей элемента, которые скушает CIBlockElement::Update
This file contains 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
<?php | |
/** | |
* Получить полный массив свойств элемента валидный для функции CElement Update | |
* | |
* @param int $elemId | |
* @param int $iblockId | |
* @return array | |
*/ | |
function getArrayOriginalProperties(int $elemId, int $iblockId): array { | |
$arSystemProp = []; | |
// Получаем стандартные свойства | |
$dbIblock = \CIBlockElement::GetList([], [ | |
'IBLOCK_ID' => $iblockId, 'ID' => $elemId], | |
false, | |
false, | |
['ID', 'CODE', 'IBLOCK_SECTION_ID', 'NAME', 'XML_ID', 'PREVIEW_TEXT', 'DETAIL_TEXT', 'ACTIVE', 'PREVIEW_PICTURE', 'DETAIL_PICTURE'] | |
); | |
if ($arItemResult = $dbIblock->GetNextElement()) { | |
$arItem = $arItemResult->GetFields(); | |
$arSystemProp['NAME'] = $arItem['NAME']; | |
$arSystemProp['ACTIVE'] = $arItem['ACTIVE']; | |
$arSystemProp['ID'] = $arItem['ID']; | |
$arSystemProp['CODE'] = $arItem['CODE']; | |
$arSystemProp['XML_ID'] = $arItem['XML_ID']; | |
$arSystemProp['IBLOCK_SECTION_ID'] = !empty($arItem['IBLOCK_SECTION_ID']) ? $arItem['IBLOCK_SECTION_ID'] : 0; | |
if (!empty($arItem['DETAIL_PICTURE'])) { | |
$arSystemProp['DETAIL_PICTURE'] = \CFile::GetFileArray($arItem['DETAIL_PICTURE']); | |
} | |
if (!empty($arItem['PREVIEW_PICTURE'])) { | |
$arSystemProp['PREVIEW_PICTURE'] = \CFile::GetFileArray($arItem['PREVIEW_PICTURE']); | |
} | |
if (!empty($arItem['PREVIEW_TEXT'])) { | |
$arSystemProp['PREVIEW_TEXT'] = $arItem['PREVIEW_TEXT']; | |
} | |
if (!empty($arItem['DETAIL_TEXT'])) { | |
$arSystemProp['DETAIL_TEXT'] = $arItem['DETAIL_TEXT']; | |
} | |
} | |
// Получаем свойства инфоблока | |
$arPropElementTo = []; | |
$dbPropertiesElementTo = \CIBlockElement::GetProperty( | |
$iblockId, | |
$elemId, | |
[], | |
[] | |
); | |
while ($arNowPropElementTo = $dbPropertiesElementTo->Fetch()) { | |
switch ($arNowPropElementTo['PROPERTY_TYPE']) { | |
case 'F': | |
if (!empty($arNowPropElementTo['VALUE'])) { | |
if ($arNowPropElementTo['MULTIPLE'] === 'Y') { | |
$index = !empty($arPropElementTo[$arNowPropElementTo['CODE']]) ? sizeof($arPropElementTo[$arNowPropElementTo['CODE']]) : 0; | |
$arPropElementTo[$arNowPropElementTo['CODE']]['n' . $index] = [ | |
'VALUE' => \CFile::GetFileArray($arNowPropElementTo['VALUE']) | |
]; | |
} else { | |
$arPropElementTo[$arNowPropElementTo['CODE']] = ['VALUE' => \CFile::GetFileArray($arNowPropElementTo['VALUE'])]; | |
} | |
} | |
break; | |
case 'E': | |
if (!empty($arNowPropElementTo['VALUE'])) { | |
if ($arNowPropElementTo['MULTIPLE'] === 'Y') { | |
$arPropElementTo[$arNowPropElementTo['CODE']][] = $arNowPropElementTo['VALUE']; | |
} else { | |
$arPropElementTo[$arNowPropElementTo['CODE']] = $arNowPropElementTo['VALUE']; | |
} | |
} | |
break; | |
case 'S': | |
if ($arNowPropElementTo['MULTIPLE'] === 'Y') { | |
if (!empty($arNowPropElementTo['VALUE']) || !empty($arNowPropElementTo['DESCRIPTION'])) { | |
$arPropElementTo[$arNowPropElementTo['CODE']][] = [ | |
'VALUE' => $arNowPropElementTo['VALUE'], | |
'DESCRIPTION' => $arNowPropElementTo['DESCRIPTION'] | |
]; | |
} | |
} else { | |
if (!empty($arNowPropElementTo['VALUE']) || !empty($arNowPropElementTo['DESCRIPTION'])) { { | |
$arPropElementTo[$arNowPropElementTo['CODE']] = [ | |
'VALUE' => $arNowPropElementTo['VALUE'], | |
'DESCRIPTION' => $arNowPropElementTo['DESCRIPTION'] | |
]; | |
} | |
} | |
} | |
break; | |
case 'L': | |
if (!empty($arNowPropElementTo['VALUE'])) { | |
if ($arNowPropElementTo['MULTIPLE'] === 'Y') { | |
$arPropElementTo[$arNowPropElementTo['CODE']][] = $arNowPropElementTo['VALUE']; | |
} else { | |
$arPropElementTo[$arNowPropElementTo['CODE']] = $arNowPropElementTo['VALUE']; | |
} | |
} | |
break; | |
} | |
} | |
if (!empty($arPropElementTo)) { | |
$arSystemProp['PROPERTY_VALUES'] = $arPropElementTo; | |
} | |
return $arSystemProp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment