1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Param.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Chat\Param;
4
5use Bitrix\Im\Model\ChatParamTable;
6use Bitrix\Im\V2\ActiveRecord;
7use Bitrix\Im\V2\Common\ActiveRecordImplementation;
8use Bitrix\Im\V2\Common\RegistryEntryImplementation;
9use Bitrix\Im\V2\RegistryEntry;
10
12{
13 use ActiveRecordImplementation;
14 use RegistryEntryImplementation;
15
16 public const
17 TYPE_STRING = 'string',
18 TYPE_INT = 'integer',
19 TYPE_BOOL = 'boolean',
20 TYPE_JSON = 'json',
21 TYPE_STRING_ARRAY = 'arrayString',
22 TYPE_INT_ARRAY = 'arrayInteger'
23 ;
24
25 public const PARAM_TYPES = [
26 self::TYPE_STRING,
27 self::TYPE_INT,
28 self::TYPE_BOOL,
29 self::TYPE_JSON,
30 self::TYPE_STRING_ARRAY,
31 self::TYPE_INT_ARRAY,
32 ];
33
34 protected ?string $type = null;
35 protected ?int $paramId = null;
36 protected ?int $chatId = null;
37 protected ?string $name = null;
38 protected ?string $jsonValue = null;
39 protected $value = null;
40 protected bool $isHidden = false;
41
42 public static function getDataClass(): string
43 {
44 return ChatParamTable::class;
45 }
46
47 public function unsetValue(): self
48 {
49 $this->value = null;
50 $this->markDrop();
51
52 if ($this->getRegistry())
53 {
54 unset($this->getRegistry()[$this->getName()]);
55 }
56
57 return $this;
58 }
59
60 public function getPrimaryId(): ?int
61 {
62 return $this->getParamId();
63 }
64
65 public function setPrimaryId(int $primaryId): self
66 {
67 return $this->setParamId($primaryId);
68 }
69
70 public function getParamId(): ?int
71 {
72 return $this->paramId;
73 }
74
75 public function setParamId(int $paramId): self
76 {
77 if (!$this->paramId)
78 {
79 $this->paramId = $paramId;
80 }
81 return $this;
82 }
83
84 public function getChatId(): ?int
85 {
86 return $this->chatId;
87 }
88
89 public function setChatId(int $chatId): self
90 {
91 if ($this->chatId != $chatId)
92 {
93 $this->markChanged();
94 }
95 $this->chatId = $chatId;
96 return $this;
97 }
98
99 public function getName(): ?string
100 {
101 return $this->name;
102 }
103
104 public function setName(string $name): self
105 {
106 $name = mb_substr(trim($name), 0, 100);
107 if ($this->name != $name)
108 {
109 $this->markChanged();
110 }
111 $this->name = $name;
112
113 return $this;
114 }
115
116 public function getType(): string
117 {
118 return $this->type ?? self::TYPE_STRING;
119 }
120
121 public function setType(string $type): self
122 {
123 switch ($type)
124 {
125 case self::TYPE_INT_ARRAY:
126 $type = self::TYPE_INT;
127 break;
128
129 case self::TYPE_STRING_ARRAY:
130 $type = self::TYPE_STRING;
131 }
132 if ($this->type !== $type)
133 {
134 $this->markChanged();
135 }
136 $this->type = $type;
137
138 return $this;
139 }
140
141 public function getValue()
142 {
143 switch ($this->type)
144 {
145 case self::TYPE_INT:
146 return (int)$this->value;
147
148 case self::TYPE_BOOL:
149 if (is_string($this->value))
150 {
151 $this->value = $this->value === 'Y';
152 }
153 return (bool)$this->value;
154
155 case self::TYPE_STRING:
156 return (string)$this->value;
157
158 default:
159 return $this->value;
160 }
161 }
162
163 public function setValue($value): self
164 {
165 if ($value === null)
166 {
167 return $this->unsetValue();
168 }
169
170 $prevValue = $this->value;
171
172 switch ($this->type)
173 {
174 case self::TYPE_INT:
175 $this->value = (int)$value;
176 break;
177
178 case self::TYPE_BOOL:
179 if (is_string($value))
180 {
181 $this->value = $value === 'Y';
182 }
183 else
184 {
185 $this->value = (bool)$value;
186 }
187 break;
188
189 case self::TYPE_STRING:
190 $this->value = (string)$value;
191 break;
192
193 default:
194 $this->value = $value;
195 }
196
197 if ($prevValue !== $this->value)
198 {
199 $this->markChanged();
200 }
201
202 return $this;
203 }
204
205 public function hasValue(): bool
206 {
207 return $this->value !== null;
208 }
209
210 public function getJsonValue()
211 {
212 return $this->jsonValue;
213 }
214
215 public function setJsonValue($value): self
216 {
217 $this->jsonValue = $value;
218 $this->markChanged();
219
220 return $this;
221 }
222
223 public function isHidden(): bool
224 {
225 return $this->isHidden;
226 }
227
228 public function setHidden(bool $isHidden): self
229 {
230 $this->isHidden = $isHidden;
231
232 return $this;
233 }
234
235 protected static function mirrorDataEntityFields(): array
236 {
237 return [
238 'ID' => [
239 'primary' => true,
240 'field' => 'paramId',
241 'get' => 'getParamId',
242 'set' => 'setParamId',
243 ],
244 'CHAT_ID' => [
245 'field' => 'chatId',
246 'set' => 'setChatId',
247 'get' => 'getChatId',
248 ],
249 'TYPE' => [
250 'set' => 'setType',
251 'get' => 'getType',
252 ],
253 'PARAM_NAME' => [
254 'field' => 'name',
255 'set' => 'setName',
256 'get' => 'getName',
257 ],
258 'PARAM_VALUE' => [
259 'field' => 'value',
260 'set' => 'setValue',
261 'get' => 'getValue',
262 'saveFilter' => 'saveValueFilter',
263 'loadFilter' => 'loadValueFilter',
264 ],
265 'PARAM_JSON' => [
266 'field' => 'jsonValue',
267 'set' => 'setJsonValue',
268 'get' => 'getJsonValue',
269 'saveFilter' => 'saveJsonFilter',
270 'loadFilter' => 'loadJsonFilter',
271 ],
272 ];
273 }
274
275 public function saveValueFilter($value)
276 {
277 if ($this->type === self::TYPE_BOOL)
278 {
279 $value = $value ? 'Y' : 'N';
280 }
281
282 return $value;
283 }
284
285 public function loadValueFilter($value)
286 {
287 if ($this->type === self::TYPE_BOOL)
288 {
289 $value = $value === 'Y';
290 }
291
292 return $value;
293 }
294
295 public function saveJsonFilter($value)
296 {
297 return $value;
298 }
299
300 public function loadJsonFilter($value)
301 {
302 return $value;
303 }
304
305 public function toRestFormat()
306 {
307 switch ($this->type)
308 {
309 case self::TYPE_BOOL:
310 return $this->getValue() ? 'Y' : 'N';
311
312 case self::TYPE_INT:
313 return (string)$this->getValue();
314
315 case self::TYPE_STRING:
316
317 default:
318 return $this->getValue();
319 }
320 }
321}
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
Определения RegistryEntry.php:6
getChatId()
Определения Param.php:84
setPrimaryId(int $primaryId)
Определения Param.php:65
setHidden(bool $isHidden)
Определения Param.php:228
$value
Определения Param.php:39
const PARAM_TYPES
Определения Param.php:25
const TYPE_BOOL
Определения Param.php:19
bool $isHidden
Определения Param.php:40
unsetValue()
Определения Param.php:47
setParamId(int $paramId)
Определения Param.php:75
setName(string $name)
Определения Param.php:104
getName()
Определения Param.php:99
setJsonValue($value)
Определения Param.php:215
getPrimaryId()
Определения Param.php:60
const TYPE_INT_ARRAY
Определения Param.php:22
string $name
Определения Param.php:37
setValue($value)
Определения Param.php:163
string $jsonValue
Определения Param.php:38
const TYPE_STRING
Определения Param.php:17
int $chatId
Определения Param.php:36
getType()
Определения Param.php:116
saveJsonFilter($value)
Определения Param.php:295
int $paramId
Определения Param.php:35
getParamId()
Определения Param.php:70
const TYPE_INT
Определения Param.php:18
loadJsonFilter($value)
Определения Param.php:300
loadValueFilter($value)
Определения Param.php:285
const TYPE_JSON
Определения Param.php:20
string $type
Определения Param.php:34
setChatId(int $chatId)
Определения Param.php:89
getValue()
Определения Param.php:141
const TYPE_STRING_ARRAY
Определения Param.php:21
saveValueFilter($value)
Определения Param.php:275
toRestFormat()
Определения Param.php:305
isHidden()
Определения Param.php:223
hasValue()
Определения Param.php:205
getJsonValue()
Определения Param.php:210
setType(string $type)
Определения Param.php:121