• Модуль: imopenlines
  • Путь к файлу: ~/bitrix/modules/imopenlines/lib/widget/formhandler.php
  • Класс: BitrixImOpenLinesWidgetFormHandler
  • Вызов: FormHandler::createCrmActivity
private function createCrmActivity(): bool
{
	if ($this->isWelcomeForm && !$this->messageId)
	{
		return false;
	}

	$crmManager = new Crm($this->session);
	$bindings = [];
	$entities = [];
	foreach ($this->crmEntities as $entity)
	{
		if (in_array($entity['ENTITY_TYPE'], [Crm::ENTITY_CONTACT, Crm::ENTITY_DEAL, Crm::ENTITY_LEAD], true))
		{
			$entityTypeId = CCrmOwnerType::ResolveId($entity['ENTITY_TYPE']);
			$bindings[] = [
				'OWNER_TYPE_ID' => $entityTypeId,
				'OWNER_ID' => $entity['ENTITY_ID']
			];
			$entities[] = [
				'ENTITY_TYPE_ID' => $entityTypeId,
				'ENTITY_ID' => $entity['ENTITY_ID']
			];
		}
	}
	$userCode = $this->session->getData('USER_CODE');
	if (!$userCode)
	{
		return false;
	}

	$activityName = Loc::getMessage('IMOL_CRM_CREATE_ACTIVITY_2',
		['#LEAD_NAME#' => $this->chat->getData('TITLE'), '#CONNECTOR_NAME#' => CrmCommon::getSourceName($userCode)]
	);

	$result = CrmActivity::add([
		'LINE_ID' => $this->configId,
		'NAME' => $activityName,
		'SESSION_ID' => $this->session->getData('ID'),
		'MODE' => $this->session->getData('MODE'),
		'BINDINGS' => $bindings,
		'OPERATOR_ID' => $crmManager->getResponsibleCrmId(),
		'USER_CODE' => $userCode,
		'CONNECTOR_ID' => $this->connectorId,
		'ENTITES' => $entities
	]);

	if ($result->isSuccess())
	{
		$this->session->updateCrmFlags([
			'CRM_ACTIVITY_ID' => $result->getResult()
		]);
	}

	return $result->isSuccess();
}