- Модуль: rest
- Путь к файлу: ~/bitrix/modules/rest/lib/api/userfieldtype.php
- Класс: BitrixRestApiUserFieldType
- Вызов: UserFieldType::update
static function update($param, $n, CRestServer $server)
{
static::checkPermission($server);
$param = array_change_key_case($param, CASE_UPPER);
$userTypeId = toLower($param['USER_TYPE_ID']);
if($userTypeId == '')
{
throw new ArgumentNullException("USER_TYPE_ID");
}
$updateFields = array();
if(!empty($param['HANDLER']))
{
$appInfo = AppTable::getByClientId($server->getClientId());;
HandlerHelper::checkCallback($param['HANDLER'], $appInfo);
$updateFields['PLACEMENT_HANDLER'] = $param['HANDLER'];
}
if (array_key_exists('OPTIONS', $param))
{
$updateFields['OPTIONS'] = static::prepareOption($param['OPTIONS']);
}
$updateFields = array_merge(
$updateFields,
Lang::fillCompatibility(
$param,
[
'TITLE',
'DESCRIPTION',
],
[
'TITLE' => $updateFields['TITLE']
]
)
);
$langAll = [];
if ($updateFields['LANG_ALL'])
{
$langAll = $updateFields['LANG_ALL'];
}
unset($updateFields['LANG_ALL']);
if(count($updateFields) > 0)
{
$dbRes = PlacementTable::getList(array(
'filter' => array(
'=REST_APP.CLIENT_ID' => $server->getClientId(),
'=ADDITIONAL' => $userTypeId
),
'select' => array('ID', 'APP_ID', 'ADDITIONAL')
));
$placementInfo = $dbRes->fetch();
if($placementInfo)
{
$updateResult = PlacementTable::update($placementInfo['ID'], $updateFields);
if($updateResult->isSuccess())
{
PlacementLangTable::deleteByPlacement($placementInfo['ID']);
foreach ($langAll as $lang => $item)
{
$item['PLACEMENT_ID'] = $placementInfo['ID'];
$item['LANGUAGE_ID'] = $lang;
$res = PlacementLangTable::add($item);
if (!$res->isSuccess())
{
throw new RestException(
'Error: ' . implode(', ', $res->getErrorMessages()),
RestException::ERROR_CORE
);
}
}
// rebind handler for failover reasons
Callback::bind($placementInfo);
}
else
{
$errorMessage = $updateResult->getErrorMessages();
throw new RestException(
'Unable to update User Field Type: '.implode(', ', $errorMessage),
RestException::ERROR_CORE
);
}
}
else
{
throw new RestException('User Field Type not found', RestException::ERROR_NOT_FOUND);
}
}
else
{
throw new ArgumentNullException('HANDLER|TITLE|DESCRIPTION');
}
return true;
}