• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/activity/provider/task.php
  • Класс: Bitrix\Crm\Activity\Provider\Task
  • Вызов: Task::bindExternalEntity
static function bindExternalEntity($entityId, array $bindings)
{
	$entityId = (int) $entityId;
	if ($entityId <= 0 || !Loader::includeModule('tasks'))
	{
		return false;
	}

	$task = \CTasks::getByID($entityId, false)->fetch();
	if(!is_array($task))
	{
		return false;
	}

	$ownerMap = array_fill_keys(
		isset($task['UF_CRM_TASK']) && is_array($task['UF_CRM_TASK']) ? $task['UF_CRM_TASK'] : array(),
		true
	);

	foreach($bindings as $binding)
	{
		$ownerTypeID = isset($binding['OWNER_TYPE_ID']) ? (int)$binding['OWNER_TYPE_ID'] : 0;
		$ownerID = isset($binding['OWNER_ID']) ? (int)$binding['OWNER_ID'] : 0;

		if(!\CCrmOwnerType::IsDefined($ownerTypeID) || $ownerID <= 0)
		{
			continue;
		}

		$ownerKey = \CCrmOwnerTypeAbbr::ResolveByTypeID($ownerTypeID).'_'.$ownerID;
		if(!isset($ownerMap[$ownerKey]))
		{
			$ownerMap[$ownerKey] = true;
		}
	}

	$taskEntity = new \CTasks();
	$taskEntity->Update($entityId, ['UF_CRM_TASK'=>array_keys($ownerMap)]);

	return true;
}