EventHandler::OnChatFinish

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. EventHandler
  4. OnChatFinish
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/integration/imopenlines/eventhandler.php
  • Класс: Bitrix\Crm\Integration\ImOpenLines\EventHandler
  • Вызов: EventHandler::OnChatFinish
static function OnChatFinish(Event $event): void
{
	$parameters = $event->getParameters();
	$session = $parameters['RUNTIME_SESSION'];
	if (!$session instanceof Session)
	{
		return;
	}

	$activityId = (int)($session->getData('CRM_ACTIVITY_ID') ?? 0);
	if ($activityId <= 0)
	{
		return;
	}

	$activity = CCrmActivity::GetByID($activityId);
	if (!$activity)
	{
		return;
	}

	if (isset($activity['COMPLETED']) && $activity['COMPLETED'] === 'Y')
	{
		return;
	}

	$bindings = CCrmActivity::GetBindings($activityId);
	if (!$bindings)
	{
		return;
	}

	$userPermissions = Container::getInstance()->getUserPermissions()->getCrmPermissions();
	$isAtLeastOnePermissionEnabled = false;
	foreach ($bindings as $binding)
	{
		if (
			CCrmActivity::CheckCompletePermission(
				$binding['OWNER_TYPE_ID'],
				$binding['OWNER_ID'],
				$userPermissions,
				['FIELDS' => $activity]
			)
		)
		{
			$isAtLeastOnePermissionEnabled = true;

			break;
		}
	}

	if ($isAtLeastOnePermissionEnabled)
	{
		CCrmActivity::Complete(
			$activityId,
			true,
			[
				'REGISTER_SONET_EVENT' => true,
				'SKIP_BEFORE_HANDLER' => true,
			]
		);
	}
}

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