- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/classes/general/restservice.php
- Класс: \CCrmRequisitePresetFieldRestProxy
- Вызов: CCrmRequisitePresetFieldRestProxy::processMethodRequest
public function processMethodRequest($name, $nameDetails, $arParams, $nav, $server)
{
$errors = array();
$name = mb_strtoupper($name);
$presetId = 0;
if($name !== 'FIELDS')
{
$preset = $this->resolveArrayParam($arParams, 'preset');
if(!is_array($preset))
{
throw new RestException("Parameter 'PRESET' is not specified or incorrect.");
}
$presetId = intval($this->resolveParam($preset, 'ID'));
if(!$this->checkEntityID($presetId))
{
throw new RestException('PRESET[ID] is not defined or invalid.');
}
}
$fieldsInfo = $this->getFieldsInfo();
if($name === 'AVAILABLETOADD')
{
$preset = new EntityPreset();
$result = $preset->getSettingsFieldsAvailableToAdd(EntityPreset::Requisite, $presetId);
if (is_object($result))
{
if($result->isSuccess())
{
$result = $result->getData();
}
else
{
throw new RestException(implode("\n", $result->getErrors()));
}
}
else
{
throw new RestException('Error when getting fields.');
}
return $result;
}
elseif($name === 'FIELDS')
{
return parent::processMethodRequest($name, '', $arParams, $nav, $server);
}
elseif($name === 'ADD')
{
$fields = $this->resolveArrayParam($arParams, 'fields');
$this->internalizeFields($fields, $fieldsInfo, array());
$errors = array();
$result = $this->innerAddField($presetId, $fields, $errors);
if($this->isValidID($result))
{
return $result;
}
if(empty($errors))
{
$errors[] = "Failed to add. General error.";
}
throw new RestException(implode("\n", $errors));
}
elseif($name === 'GET')
{
$id = intval($this->resolveParam($arParams, 'ID'));
if(!$this->isValidID($id))
{
throw new RestException('ID is not defined or invalid.');
}
$errors = array();
$result = $this->innerGetFields($presetId, $id, $errors);
if(is_array($result))
{
$this->externalizeFields($result, $fieldsInfo);
return $result;
}
if(empty($errors))
{
$errors[] = "Failed to get. General error.";
}
throw new RestException(implode("\n", $errors));
}
elseif($name === 'LIST')
{
$errors = array();
$result = $this->innerGetListFields($presetId, $errors);
if(is_array($result))
{
return $result;
}
if(empty($errors))
{
$errors[] = "Failed to get list. General error.";
}
throw new RestException(implode("\n", $errors));
}
elseif($name === 'UPDATE')
{
$fields = $this->resolveArrayParam($arParams, 'fields');
$id = intval($this->resolveParam($arParams, 'ID'));
if(!$this->checkEntityID($id))
{
throw new RestException('ID is not defined or invalid.');
}
$this->internalizeFields($fields, $fieldsInfo, array());
$errors = array();
$result = $this->innerUpdateFields($presetId, $id, $fields, $errors);
if($this->isValidID($result))
{
return true;
}
if(empty($errors))
{
$errors[] = "Failed to update. General error.";
}
throw new RestException(implode("\n", $errors));
}
elseif($name === 'DELETE')
{
$id = intval($this->resolveParam($arParams, 'ID'));
if(!$this->isValidID($id))
{
throw new RestException('ID is not defined or invalid.');
}
$result = $this->innerDeleteField($presetId, $id, $errors);
if($result)
{
return true;
}
if(empty($errors))
{
$errors[] = "Failed to delete. General error.";
}
throw new RestException(implode("\n", $errors));
}
throw new RestException("Resource '{$name}' is not supported in current context.");
}