1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
livewatchservice.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Socialnetwork\Internals\Space\LiveWatch;
4
5
use Bitrix\Main\Application;
6
use Bitrix\Main\DB\SqlExpression;
7
8
class
LiveWatchService
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
62
$res
=
LiveWatchTable::getList
([
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
}
$userId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения
check_mail.php:18
Bitrix\Main\DB\SqlExpression
Определения
sqlexpression.php:21
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Определения
datamanager.php:431
Bitrix\Socialnetwork\Internals\Space\LiveWatch\LiveWatchService
Определения
livewatchservice.php:9
Bitrix\Socialnetwork\Internals\Space\LiveWatch\LiveWatchService\setUserAsWatchingNow
setUserAsWatchingNow(int $userId)
Определения
livewatchservice.php:32
Bitrix\Socialnetwork\Internals\Space\LiveWatch\LiveWatchService\isUserWatchingSpaces
isUserWatchingSpaces(int $userId)
Определения
livewatchservice.php:54
Bitrix\Socialnetwork\Internals\Space\LiveWatch\LiveWatchService\removeStaleRecords
removeStaleRecords()
Определения
livewatchservice.php:84
Bitrix\Socialnetwork\Internals\Space\LiveWatch\LiveWatchService\getInstance
static getInstance()
Определения
livewatchservice.php:17
$res
$res
Определения
filter_act.php:7
bitrix
modules
socialnetwork
lib
internals
space
livewatch
livewatchservice.php
Создано системой
1.14.0