Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Menu.php
1<?php
2
4
5use Bitrix\Im;
9
10class Menu extends Param
11{
13 protected bool $isValid = true;
14
19 public function setValue($value): self
20 {
21 if ($value === null || $value === $this->getDefaultValue())
22 {
23 return $this->unsetValue();
24 }
25 if ($value instanceof Im\Bot\ContextMenu)
26 {
27 $this->menu = $value;
28 }
29 elseif (!empty($value))
30 {
31 $this->menu = Im\Bot\ContextMenu::getByJson($value);
32 if ($this->menu === null)
33 {
34 $this->isValid = false;
35 }
36 }
37
38 if (isset($this->menu))
39 {
40 $this->value = $this->menu->getArray();
41 $this->jsonValue = $this->menu->getJson();
42 }
43
44 return $this;
45 }
46
50 public function getValue()
51 {
52 return $this->value ?? $this->getDefaultValue();
53 }
54
55 public function getDefaultValue()
56 {
57 return 'N';
58 }
59
64 public function saveValueFilter($value)
65 {
66 return '';
67 }
68
73 public function loadValueFilter($value)
74 {
75 if (!empty($value))
76 {
77 $value = Im\Text::decodeEmoji($value);
78 }
79 else
80 {
81 $value = null;
82 }
83
84 return $value;
85 }
86
91 public function saveJsonFilter($value)
92 {
93 return $this->jsonValue;
94 }
95
100 public function loadJsonFilter($value)
101 {
102 if (!empty($value))
103 {
104 try
105 {
106 $this->value = \Bitrix\Main\Web\Json::decode($value);
107 }
108 catch (ArgumentException $ext)
109 {}
110 }
111 else
112 {
113 $value = null;
114 }
115
116 return $value;
117 }
118
122 public function toRestFormat()
123 {
124 return $this->getValue();
125 }
126
130 public function toPullFormat()
131 {
132 return $this->getValue();
133 }
134
138 public function isValid(): Result
139 {
140 $result = new Result();
141
142 if ($this->isValid && (!isset($this->menu) || $this->menu->IsAllowSize()))
143 {
144 return $result;
145 }
146
147 return $result->addError(new ParamError(ParamError::MENU_ERROR));
148 }
149}
Im Bot ContextMenu $menu
Definition Menu.php:12