• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/rest/controllers/task.php
  • Класс: BitrixTasksRestControllersTask
  • Вызов: Task::fillUserInfo
private function fillUserInfo(array $rows): array
{
	static $users = [];

	$userIds = [];
	foreach ($rows as $row)
	{
		if (
			array_key_exists('CREATED_BY', $row)
			&& !array_key_exists($row['CREATED_BY'], $users)
		)
		{
			$userIds[] = (int)$row['CREATED_BY'];
		}
		if (
			array_key_exists('RESPONSIBLE_ID', $row)
			&& !array_key_exists($row['RESPONSIBLE_ID'], $users)
		)
		{
			$userIds[] = (int)$row['RESPONSIBLE_ID'];
		}
		if (array_key_exists('ACCOMPLICES', $row) && is_array($row['ACCOMPLICES']))
		{
			foreach ($row['ACCOMPLICES'] as $userId)
			{
				$userId = (int)$userId;
				if (!array_key_exists($userId, $users))
				{
					$userIds[] = $userId;
				}
			}
		}
		if (array_key_exists('AUDITORS', $row) && is_array($row['AUDITORS']))
		{
			foreach ($row['AUDITORS'] as $userId)
			{
				$userId = (int)$userId;
				if (!array_key_exists($userId, $users))
				{
					$userIds[] = $userId;
				}
			}
		}
	}
	$userIds = array_unique($userIds);

	$userResult = UserTable::getList([
		'select' => ['ID', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'LOGIN', 'PERSONAL_PHOTO', 'WORK_POSITION'],
		'filter' => ['ID' => $userIds],
	]);
	while ($user = $userResult->fetch())
	{
		$userId = $user['ID'];
		$userName = CUser::FormatName(
			CSite::GetNameFormat(),
			[
				'LOGIN' => $user['LOGIN'],
				'NAME' => $user['NAME'],
				'LAST_NAME' => $user['LAST_NAME'],
				'SECOND_NAME' => $user['SECOND_NAME'],
			],
			true,
			false
		);
		$replaceList = ['user_id' => $userId];
		$link = CComponentEngine::makePathFromTemplate('/company/personal/user/#user_id#/', $replaceList);

		$users[$userId] = [
			'ID' => $userId,
			'NAME' => $userName,
			'LINK' => $link,
			'ICON' => UIAvatar::getPerson($user['PERSONAL_PHOTO']),
			'WORK_POSITION' => $user['WORK_POSITION'],
		];
	}

	foreach ($rows as $id => $row)
	{
		if (array_key_exists('CREATED_BY', $row) && array_key_exists($row['CREATED_BY'], $users))
		{
			$rows[$id]['CREATOR'] = $users[$row['CREATED_BY']];
		}
		if (array_key_exists('RESPONSIBLE_ID', $row) && array_key_exists($row['RESPONSIBLE_ID'], $users))
		{
			$rows[$id]['RESPONSIBLE'] = $users[$row['RESPONSIBLE_ID']];
		}
		if (array_key_exists('ACCOMPLICES', $row) && is_array($row['ACCOMPLICES']))
		{
			$accomplicesData = [];
			foreach ($row['ACCOMPLICES'] as $userId)
			{
				if (array_key_exists($userId, $users))
				{
					$accomplicesData[$userId] = $users[$userId];
				}
			}
			$rows[$id]['ACCOMPLICES_DATA'] = $accomplicesData;
		}
		if (array_key_exists('AUDITORS', $row) && is_array($row['AUDITORS']))
		{
			$auditorsData = [];
			foreach ($row['AUDITORS'] as $userId)
			{
				if (array_key_exists($userId, $users))
				{
					$auditorsData[$userId] = $users[$userId];
				}
			}
			$rows[$id]['AUDITORS_DATA'] = $auditorsData;
		}
	}

	return $rows;
}