1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
UserProvider.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Socialnetwork\Provider;
6
7use Bitrix\Main\UserTable;
8use Bitrix\Socialnetwork\Helper\InstanceTrait;
9use Bitrix\Socialnetwork\Provider\User\User;
10use Bitrix\Socialnetwork\Provider\User\UserCollection;
11use CSite;
12use CUser;
13
15{
16 use InstanceTrait;
17
18 protected static array $users = [];
19
20 public function enrich(array $userIds): UserCollection
21 {
22 if (empty($userIds))
23 {
24 return new UserCollection();
25 }
26
27 $notStoredUserIds = $this->getNotStoredUserIds($userIds);
28 $storedUserIds = $this->getStoredUserIds($userIds);
29
30 $storedUsers = $this->getUsersFromStorage($storedUserIds);
31
32 $userCollection = new UserCollection(...$storedUsers);
33 if (empty($notStoredUserIds))
34 {
35 return $userCollection;
36 }
37
38 $select = [
39 'ID',
40 'NAME',
41 'LAST_NAME',
42 'SECOND_NAME',
43 'LOGIN',
44 'EMAIL',
45 'TITLE',
46 ];
47
48 $nameFormat = CSite::getNameFormat();
49
50 $users = UserTable::query()
51 ->setSelect($select)
52 ->whereIn('ID', $notStoredUserIds)
53 ->exec()
54 ->fetchCollection();
55
56 foreach ($users as $userEntity)
57 {
58 $fullName = CUser::FormatName(
60 [
61 'NAME' => $userEntity->getName(),
62 'LAST_NAME' => $userEntity->getLastName(),
63 'SECOND_NAME' => $userEntity->getSecondName(),
64 'LOGIN' => $userEntity->getLogin(),
65 'EMAIL' => $userEntity->getEmail(),
66 'TITLE' => $userEntity->getTitle(),
67 ],
68 true,
69 false
70 );
71
72 $user = new User(
73 id: $userEntity->getId(),
74 firstName: $userEntity->getName(),
75 lastName: $userEntity->getLastName(),
76 fullName: $fullName,
77 );
78
79 $userCollection->add($user);
80 }
81
82 return $userCollection;
83 }
84
85 protected function getNotStoredUserIds(array $userIds): array
86 {
87 return array_filter($userIds, static fn (int $userId): bool => !isset(static::$users[$userId]));
88 }
89
90 protected function getStoredUserIds(array $userIds): array
91 {
92 return array_filter($userIds, static fn (int $userId): bool => isset(static::$users[$userId]));
93 }
94
96 protected function getUsersFromStorage(array $userIds): array
97 {
98 return array_filter(static::$users, static fn (User $user): bool => in_array($user->getId(), $userIds, true));
99 }
100}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
getUsersFromStorage(array $userIds)
Определения UserProvider.php:96
getNotStoredUserIds(array $userIds)
Определения UserProvider.php:85
getStoredUserIds(array $userIds)
Определения UserProvider.php:90
$nameFormat
Определения discount_coupon_list.php:278
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$select
Определения iblock_catalog_list.php:194
$user
Определения mysql_to_pgsql.php:33