1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Background.php
См. документацию.
1<?php
2
4
9
10class 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}
toRestFormat(array $option=[])
Определения Background.php:69
static validateBackgroundId(mixed $backgroundId)
Определения Background.php:81
__construct(int $chatId)
Определения Background.php:20
static getInstance()
Определения application.php:98
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$option
Определения options.php:1711