Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
user.php
1<?php
2
10
13
14class User
15{
16 protected static string $userTableClass = UserTable::class;
17
18 public static function getCurrentUserId(): int
19 {
20 global $USER;
21
22 return (int)$USER->getId();
23 }
24
25 public static function getUserListNameFormatted(array $userIdList = [], $params = []): array
26 {
27 static $cache = [];
28
29 $nameFormat = ($params['nameFormat'] ?? \CSite::getNameFormat());
30
31 $result = [];
32
33 $userIdList = array_map(static function ($userId) {
34 return (int)$userId;
35 }, $userIdList);
36
37 $userIdList = array_filter($userIdList, static function ($userId) {
38 return $userId > 0;
39 });
40
41 $userIdList = array_unique($userIdList);
42
43 if (empty($userIdList))
44 {
45 return $result;
46 }
47
48 if (!isset($cache[$nameFormat]))
49 {
50 $cache[$nameFormat] = [];
51 }
52
53 $result = array_filter($cache[$nameFormat], function($cacheItem, $userId) use ($userIdList) {
54 return in_array($userId, $userIdList);
55 }, ARRAY_FILTER_USE_BOTH);
56
57 $userIdListToGet = array_diff($userIdList, array_keys($cache[$nameFormat]));
58 if (!empty($userIdListToGet))
59 {
60 $res = self::$userTableClass::getList([
61 'filter' => [
62 '@ID' => $userIdListToGet,
63 ],
64 'select' => [
65 'ID',
66 'LOGIN',
67 'EMAIL',
68 'NAME',
69 'SECOND_NAME',
70 'LAST_NAME',
71 ],
72 ]);
73
74 $useLogin = ModuleManager::isModuleInstalled('intranet');
75
76 while ($userFields = $res->fetch())
77 {
78 $value = \CUser::FormatName($nameFormat, $userFields, $useLogin, false);
79 $result[(int)$userFields['ID']] = $value;
80 $cache[$nameFormat][(int)$userFields['ID']] = $value;
81 }
82 }
83
84 return $result;
85 }
86}
static getUserListNameFormatted(array $userIdList=[], $params=[])
Definition user.php:25
static string $userTableClass
Definition user.php:16