• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/entity/lead.php
  • Класс: Bitrix\Crm\Entity\Lead
  • Вызов: Lead::setChildEntityIDs
static function setChildEntityIDs($ID, $childEntityTypeID, array $childEntityIDs)
{
	if($ID <= 0)
	{
		throw new Main\ArgumentException('Must be greater than zero.', 'ID');
	}

	if($childEntityTypeID <= 0)
	{
		throw new Main\ArgumentException('Must be greater than zero.', 'childEntityTypeID');
	}

	$childEntityIDs = array_filter(array_map('intval', $childEntityIDs));
	if(empty($childEntityIDs))
	{
		return;
	}

	$slug = implode(', ', $childEntityIDs);

	if($childEntityTypeID === \CCrmOwnerType::Contact)
	{
		Main\Application::getConnection()->queryExecute(
		/** @lang text*/
			"UPDATE b_crm_contact SET LEAD_ID = {$ID} WHERE ID IN({$slug})"
		);
	}
	elseif($childEntityTypeID === \CCrmOwnerType::Company)
	{
		Main\Application::getConnection()->queryExecute(
		/** @lang text*/
			"UPDATE b_crm_company SET LEAD_ID = {$ID} WHERE ID IN({$slug})"
		);
	}
	elseif($childEntityTypeID === \CCrmOwnerType::Deal)
	{
		Main\Application::getConnection()->queryExecute(
		/** @lang text*/
			"UPDATE b_crm_deal SET LEAD_ID = {$ID} WHERE ID IN({$slug})"
		);
	}
	elseif($childEntityTypeID === \CCrmOwnerType::Quote)
	{
		Main\Application::getConnection()->queryExecute(
		/** @lang text*/
			"UPDATE b_crm_quote SET LEAD_ID = {$ID} WHERE ID IN({$slug})"
		);
	}
	else
	{
		$entityTypeName = \CCrmOwnerType::ResolveName($childEntityTypeID);
		throw new Main\NotSupportedException("Entity type: '{$entityTypeName}' is not supported in current context");
	}

	Crm\Statistics\LeadConversionStatisticsEntry::register($ID);
}