Task::legacySetBindings

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. Task
  4. legacySetBindings
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/activity/provider/tasks/task.php
  • Класс: Bitrix\Crm\Activity\Provider\Tasks\Task
  • Вызов: Task::legacySetBindings
static function legacySetBindings(array &$taskFields, array &$activity): void
{
	$taskOwners = $taskFields['UF_CRM_TASK'] ?? [];
	$ownerData = [];
	if (!is_array($taskOwners))
	{
		$taskOwners = [$taskOwners];
	}
	$activity['BINDINGS'] = [];
	if (\CCrmActivity::tryResolveUserFieldOwners($taskOwners, $ownerData, \CCrmUserType::getTaskBindingField()))
	{
		$bindingMap = [];
		foreach ($ownerData as $ownerInfo)
		{
			$ownerTypeId = \CCrmOwnerType::resolveID($ownerInfo['OWNER_TYPE_NAME']);
			$ownerId = (int)$ownerInfo['OWNER_ID'];

			$bindingMap["{$ownerTypeId}_{$ownerId}"] = [
				'OWNER_TYPE_ID' => $ownerTypeId,
				'OWNER_ID' => $ownerId,
			];
			$bindingMap = array_merge(
				$bindingMap,
				\CCrmActivity::getSubsidiaryEntityBindingMap($ownerTypeId, $ownerId)
			);
		}
		$bindings = array_values($bindingMap);
		if (count($bindings) > 1)
		{
			//Lead and Deals will be at beginning of list for take activity ownership
			usort(
				$bindings,
				function ($a, $b) {
					if ($a['OWNER_TYPE_ID'] == $b['OWNER_TYPE_ID'])
					{
						return 0;
					}
					return $a['OWNER_TYPE_ID'] > $b['OWNER_TYPE_ID'] ? 1 : -1;
				}
			);
		}
		$activity['BINDINGS'] = $bindings;
	}

	if (!empty($activity['BINDINGS']))
	{
		//Check for owner change
		$ownerTypeId = isset($activity['OWNER_TYPE_ID']) ? (int)$activity['OWNER_TYPE_ID']
			: \CCrmOwnerType::Undefined;
		$ownerId = isset($activity['OWNER_ID']) ? (int)$activity['OWNER_ID'] : 0;
		$ownerIsFound = false;
		foreach ($activity['BINDINGS'] as $binding)
		{
			if ($binding['OWNER_TYPE_ID'] === $ownerTypeId && $binding['OWNER_ID'] === $ownerId)
			{
				$ownerIsFound = true;
				break;
			}
		}

		if (!$ownerIsFound)
		{
			$binding = $activity['BINDINGS'][0];
			$activity['OWNER_TYPE_ID'] = $binding['OWNER_TYPE_ID'];
			$activity['OWNER_ID'] = $binding['OWNER_ID'];
		}
	}
}

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