1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
calluser.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Im\Call;
4
5
use Bitrix\Im\Model\CallUserTable;
6
use Bitrix\Main\ArgumentException;
7
use Bitrix\Main\Type\DateTime;
8
9
class
CallUser
10
{
11
const
LAST_SEEN_THRESHOLD
= 75;
12
const
STATE_UNAVAILABLE
=
'unavailable'
;
13
const
STATE_IDLE
=
'idle'
;
14
const
STATE_CALLING
=
'calling'
;
15
const
STATE_DECLINED
=
'declined'
;
16
const
STATE_BUSY
=
'busy'
;
17
const
STATE_READY
=
'ready'
;
18
19
protected
$userId
;
20
protected
$callId
;
21
protected
$state
;
22
protected
$lastSeen
;
23
protected
$firstJoined
;
24
protected
$isMobile
;
25
protected
$sharedScreen
;
26
protected
$recorded
;
27
28
public
static
function
create
(
array
$fields
): static
29
{
30
if
(!isset(
$fields
[
'USER_ID'
]) || !
$fields
[
'USER_ID'
])
31
{
32
throw
new
ArgumentException
(
'USER_ID should be positive integer'
);
33
}
34
$instance
=
new
static
();
35
$instance
->setFields(
$fields
);
36
return
$instance
;
37
}
38
42
public
function
getState
()
43
{
44
// previous version with 'lastSeen' field check
45
// ($this->isSeenRecently() ? $this->state : static::STATE_IDLE)
46
// will return wrong state for new scheme
47
// because this field will not be updated during a call
48
// because 'ping' requests from client side were removed
49
return
$this->state
;
50
}
51
52
public
function
isSeenRecently
()
53
{
54
if
(!($this->lastSeen instanceof
DateTime
))
55
{
56
return
false
;
57
}
58
$now = time();
59
$delta
= $now - $this->lastSeen->getTimestamp();
60
return
$delta
<= static::LAST_SEEN_THRESHOLD;
61
}
62
63
public
function
updateState
(
$state
)
64
{
65
$fields
= [
'STATE'
=>
$state
];
66
if
(
$state
=== self::STATE_CALLING)
67
{
68
$fields
[
'LAST_SEEN'
] =
new
DateTime
();
69
}
70
$this->
update
(
$fields
);
71
}
72
76
public
function
getLastSeen
()
77
{
78
return
$this->lastSeen
;
79
}
80
86
public
function
updateLastSeen
(
DateTime
$lastSeen
)
87
{
88
$this->
update
([
'LAST_SEEN'
=> $lastSeen]);
89
}
90
91
public
function
getFirstJoined
() : ?
DateTime
92
{
93
return
$this->firstJoined
;
94
}
95
99
public
function
wasScreenShared
()
100
{
101
return
$this->sharedScreen
;
102
}
103
107
public
function
wasRecorded
()
108
{
109
return
$this->recorded
;
110
}
111
112
118
public
function
isActive
()
119
{
120
$seenRecently =
false
;
121
122
if
($this->lastSeen instanceof
DateTime
)
123
{
124
$now = time();
125
$delta
= $now - $this->lastSeen->getTimestamp();
126
$seenRecently =
$delta
<= static::LAST_SEEN_THRESHOLD;
127
}
128
129
return
in_array($this->state, [static::STATE_READY, static::STATE_CALLING]) && $seenRecently;
130
}
131
132
public
function
isUaMobile
()
133
{
134
return
$this->isMobile
;
135
}
136
137
public
function
setFields
(
array
$fields
)
138
{
139
$this->userId = array_key_exists(
'USER_ID'
,
$fields
) ?
$fields
[
'USER_ID'
] :
$this->userId
;
140
$this->callId = array_key_exists(
'CALL_ID'
,
$fields
) ?
$fields
[
'CALL_ID'
] :
$this->callId
;
141
$this->state = array_key_exists(
'STATE'
,
$fields
) ?
$fields
[
'STATE'
] :
$this->state
;
142
$this->lastSeen = array_key_exists(
'LAST_SEEN'
,
$fields
) ?
$fields
[
'LAST_SEEN'
] :
$this->lastSeen
;
143
$this->firstJoined = array_key_exists(
'FIRST_JOINED'
,
$fields
) ?
$fields
[
'FIRST_JOINED'
] :
$this->firstJoined
;
144
$this->isMobile = array_key_exists(
'IS_MOBILE'
,
$fields
) ?
$fields
[
'IS_MOBILE'
] ===
'Y'
:
$this->isMobile
;
145
$this->sharedScreen = array_key_exists(
'SHARED_SCREEN'
,
$fields
) ?
$fields
[
'SHARED_SCREEN'
] ===
'Y'
:
$this->sharedScreen
;
146
$this->recorded = array_key_exists(
'RECORDED'
,
$fields
) ?
$fields
[
'RECORDED'
] ===
'Y'
:
$this->recorded
;
147
}
148
149
public
function
save
()
150
{
151
CallUserTable::merge($this->
toArray
());
152
}
153
154
public
function
toArray
()
155
{
156
return
[
157
'USER_ID'
=>
$this->userId
,
158
'CALL_ID'
=>
$this->callId
,
159
'STATE'
=>
$this->state
,
160
'LAST_SEEN'
=>
$this->lastSeen
,
161
'FIRST_JOINED'
=>
$this->firstJoined
,
162
'IS_MOBILE'
=> is_bool($this->isMobile) ? $this->isMobile :
null
,
163
'SHARED_SCREEN'
=> is_bool($this->sharedScreen) ? $this->sharedScreen :
null
,
164
'RECORDED'
=> is_bool($this->recorded) ? $this->recorded : null
165
];
166
}
167
168
public
function
update
(
array
$fields
)
169
{
170
$updateResult = CallUserTable::update([
'CALL_ID'
=> $this->callId,
'USER_ID'
=> $this->userId],
$fields
);
171
172
if
($updateResult->isSuccess())
173
{
174
$updateData = $updateResult->getData();
175
$this->
setFields
($updateData);
176
}
177
$this->
setFields
($fields);
178
}
179
180
public
static
function
delete
(
$callId
,
$userId
)
181
{
182
CallUserTable::delete([
183
'CALL_ID'
=>
$callId
,
184
'USER_ID'
=>
$userId
185
]);
186
}
187
}
Bitrix\Im\Call\CallUser
Определения
calluser.php:10
Bitrix\Im\Call\CallUser\updateLastSeen
updateLastSeen(DateTime $lastSeen)
Определения
calluser.php:86
Bitrix\Im\Call\CallUser\STATE_BUSY
const STATE_BUSY
Определения
calluser.php:16
Bitrix\Im\Call\CallUser\updateState
updateState($state)
Определения
calluser.php:63
Bitrix\Im\Call\CallUser\$sharedScreen
$sharedScreen
Определения
calluser.php:25
Bitrix\Im\Call\CallUser\toArray
toArray()
Определения
calluser.php:154
Bitrix\Im\Call\CallUser\$firstJoined
$firstJoined
Определения
calluser.php:23
Bitrix\Im\Call\CallUser\$isMobile
$isMobile
Определения
calluser.php:24
Bitrix\Im\Call\CallUser\$recorded
$recorded
Определения
calluser.php:26
Bitrix\Im\Call\CallUser\$lastSeen
$lastSeen
Определения
calluser.php:22
Bitrix\Im\Call\CallUser\wasRecorded
wasRecorded()
Определения
calluser.php:107
Bitrix\Im\Call\CallUser\$userId
$userId
Определения
calluser.php:19
Bitrix\Im\Call\CallUser\STATE_DECLINED
const STATE_DECLINED
Определения
calluser.php:15
Bitrix\Im\Call\CallUser\wasScreenShared
wasScreenShared()
Определения
calluser.php:99
Bitrix\Im\Call\CallUser\isActive
isActive()
Определения
calluser.php:118
Bitrix\Im\Call\CallUser\getFirstJoined
getFirstJoined()
Определения
calluser.php:91
Bitrix\Im\Call\CallUser\STATE_IDLE
const STATE_IDLE
Определения
calluser.php:13
Bitrix\Im\Call\CallUser\STATE_CALLING
const STATE_CALLING
Определения
calluser.php:14
Bitrix\Im\Call\CallUser\STATE_UNAVAILABLE
const STATE_UNAVAILABLE
Определения
calluser.php:12
Bitrix\Im\Call\CallUser\STATE_READY
const STATE_READY
Определения
calluser.php:17
Bitrix\Im\Call\CallUser\create
static create(array $fields)
Определения
calluser.php:28
Bitrix\Im\Call\CallUser\isUaMobile
isUaMobile()
Определения
calluser.php:132
Bitrix\Im\Call\CallUser\$callId
$callId
Определения
calluser.php:20
Bitrix\Im\Call\CallUser\getLastSeen
getLastSeen()
Определения
calluser.php:76
Bitrix\Im\Call\CallUser\update
update(array $fields)
Определения
calluser.php:168
Bitrix\Im\Call\CallUser\setFields
setFields(array $fields)
Определения
calluser.php:137
Bitrix\Im\Call\CallUser\$state
$state
Определения
calluser.php:21
Bitrix\Im\Call\CallUser\LAST_SEEN_THRESHOLD
const LAST_SEEN_THRESHOLD
Определения
calluser.php:11
Bitrix\Im\Call\CallUser\isSeenRecently
isSeenRecently()
Определения
calluser.php:52
Bitrix\Im\Call\CallUser\getState
getState()
Определения
calluser.php:42
Bitrix\Im\Call\CallUser\save
save()
Определения
calluser.php:149
Bitrix\Main\ArgumentException
Определения
ArgumentException.php:9
Bitrix\Main\Type\DateTime
Определения
datetime.php:9
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$delta
$delta
Определения
prolog_main_admin.php:363
$instance
$instance
Определения
ps_b24_final.php:14
$fields
$fields
Определения
yandex_run.php:501
bitrix
modules
im
lib
call
calluser.php
Создано системой
1.14.0