CCrmRequisiteLinkRestProxy::processMethodRequest

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmRequisiteLinkRestProxy
  4. processMethodRequest
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/restservice.php
  • Класс: \CCrmRequisiteLinkRestProxy
  • Вызов: CCrmRequisiteLinkRestProxy::processMethodRequest
public function processMethodRequest($name, $nameDetails, $arParams, $nav, $server)
{
	$name = mb_strtoupper($name);
	if($name === 'LINK')
	{
		$fieldsInfo = $this->getFieldsInfo();

		$nameSuffix = mb_strtoupper(!empty($nameDetails)? implode('_', $nameDetails) : '');
		if ($nameSuffix === 'FIELDS' || $nameSuffix === 'LIST')
		{
			return parent::processMethodRequest($nameSuffix, '', $arParams, $nav, $server);
		}
		else if ($nameSuffix === 'GET')
		{
			$entityTypeId = intval($this->resolveParam($arParams, 'entityTypeId'));
			$entityId = intval($this->resolveParam($arParams, 'entityId'));

			$availableEntityTypeIds = \Bitrix\Crm\Requisite\EntityLink::getAvailableEntityTypeIds();
			if (!isset($availableEntityTypeIds[$entityTypeId]))
			{
				$errors[] = 'entityTypeId is not defined or invalid.';
				return false;
			}
			if(!$this->checkEntityID($entityId))
			{
				$errors[] = 'entityId is not defined or invalid.';
				return false;
			}

			$errors = array();
			$result = $this->getEntityRequisite($entityTypeId, $entityId, $errors);
			if(!is_array($result))
			{
				throw new RestException(implode("\n", $errors));
			}
			$this->externalizeFields($result, $fieldsInfo);
			return $result;
		}
		else if ($nameSuffix === 'REGISTER')
		{
			$fields = $this->resolveArrayParam($arParams, 'fields');
			$methodParams = $this->resolveArrayParam($arParams, 'params');
			$this->internalizeFields($fields, $fieldsInfo, array());
			$errors = array();
			if(!$this->innerRegister($fields, $errors, $methodParams))
			{
				throw new RestException(implode("\n", $errors));
			}

			return true;
		}
		else if ($nameSuffix === 'UNREGISTER')
		{
			$entityTypeId = intval($this->resolveParam($arParams, 'entityTypeId'));
			$entityId = intval($this->resolveParam($arParams, 'entityId'));

			$availableEntityTypeIds = \Bitrix\Crm\Requisite\EntityLink::getAvailableEntityTypeIds();
			if (!isset($availableEntityTypeIds[$entityTypeId]))
			{
				$errors[] = 'entityTypeId is not defined or invalid.';
				return false;
			}
			if(!$this->checkEntityID($entityId))
			{
				throw new RestException('entityId is not defined or invalid.');
			}

			$errors = array();
			if(!$this->innerUnregister($entityTypeId, $entityId, $errors))
			{
				throw new RestException(implode("\n", $errors));
			}

			return true;
		}
	}

	throw new RestException("Resource '{$name}' is not supported in current context.");
}

Добавить комментарий