1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Background.php
См. документацию.
1<?php
2
4
8
10{
11 protected int $chatId;
12 protected Params $params;
13
14 public function __construct(int $chatId)
15 {
16 $this->chatId = $chatId;
17 $this->params = Params::getInstance($chatId);
18 }
19
20 public function get(): ?string
21 {
22 $background = $this->params->get(Params::BACKGROUND_ID)?->getValue();
23
24 return $background ? (string)$background : null;
25 }
26
27 public function set(?string $value): self
28 {
29 if (
30 !$this->chatId
31 || $this->params->get(Params::BACKGROUND_ID)?->getValue() === $value
32 )
33 {
34 return $this;
35 }
36
37 if (!$value)
38 {
39 $this->params->deleteParam(Params::BACKGROUND_ID);
40 $this->sendPush();
41
42 return $this;
43 }
44
45 if (BackgroundId::tryFrom($value) === null)
46 {
47 return $this;
48 }
49
50 $this->params->addParamByName(Params::BACKGROUND_ID, $value);
51 $this->sendPush();
52
53 return $this;
54 }
55
56 protected function sendPush(): void
57 {
58 $chat = Chat::getInstance($this->chatId);
59 $updateField = ['backgroundId' => $this->get()];
60 (new ChatFieldsUpdate($chat, $updateField))->send();
61 }
62
63 public static function validateBackgroundId(mixed $value): ?string
64 {
65 if (!isset($value) || $value === '' || !is_string($value))
66 {
67 return null;
68 }
69
70 if (BackgroundId::tryFrom($value) === null)
71 {
72 return null;
73 }
74
75 return $value;
76 }
77}
static validateBackgroundId(mixed $value)
Определения Background.php:63
__construct(int $chatId)
Определения Background.php:14
static getInstance()
Определения application.php:98
$background
Определения html.php:27