CCrmRestProxyBase::processEntityEvent

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmRestProxyBase
  4. processEntityEvent
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/restservice.php
  • Класс: \CCrmRestProxyBase
  • Вызов: CCrmRestProxyBase::processEntityEvent
static function processEntityEvent($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;
	if(mb_strpos(mb_strtoupper($eventName), $eventNamePrefix) !== 0)
	{
		throw new RestException("The Event \"{$eventName}\" is not supported in current context");
	}

	$eventNamePrefix .= 'USERFIELD';
	if(mb_strpos(mb_strtoupper($eventName), $eventNamePrefix) === 0)
	{
		return self::processEntityUserFieldEvent($entityTypeID, $arParams, $arHandler);
	}

	$action = mb_substr($eventName, 5 + mb_strlen($entityTypeName));
	if($action === false || $action === '')
	{
		throw new RestException("The Event \"{$eventName}\" is not supported in current context");
	}

	switch(mb_strtoupper($action))
	{
		case 'ADD':
		case 'UPDATE':
			{
				$fields = $arParams[0] ?? null;
				$ID = is_array($fields) && isset($fields['ID'])? (int)$fields['ID'] : 0;
			}
			break;
		case 'DELETE':
			{
				$ID = isset($arParams[0])? (int)$arParams[0] : 0;
			}
			break;
		default:
			throw new RestException("The Event \"{$eventName}\" is not supported in current context");
	}

	if($ID <= 0)
	{
		throw new RestException("Could not find entity ID in fields of event \"{$eventName}\"");
	}
	return array('FIELDS' => array('ID' => $ID));
}

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