• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/timeline/externalnoticecontroller.php
  • Класс: Bitrix\Crm\Timeline\ExternalNoticeController
  • Вызов: ExternalNoticeController::onReceive
public function onReceive($ownerID, $ownerTypeID, array $params)
{
	if(!is_int($ownerID))
	{
		$ownerID = (int)$ownerID;
	}
	if($ownerID <= 0)
	{
		throw new Main\ArgumentException('Owner ID must be greater than zero.', 'ownerID');
	}

	if(!\CCrmOwnerType::IsDefined((int)$ownerTypeID))
	{
		throw new Main\ArgumentException('Owner Type ID is not defined.', 'ownerTypeID');
	}

	$messageType = $params['TYPE_CATEGORY_ID'] ?? TimelineType::MODIFICATION;
	$messageType = (int)$messageType;

	if($messageType <= 0)
	{
		throw new Main\ArgumentException('Type category ID must be greater than zero.', '$messageType');
	}

	$fields = isset($params['ENTITY_FIELDS']) && is_array($params['ENTITY_FIELDS']) ? $params['ENTITY_FIELDS'] : [];

	$settings = [
		'ENTITY_TYPE_ID' => (int)$params['ENTITY_TYPE_ID'],
		'LEGEND' => $params['LEGEND'] ?? '',
	];

	if ($messageType === TimelineType::MODIFICATION)
	{
		$settings['FIELD_NAME'] = isset($params['FIELD_NAME']) ? (string)$params['FIELD_NAME'] : '';
		$settings['CURRENT_VALUE'] = isset($params['CURRENT_VALUE']) ? (string)$params['CURRENT_VALUE'] : '';
		$settings['PREVIOUS_VALUE'] = isset($params['PREVIOUS_VALUE']) ? (string)$params['PREVIOUS_VALUE'] : '';
		$settings['MODIFIED_FIELD'] = $settings['FIELD_NAME'];
	}

	if ($fields['DATE_INSERT'] instanceof Main\Type\Date)
	{
		$settings['DATE_INSERT_TIMESTAMP'] = $fields['DATE_INSERT']->getTimestamp();
	}

	$authorID = self::resolveCreatorID($params);

	$tag = TimelineEntry::prepareEntityPushTag($ownerTypeID, $ownerID);
	$historyEntryID = ExternalNoticeEntry::create(
		array(
			'ENTITY_TYPE_ID' => $ownerTypeID,
			'ENTITY_ID' => $ownerID,
			'TYPE_CATEGORY_ID' => $messageType,
			'AUTHOR_ID' => $authorID,
			'SETTINGS' => $settings,
		)
	);

	if($historyEntryID > 0)
	{
		self::pushHistoryEntry($historyEntryID, $tag,'timeline_rest_notification_add');
	}
}