• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/integration/calendar/helper.php
  • Класс: Bitrix\Crm\Integration\Calendar\Helper
  • Вызов: Helper::sendLinkToClient
public function sendLinkToClient(
	int $entityId,
	int $contactId,
	int $contactTypeId,
	string $channelId,
	string $senderId
): Result
{
	$result = new Result();
	if (!$this->isAvailable())
	{
		$result->addError(new Error('Sharing is not available', 10010));

		return $result;
	}

	$contact = $this->getContactPhoneCommunications(
		$entityId,
		\CCrmOwnerType::Deal,
		$contactId,
		$contactTypeId,
	);

	if ($contact === null)
	{
		$result->addError(new Error('Contact not found', 10020));

		return $result;
	}

	$broker = Container::getInstance()->getEntityBroker(\CCrmOwnerType::Deal);
	if (!$broker)
	{
		$result->addError(new Error('Deal broker not found', 10030));

		return $result;
	}

	$deal = $broker->getById($entityId);
	if (!$deal)
	{
		$result->addError(new Error('Deal not found', 10040));

		return $result;
	}

	$ownerId = $deal->getAssignedById();

	$contactType = $contact['entityTypeId'];

	$factory = self::getLinkFactory();
	/** @var CrmDealLink $crmDealLink */
	$crmDealLink = $factory->getCrmDealLink($entityId, $ownerId, $contactId, $contactType);
	if (!$crmDealLink)
	{
		$crmDealLink = $factory->createCrmDealLink($ownerId, $entityId, $contactId, $contactType, $channelId, $senderId);
	}

	if ($crmDealLink->getSenderId() !== $senderId || $crmDealLink->getChannelId() !== $channelId)
	{
		$crmDealLink
			->setSenderId($senderId)
			->setChannelId($channelId)
		;

		(new CrmDealLinkMapper())->update($crmDealLink);
	}

	$result->setData(['linkHash' => $crmDealLink->getHash()]);

	Notification\Manager::getSenderInstance($crmDealLink)
		->setCrmDealLink($crmDealLink)
		->sendCrmSharingInvited()
	;

	return $result;
}