Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
UserCollection.php
1<?php
2
4
10
17{
18 public function __construct(array $usersIds = [])
19 {
20 parent::__construct();
21
22 foreach ($usersIds as $userId)
23 {
24 $this[] = User::getInstance($userId);
25 }
26 }
27
28 public function fillOnlineData(bool $withStatus = false): void
29 {
30 $idsUsersWithoutOnlineData = [];
31
32 foreach ($this as $user)
33 {
34 if (!$user->isOnlineDataFilled($withStatus))
35 {
36 $idsUsersWithoutOnlineData[] = $user->getId();
37 }
38 }
39
40 $idsUsersWithoutOnlineData = array_unique($idsUsersWithoutOnlineData);
41
42 if (empty($idsUsersWithoutOnlineData))
43 {
44 return;
45 }
46
48 $query = UserTable::query()
49 ->setSelect($select)
50 ->whereIn('ID', $idsUsersWithoutOnlineData)
51 ;
52 if ($withStatus)
53 {
54 $query->registerRuntimeField(
55 new Reference(
56 'STATUS',
57 StatusTable::class,
58 Join::on('this.ID', 'ref.USER_ID'),
59 ['join_type' => Join::TYPE_LEFT]
60 )
61 );
62 }
63 $statusesData = $query->fetchAll() ?: [];
64
65 foreach ($statusesData as $statusData)
66 {
67 $this->getById((int)$statusData['USER_ID'])->setOnlineData($statusData, $withStatus);
68 }
69 }
70
71 public function filterExtranet(): self
72 {
73 $filteredUsers = new static();
74
75 foreach ($this as $user)
76 {
77 if (!$user->isExtranet())
78 {
79 $filteredUsers[] = $user;
80 }
81 }
82
83 return $filteredUsers;
84 }
85
86 public static function filterOnlineUserId(array $userIds): array
87 {
88 if (empty($userIds))
89 {
90 return [];
91 }
92
93 $result = UserTable::query()
94 ->setSelect(['ID'])
95 ->whereIn('ID', $userIds)
96 ->where('IS_ONLINE', true)
97 ->fetchAll()
98 ;
99 $onlineUsers = [];
100 foreach ($result as $row)
101 {
102 $onlineUsers[] = (int)$row['ID'];
103 }
104
105 return $onlineUsers;
106 }
107
108 public function toRestFormat(array $option = []): array
109 {
110 $this->fillOnlineData();
111
112 return parent::toRestFormat($option);
113 }
114
115 public static function getRestEntityName(): string
116 {
117 return 'users';
118 }
119
126 public function offsetSet($offset, $value): void
127 {
129 if (!$value->isExist())
130 {
131 return;
132 }
133
134 parent::offsetSet($offset, $value);
135 }
136}
const ONLINE_DATA_SELECTED_FIELDS_WITHOUT_STATUS
Definition User.php:37