• Модуль: rest
  • Путь к файлу: ~/bitrix/modules/rest/classes/general/restentity.php
  • Класс: CBitrixRestEntity
  • Вызов: CBitrixRestEntity::entityItemUpdate
static function entityItemUpdate($params, $n, $server)
{
	if(self::checkItemParams($params))
	{
		$params['ID'] = intval($params['ID']);
		if($params['ID'] <= 0)
		{
			throw new BitrixMainArgumentNullException("ID");
		}
		else
		{
			$arIBlock = self::getIBlock(self::getEntityIBlockCode($params['ENTITY'], $server));
			if($arIBlock)
			{
				if(CIBlockRights::UserHasRightTo($arIBlock['ID'], $arIBlock['ID'], 'element_edit'))
				{
					$dbRes = CIBlockElement::GetList(array(), array(
						'ID' => $params['ID'],
						'IBLOCK_ID' => $arIBlock['ID']
					), false, false, array('ID'));
					$arRes = $dbRes->Fetch();

					if($arRes)
					{
						$arItemFields = self::prepareItem($params, $arIBlock, $server);

						if(count($arItemFields) > 0)
						{
							$ib = new CIBlockElement();
							$PROPS = false;

							if(isset($arItemFields['PROPERTY_VALUES']))
							{
								$PROPS = $arItemFields['PROPERTY_VALUES'];
								unset($arItemFields['PROPERTY_VALUES']);
							}

							if(isset($arItemFields["PREVIEW_PICTURE"]) && $arItemFields["PREVIEW_PICTURE"] == false)
							{
								$arItemFields["PREVIEW_PICTURE"] = array("del" => "Y");
							}

							if(isset($arItemFields["DETAIL_PICTURE"]) && $arItemFields["DETAIL_PICTURE"] == false)
							{
								$arItemFields["DETAIL_PICTURE"] = array("del" => "Y");
							}

							$res = $ib->Update($arRes['ID'], $arItemFields);
							if($res)
							{
								if($PROPS)
								{
									CIBlockElement::SetPropertyValuesEx($arRes['ID'], $arIBlock['ID'], $PROPS);
								}
							}
							else
							{
								throw new RestException($ib->LAST_ERROR, RestException::ERROR_CORE);
							}
						}

						return true;
					}
					else
					{
						throw new RestException('Item not found', self::ERROR_ITEM_NOT_FOUND);
					}
				}
				else
				{
					throw new AccessException();
				}
			}
			else
			{
				throw new RestException('Entity not found', self::ERROR_ENTITY_NOT_FOUND);
			}
		}
	}
}