1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
livewatchservice.php
См. документацию.
1<?php
2
3namespace Bitrix\Socialnetwork\Internals\Space\LiveWatch;
4
5use Bitrix\Main\Application;
6use Bitrix\Main\DB\SqlExpression;
7
9{
10 private const TTL = 900; // 15 minutes
11 private const LIMIT = 5000;
12
13 private $whoisWatchingNow;
14
15 private static $instance;
16
17 public static function getInstance(): self
18 {
19 if (!self::$instance)
20 {
21 self::$instance = new self();
22 }
23
24 return self::$instance;
25 }
26
27 private function __construct()
28 {
29
30 }
31
32 public function setUserAsWatchingNow(int $userId): void
33 {
34 $helper = Application::getConnection()->getSqlHelper();
35 $now = new SqlExpression($helper->getCurrentDateTimeFunction());
36
37 $insertFields = [
38 "USER_ID" => $userId,
39 "DATETIME" => $now,
40 ];
41
42 $updateFields = [
43 "DATETIME" => $now,
44 ];
45
46 LiveWatchTable::merge($insertFields, $updateFields);
47
48 if ($this->whoisWatchingNow)
49 {
50 $this->whoisWatchingNow[$userId] = true;
51 }
52 }
53
54 public function isUserWatchingSpaces(int $userId): bool
55 {
56 if (!$this->whoisWatchingNow)
57 {
58 $this->whoisWatchingNow = [];
59 $helper = Application::getConnection()->getSqlHelper();
60 $ttlSecondsBack = new SqlExpression($helper->addSecondsToDateTime(-self::TTL));
61
63 'select' => ['USER_ID', 'DATETIME'],
64 'filter' => [
65 '>DATETIME' => $ttlSecondsBack,
66 ],
67 'limit' => self::LIMIT,
68 ]);
69
70 if (!$res)
71 {
72 return false;
73 }
74
75 foreach ($res as $watching)
76 {
77 $this->whoisWatchingNow[$watching['USER_ID']] = true;
78 }
79 }
80
81 return isset($this->whoisWatchingNow[$userId]);
82 }
83
84 public function removeStaleRecords(): void
85 {
86 $helper = Application::getConnection()->getSqlHelper();
87 $ttlSecondsBack = new SqlExpression($helper->addSecondsToDateTime(-self::TTL));
88
89 LiveWatchTable::deleteByFilter([
90 '<DATETIME' => $ttlSecondsBack,
91 ]);
92 }
93}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getList(array $parameters=array())
Определения datamanager.php:431
$res
Определения filter_act.php:7