CCrmRestProxyBase::processEntityUserFieldEvent

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmRestProxyBase
  4. processEntityUserFieldEvent
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/restservice.php
  • Класс: \CCrmRestProxyBase
  • Вызов: CCrmRestProxyBase::processEntityUserFieldEvent
static function processEntityUserFieldEvent($entityTypeID, array $arParams, array $arHandler)
{
	$entityTypeName = CCrmOwnerType::ResolveName($entityTypeID);
	if($entityTypeName === '')
	{
		throw new RestException("The 'entityTypeName' is not specified");
	}

	$eventName = $arHandler['EVENT_NAME'];

	$eventNamePrefix = 'ONCRM'.$entityTypeName.'USERFIELD';
	if(mb_strpos(mb_strtoupper($eventName), $eventNamePrefix) !== 0)
	{
		throw new RestException("The Event \"{$eventName}\" is not supported in current context");
	}

	if (!($arParams[0] instanceof Bitrix\Main\Event))
	{
		throw new RestException("Invalid parameters of event \"{$eventName}\"");
	}

	$params = $arParams[0]->getParameters();

	$action = mb_substr($eventName, mb_strlen($eventNamePrefix));
	switch ($action)
	{
		case 'ADD':
		case 'UPDATE':
		case 'DELETE':
		case 'SETENUMVALUES':
			{
				$id = isset($params['id']) ? (int)$params['id'] : 0;
				$entityId = isset($params['entityId']) && is_string($params['entityId']) ?
					$params['entityId'] : '';
				$fieldName = isset($params['fieldName']) && is_string($params['fieldName']) ?
					$params['fieldName'] : '';

				if($id <= 0)
				{
					throw new RestException("Could not find parameter \"ID\" of event \"{$eventName}\"");
				}

				if($entityId === '')
				{
					throw new RestException("Could not find parameter \"ENTITY_ID\" of event \"{$eventName}\"");
				}

				if($fieldName === '')
				{
					throw new RestException("Could not find parameter \"FIELD_NAME\" of event \"{$eventName}\"");
				}

				return array('FIELDS' => array('ID' => $id, 'ENTITY_ID' => $entityId, 'FIELD_NAME' => $fieldName));
			}
			break;
		default:
			throw new RestException("The Event \"{$eventName}\" is not supported in current context");
	}
}

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