• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/lib/helper/user.php
  • Класс: BitrixSocialnetworkHelperUser
  • Вызов: User::getUserListNameFormatted
static function getUserListNameFormatted(array $userIdList = [], $params = []): array
{
	static $cache = [];

	$nameFormat = ($params['nameFormat'] ?? CSite::getNameFormat());

	$result = [];

	$userIdList = array_map(static function ($userId) {
		return (int)$userId;
	}, $userIdList);

	$userIdList = array_filter($userIdList, static function ($userId) {
		return $userId > 0;
	});

	$userIdList = array_unique($userIdList);

	if (empty($userIdList))
	{
		return $result;
	}

	if (!isset($cache[$nameFormat]))
	{
		$cache[$nameFormat] = [];
	}

	$result = array_filter($cache[$nameFormat], function($cacheItem, $userId) use ($userIdList) {
		return in_array($userId, $userIdList);
	}, ARRAY_FILTER_USE_BOTH);

	$userIdListToGet = array_diff($userIdList, array_keys($cache[$nameFormat]));
	if (!empty($userIdListToGet))
	{
		$res = self::$userTableClass::getList([
			'filter' => [
				'@ID' => $userIdListToGet,
			],
			'select' => [
				'ID',
				'LOGIN',
				'EMAIL',
				'NAME',
				'SECOND_NAME',
				'LAST_NAME',
			],
		]);

		$useLogin = ModuleManager::isModuleInstalled('intranet');

		while ($userFields = $res->fetch())
		{
			$value = CUser::FormatName($nameFormat, $userFields, $useLogin, false);
			$result[(int)$userFields['ID']] = $value;
			$cache[$nameFormat][(int)$userFields['ID']] = $value;
		}
	}

	return $result;
}