• Модуль: imopenlines
  • Путь к файлу: ~/bitrix/modules/imopenlines/lib/widget/formhandler.php
  • Класс: BitrixImOpenLinesWidgetFormHandler
  • Вызов: FormHandler::addCrmBindingToLines
private function addCrmBindingToLines(): bool
{
	$updateFields = [];
	$updateSession = [];
	foreach ($this->crmEntities as $entity)
	{
		switch ($entity['ENTITY_TYPE'])
		{
			case CCrmOwnerType::LeadName:
				$updateFields['LEAD'] = $entity['ENTITY_ID'];
				break;

			case CCrmOwnerType::DealName:
				$updateFields['DEAL'] = $entity['ENTITY_ID'];
				break;

			case CCrmOwnerType::ContactName:
				$updateFields['CONTACT'] = $entity['ENTITY_ID'];
				break;

			case CCrmOwnerType::CompanyName:
				$updateFields['COMPANY'] = $entity['ENTITY_ID'];
				break;
		}
	}

	//For backward compatibility, the most up-to-date entity.
	if (empty($updateFields))
	{
		return false;
	}

	if (!empty($updateFields['DEAL']))
	{
		$updateFields['ENTITY_TYPE'] = CCrmOwnerType::DealName;
		$updateFields['ENTITY_ID'] = $updateFields['DEAL'];
		$updateSession['CRM_CREATE_DEAL'] = 'Y';
	}
	else if (!empty($updateFields['LEAD']))
	{
		$updateFields['ENTITY_TYPE'] = CCrmOwnerType::LeadName;
		$updateFields['ENTITY_ID'] = $updateFields['LEAD'];
		$updateSession['CRM_CREATE_LEAD'] = 'Y';
	}
	else if (!empty($updateFields['COMPANY']))
	{
		$updateFields['ENTITY_TYPE'] = CCrmOwnerType::CompanyName;
		$updateFields['ENTITY_ID'] = $updateFields['COMPANY'];
		$updateSession['CRM_CREATE_COMPANY'] = 'Y';
	}
	else if (!empty($updateFields['CONTACT']))
	{
		$updateFields['ENTITY_TYPE'] = CCrmOwnerType::ContactName;
		$updateFields['ENTITY_ID'] = $updateFields['CONTACT'];
		$updateSession['CRM_CREATE_CONTACT'] = 'Y';
	}

	$updateFields['CRM'] = 'Y';

	if ($this->chat instanceof Chat)
	{
		$this->chat->setCrmFlag($updateFields);
	}
	if ($this->session instanceof Session)
	{
		$this->session->updateCrmFlags($updateSession);
	}

	return true;
}