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

	$fields = isset($params['FIELDS']) && is_array($params['FIELDS']) ? $params['FIELDS'] : null;
	if (is_array($fields))
	{
		$fieldsMap = $params['FIELDS_MAP'] ?? null;
		if (is_array($fieldsMap))
		{
			$fields = EntityFieldsHelper::replaceFieldNamesByMap($fields, $fieldsMap);
		}
	}
	else
	{
		$fields = self::getEntity($ownerID);
	}

	if(!is_array($fields))
	{
		return;
	}

	$settings = array();
	if(isset($fields['SOURCE_ID']))
	{
		$settings['SOURCE_ID'] = $fields['SOURCE_ID'];
	}

	$authorID = self::resolveCreatorID($fields);
	$historyEntryID = CreationEntry::create(
		array(
			'ENTITY_TYPE_ID' => \CCrmOwnerType::Lead,
			'ENTITY_ID' => $ownerID,
			'AUTHOR_ID' => $authorID,
			'SETTINGS' => $settings,
			'BINDINGS' => array(
				array(
					'ENTITY_TYPE_ID' => \CCrmOwnerType::Lead,
					'ENTITY_ID' => $ownerID
				)
			)
		)
	);

	$enableHistoryPush = $historyEntryID > 0;
	if($enableHistoryPush && Main\Loader::includeModule('pull'))
	{
		$pushParams = array('ID' => $ownerID);
		if($enableHistoryPush)
		{
			$historyFields = TimelineEntry::getByID($historyEntryID);
			if(is_array($historyFields))
			{
				$pushParams['HISTORY_ITEM'] = $this->prepareHistoryDataModel(
					$historyFields,
					array('ENABLE_USER_INFO' => true)
				);
			}
		}

		$tag = $pushParams['TAG'] = TimelineEntry::prepareEntityPushTag(\CCrmOwnerType::Lead, 0);
		\CPullWatch::AddToStack(
			$tag,
			array(
				'module_id' => 'crm',
				'command' => self::ADD_EVENT_NAME,
				'params' => $pushParams,
			)
		);
	}

	$this->createManualOpportunityModificationEntryIfNeeded($ownerID, $authorID, $fields);
}