EventHandler::onAfterPostingSendRecipientMultiple

  1. Bitrix24 API (v. 23.675.0)
  2. sender
  3. EventHandler
  4. onAfterPostingSendRecipientMultiple
  • Модуль: sender
  • Путь к файлу: ~/bitrix/modules/sender/lib/integration/crm/eventhandler.php
  • Класс: Bitrix\Sender\Integration\Crm\EventHandler
  • Вызов: EventHandler::onAfterPostingSendRecipientMultiple
static function onAfterPostingSendRecipientMultiple(array $eventDataArray, Entity\Letter $letter)
{
	static $isModuleIncluded = null;

	if ($isModuleIncluded === null)
	{
		$isModuleIncluded = Loader::includeModule('crm');
	}

	if (!$isModuleIncluded)
	{
		return;
	}

	if ($letter->getMessage()->isReturnCustomer())
	{
		return;
	}

	$dataToInsert = [];
	foreach($eventDataArray as $eventData)
	{
		$recipient = $eventData['RECIPIENT'];
		$fields = $eventData['RECIPIENT']['FIELDS'];

		$entityId = $fields['CRM_ENTITY_ID'] ?? $recipient['CONTACT_ID'];

		if (!$entityId)
		{
			continue;
		}

		$dataToInsert[] = [
			'RECIPIENT_ID' => $recipient['ID'],
			'POSTING_ID' => $letter->getId(),
			'FIELDS' => Json::encode($fields),
			'ENTITY_ID' => $entityId,
			'CONTACT_TYPE_ID' => $recipient['CONTACT_TYPE_ID'],
			'CONTACT_CODE' => $recipient['CONTACT_CODE'],
		];
	}

	if($dataToInsert)
	{
		TimeLineQueueTable::addMulti($dataToInsert, true);
	}
}

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