Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
user.php
1<?php
2
4
5use \Bitrix\Main\Application;
11
13{
14 function getLastSeenAction(array $userIds, bool $sendToQueueSever = false)
15 {
16 $userIds = array_map(fn ($a) => (int)$a, $userIds);
17 if (empty($userIds))
18 {
19 $this->addError(new Error("userIds should not be empty"));
20 }
21
22 $now = time();
23 $timestamps = [];
24 $result = [];
25
26 $cursor = UserTable::getList([
27 'select' => ['ID', 'LAST_ACTIVITY_DATE'],
28 'filter' => ['=ID' => $userIds],
29 ]);
30
31 foreach ($cursor->getIterator() as $row)
32 {
33 if ($row['LAST_ACTIVITY_DATE'] instanceof DateTime)
34 {
35 $userId = $row['ID'];
36 $lastSeen = $row['LAST_ACTIVITY_DATE']->getTimestamp();
37 $timestamps[$userId] = $lastSeen;
38 $result[$userId] = $now - $lastSeen;
39 }
40 }
41
42 if ($sendToQueueSever && !empty($timestamps))
43 {
44 Application::getInstance()->addBackgroundJob(
45 function (array $timestamps) {
46 (new JsonRpcTransport())->updateUsersLastSeen($timestamps);
47 },
48 [$timestamps]
49 );
50 }
51 return $result;
52 }
53}
getLastSeenAction(array $userIds, bool $sendToQueueSever=false)
Definition user.php:14