1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
Background.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Im\V2\Chat\Fields\Field
;
4
5
use
Bitrix\Im\V2\Chat
;
6
use
Bitrix\Im\V2\Chat\Fields\BaseField
;
7
use
Bitrix\Im\V2\Chat\Param\Params
;
8
use
Bitrix\Im\V2\Pull\Event\ChatFieldsUpdate
;
9
10
class
Background
extends
BaseField
11
{
12
public
const
BACKGROUND_IDS
= [
13
'marta'
=>
'martaAI'
,
14
'copilot'
=>
'copilot'
,
15
'collab'
=>
'collab'
,
16
];
17
18
protected
Params
$params
;
19
20
public
function
__construct
(
int
$chatId)
21
{
22
parent::__construct($chatId);
23
$this->params = Params::getInstance($chatId);
24
}
25
29
public
function
get
(): ?string
30
{
31
return
$this->params->get(Params::BACKGROUND_ID)?->getValue();
32
}
33
38
public
function
set
(mixed $value): self
39
{
40
if
($value ===
null
|| $value ===
''
)
41
{
42
$this->params->deleteParam(Params::BACKGROUND_ID);
43
$this->
sendPush
();
44
}
45
46
if
(!in_array($value, self::BACKGROUND_IDS,
true
))
47
{
48
return
$this;
49
}
50
51
$this->params->addParamByName(Params::BACKGROUND_ID, $value);
52
$this->
sendPush
();
53
54
return
$this;
55
}
56
57
protected
function
sendPush
(): void
58
{
59
$chat =
Chat::getInstance
($this->chatId);
60
$updateField = [
'optionalParams'
=> [$this->
getFieldName
() => $this->
get
()]];
61
(
new
ChatFieldsUpdate
($chat, $updateField))->send();
62
}
63
64
protected
function
getFieldName
(): string
65
{
66
return
'backgroundId'
;
67
}
68
69
public
function
toRestFormat
(
array
$option
= []):
array
70
{
71
$backgroundId = $this->
get
();
72
73
if
(!isset($backgroundId))
74
{
75
return
[];
76
}
77
78
return
[$this->
getFieldName
() => $backgroundId];
79
}
80
81
public
static
function
validateBackgroundId
(mixed $backgroundId): ?string
82
{
83
if
(!isset($backgroundId) || $backgroundId ===
''
|| !is_string($backgroundId))
84
{
85
return
null
;
86
}
87
88
if
(!in_array($backgroundId, self::BACKGROUND_IDS,
true
))
89
{
90
return
null
;
91
}
92
93
return
$backgroundId;
94
}
95
}
Bitrix\Im\V2\Chat\Fields\BaseField
Определения
BaseField.php:9
Bitrix\Im\V2\Chat\Fields\Field\Background\toRestFormat
toRestFormat(array $option=[])
Определения
Background.php:69
Bitrix\Im\V2\Chat\Fields\Field\Background\getFieldName
getFieldName()
Определения
Background.php:64
Bitrix\Im\V2\Chat\Fields\Field\Background\sendPush
sendPush()
Определения
Background.php:57
Bitrix\Im\V2\Chat\Fields\Field\Background\BACKGROUND_IDS
const BACKGROUND_IDS
Определения
Background.php:12
Bitrix\Im\V2\Chat\Fields\Field\Background\$params
Params $params
Определения
Background.php:18
Bitrix\Im\V2\Chat\Fields\Field\Background\validateBackgroundId
static validateBackgroundId(mixed $backgroundId)
Определения
Background.php:81
Bitrix\Im\V2\Chat\Fields\Field\Background\__construct
__construct(int $chatId)
Определения
Background.php:20
Bitrix\Im\V2\Chat\Param\Params
Определения
Params.php:21
Bitrix\Im\V2\Pull\Event\ChatFieldsUpdate
Определения
ChatFieldsUpdate.php:10
Bitrix\Main\Application\getInstance
static getInstance()
Определения
application.php:98
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
Bitrix\Im\V2\Chat\Background
Определения
Background.php:3
Bitrix\Im\V2\Chat\Fields\Field
Определения
Background.php:3
Bitrix\Im\V2\Chat
$option
$option
Определения
options.php:1711
bitrix
modules
im
lib
V2
Chat
Fields
Field
Background.php
Создано системой
1.14.0