CCrmAddressRestProxy::processEvent

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmAddressRestProxy
  4. processEvent
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/restservice.php
  • Класс: \CCrmAddressRestProxy
  • Вызов: CCrmAddressRestProxy::processEvent
static function processEvent(array $arParams, array $arHandler)
{
	$eventName = $arHandler['EVENT_NAME'];
	switch(mb_strtolower($eventName))
	{
		case 'oncrmaddressregister':
		case 'oncrmaddressunregister':

			$fields = isset($arParams[0])? $arParams[0]->getParameter('fields') : null;

			$typeID = is_array($fields) && isset($fields['TYPE_ID'])? (int)$fields['TYPE_ID'] : 0;
			$entityTypeID = is_array($fields) && isset($fields['ENTITY_TYPE_ID'])? (int)$fields['ENTITY_TYPE_ID'] : 0;
			$entityID = is_array($fields) && isset($fields['ENTITY_ID'])? (int)$fields['ENTITY_ID'] : 0;

			$address = new static();

			if(!$address->isValidID($typeID) || !EntityAddressType::isDefined($typeID))
			{
				throw new RestException("Could not find TYPE_ID in fields of event \"{$eventName}\"");
			}
			if(!$address->isValidID($entityTypeID) || !CCrmOwnerType::IsDefined($entityTypeID))
			{
				throw new RestException("Could not find ENTITY_TYPE_ID in fields of event \"{$eventName}\"");
			}
			if(!$address->checkEntityID($entityID))
			{
				throw new RestException("Could not find ENTITY_ID in fields of event \"{$eventName}\"");
			}

			if(mb_strtolower($eventName) == 'oncrmaddressunregister')
			{
				$r = \Bitrix\Crm\AddressTable::getList(array(
					'select' => array(
						'ANCHOR_ID',
						'ANCHOR_TYPE_ID'
					),
					'filter' => array(
						'=ENTITY_ID' => $entityID,
						'=ENTITY_TYPE_ID' => $entityTypeID,
						'=TYPE_ID' => $typeID,
					)
				));

				if($addressFields = $r->fetch())
				{
					$anchorID = (int)$addressFields['ANCHOR_ID'];
					$anchorTypeID = (int)$addressFields['ANCHOR_TYPE_ID'];
				}

			}
			else
			{
				$anchorID = is_array($fields) && isset($fields['ANCHOR_ID'])? (int)$fields['ANCHOR_ID'] : 0;
				$anchorTypeID = is_array($fields) && isset($fields['ANCHOR_TYPE_ID'])? (int)$fields['ANCHOR_TYPE_ID'] : 0;
			}

			if(!$address->isValidID($anchorTypeID) || !CCrmOwnerType::IsDefined($anchorTypeID))
			{
				throw new RestException("Could not find ANCHOR_TYPE_ID in fields of event \"{$eventName}\"");
			}
			if(!$address->checkEntityID($anchorID))
			{
				throw new RestException("Could not find ANCHOR_ID in fields of event \"{$eventName}\"");
			}

			return array('FIELDS' => array('TYPE_ID' => EntityAddressType::resolveName($typeID), 'ENTITY_TYPE_ID' => CCrmOwnerType::resolveName($entityTypeID), 'ENTITY_ID' => $entityID, 'ANCHOR_ID' => $anchorID, 'ANCHOR_TYPE_ID' => CCrmOwnerType::resolveName($anchorTypeID)));
			break;
		default:
			throw new RestException("The Event \"{$eventName}\" is not supported in current context");
	}
}

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