1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
Param.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Im\V2\Message;
4
5
use Bitrix\Im\Text;
6
use Bitrix\Main\ORM\Data\DataManager;
7
use Bitrix\Main\ORM\Objectify\EntityObject;
8
use Bitrix\Im\Model\EO_MessageParam;
9
use Bitrix\Im\Model\MessageParamTable;
10
use Bitrix\Im\V2\Result;
11
use Bitrix\Im\V2\ActiveRecord;
12
use Bitrix\Im\V2\RegistryEntry;
13
use Bitrix\Im\V2\Common\ActiveRecordImplementation;
14
use Bitrix\Im\V2\Common\RegistryEntryImplementation;
15
19
class
Param
implements
MessageParameter
,
RegistryEntry
,
ActiveRecord
20
{
21
use ActiveRecordImplementation
22
{
23
load
as defaultLoad;
24
}
25
use RegistryEntryImplementation;
26
27
public
const
28
TYPE_STRING
=
'String'
,
29
TYPE_INT
=
'Integer'
,
30
TYPE_BOOL
=
'Boolean'
,
31
TYPE_STRING_ARRAY
=
'ArrayString'
,
32
TYPE_INT_ARRAY
=
'ArrayInteger'
,
33
TYPE_DATE_TIME
=
'DateTime'
,
34
TYPE_JSON
=
'Json'
35
;
36
37
protected
?
string
$type
=
null
;
38
39
protected
?
int
$paramId
=
null
;
40
41
protected
?
int
$messageId
=
null
;
42
43
protected
?
string
$name
=
null
;
44
46
protected
$value
=
null
;
47
49
protected
?
string
$jsonValue
=
null
;
50
52
protected
$defaultValue
=
null
;
53
57
public
function
__construct
($source =
null
)
58
{
59
if
(!empty($source))
60
{
61
$this->
load
($source);
62
}
63
}
64
68
public
function
load
($source):
Result
69
{
70
$result
= $this->defaultLoad($source);
71
if
(
$result
->isSuccess())
72
{
73
$checkType = $this->
getType
();
74
$this->
detectType
();
75
if
($this->type !== $checkType)
76
{
77
$this->
setValue
($this->value);
78
}
79
80
$type
=
Params::getType
($this->name);
81
if
(isset(
$type
[
'loadValueFilter'
]) && is_callable(
$type
[
'loadValueFilter'
]))
82
{
83
$this->value = \call_user_func(
$type
[
'loadValueFilter'
], $this->value);
84
}
85
}
86
87
return
$result
;
88
}
89
90
//region Param value
91
96
public
function
setValue
(
$value
): self
97
{
98
if
(
$value
===
null
)
99
{
100
return
$this->
unsetValue
();
101
}
102
103
switch
($this->type)
104
{
105
case
self::TYPE_INT:
106
$this->value = (int)
$value
;
107
break
;
108
109
case
self::TYPE_BOOL:
110
if
(is_string(
$value
))
111
{
112
$this->value =
$value
===
'Y'
;
113
}
114
else
115
{
116
$this->value = (bool)
$value
;
117
}
118
break
;
119
120
case
self::TYPE_STRING:
121
$this->value = (string)
$value
;
122
break
;
123
124
default
:
125
$this->value =
$value
;
126
}
127
128
$defaultValue
= $this->
getDefaultValue
();
129
if
($this->value ===
$defaultValue
)
130
{
131
return
$this->
unsetValue
();
132
}
133
134
$this->
markChanged
();
135
136
return
$this;
137
}
138
142
public
function
getDefaultValue
()
143
{
144
if
($this->defaultValue ===
null
)
145
{
146
$type
=
Params::getType
($this->name);
147
if
(isset(
$type
[
'default'
]))
148
{
149
$value
=
$type
[
'default'
];
150
151
switch
($this->type)
152
{
153
case
self::TYPE_INT:
154
$this->defaultValue = (int)
$value
;
155
break
;
156
157
case
self::TYPE_BOOL:
158
$this->defaultValue = (bool)
$value
;
159
break
;
160
161
case
self::TYPE_STRING:
162
$this->defaultValue = (string)
$value
;
163
break
;
164
165
default
:
166
$this->defaultValue =
$value
;
167
}
168
}
169
}
170
171
return
$this->defaultValue
;
172
}
173
177
public
function
hasValue
(): bool
178
{
179
return
$this->value !==
null
;
180
}
181
185
public
function
getValue
()
186
{
187
if
($this->value ===
null
)
188
{
189
return
$this->
getDefaultValue
();
190
}
191
switch
($this->type)
192
{
193
case
self::TYPE_INT:
194
return
(
int
)
$this->value
;
195
196
case
self::TYPE_BOOL:
197
if
(is_string($this->value))
198
{
199
$this->value = $this->value ===
'Y'
;
200
}
201
return
(
bool
)
$this->value
;
202
203
case
self::TYPE_STRING:
204
return
(
string
)
$this->value
;
205
206
default
:
207
return
$this->value
;
208
}
209
}
210
215
public
function
addValue
(
$value
): self
216
{
217
return
$this->
setValue
(
$value
);
218
}
219
223
public
function
unsetValue
(): self
224
{
225
$this->value =
null
;
226
$this->
markDrop
();
227
228
if
($this->
getRegistry
())
229
{
230
unset($this->
getRegistry
()[$this->
getName
()]);
231
}
232
233
return
$this;
234
}
235
236
public
function
isHidden
(): bool
237
{
238
return
Params::getType
($this->name)[
'isHidden'
] ??
false
;
239
}
240
244
public
function
toRestFormat
()
245
{
246
switch
($this->type)
247
{
248
case
self::TYPE_BOOL:
249
return
$this->
getValue
() ?
'Y'
:
'N'
;
250
251
case
self::TYPE_INT:
252
return
(
string
)$this->
getValue
();
253
254
case
self::TYPE_STRING:
255
default
:
256
return
$this->
getValue
();
257
258
}
259
}
260
264
public
function
toPullFormat
()
265
{
266
return
$this->
toRestFormat
();
267
}
268
269
//endregion
270
271
//region Setters & Getters
272
273
public
function
setParamId
(
int
$paramId): self
274
{
275
if
(!$this->paramId)
276
{
277
$this->paramId =
$paramId
;
278
}
279
return
$this;
280
}
281
282
public
function
getParamId
(): ?int
283
{
284
return
$this->paramId
;
285
}
286
287
public
function
setMessageId
(
int
$messageId
): self
288
{
289
if
($this->messageId !=
$messageId
)
290
{
291
$this->
markChanged
();
292
}
293
$this->messageId =
$messageId
;
294
return
$this;
295
}
296
297
public
function
getMessageId
(): ?int
298
{
299
return
$this->messageId
;
300
}
301
302
public
function
setName
(
string
$name
): self
303
{
304
$name
= mb_substr(trim(
$name
), 0, 100);
305
if
($this->name !=
$name
)
306
{
307
$this->
markChanged
();
308
}
309
$this->name =
$name
;
310
$this->
detectType
();
311
312
return
$this;
313
}
314
315
public
function
getName
(): ?string
316
{
317
return
$this->name
;
318
}
319
320
public
function
saveNameFilter
(
$name
): string
321
{
322
$name
=
$name
??
''
;
323
if
(is_string(
$name
) && mb_strlen(
$name
) > 100)
324
{
325
$name
= mb_substr(
$name
, 0, 100);
326
}
327
328
return
$name
;
329
}
330
331
public
function
setType
(
string
$type
): self
332
{
333
switch
(
$type
)
334
{
335
case
Param::TYPE_INT_ARRAY
:
336
$type
=
Param::TYPE_INT
;
337
break
;
338
339
case
Param::TYPE_STRING_ARRAY
:
340
$type
=
Param::TYPE_STRING
;
341
}
342
if
($this->type !=
$type
)
343
{
344
$this->
markChanged
();
345
}
346
$this->type =
$type
;
347
348
return
$this;
349
}
350
351
public
function
getType
(): string
352
{
353
return
$this->type ??
Param::TYPE_STRING
;
354
}
355
356
public
function
detectType
(): self
357
{
358
if
(empty($this->type) && !empty($this->name))
359
{
360
$type
=
Params::getType
($this->name);
361
$this->
setType
($type[
'type'
] ??
Param::TYPE_STRING
);
362
}
363
364
return
$this;
365
}
366
367
public
function
setJsonValue
(
$value
): self
368
{
369
$this->jsonValue =
$value
;
370
$this->
markChanged
();
371
372
return
$this;
373
}
374
375
public
function
getJsonValue
()
376
{
377
return
$this->jsonValue
;
378
}
379
380
//endregion
381
382
//region Data storage
383
387
protected
static
function
mirrorDataEntityFields
():
array
388
{
389
return
[
390
'ID'
=> [
391
'primary'
=>
true
,
392
'field'
=>
'paramId'
,
393
'get'
=>
'getParamId'
,
394
'set'
=>
'setParamId'
,
395
],
396
'MESSAGE_ID'
=> [
397
'field'
=>
'messageId'
,
398
'set'
=>
'setMessageId'
,
399
'get'
=>
'getMessageId'
,
400
],
401
'TYPE'
=> [
402
'set'
=>
'setType'
,
403
'get'
=>
'getType'
,
404
],
405
'PARAM_NAME'
=> [
406
'field'
=>
'name'
,
407
'set'
=>
'setName'
,
408
'get'
=>
'getName'
,
409
'saveFilter'
=>
'saveNameFilter'
,
410
],
411
'PARAM_VALUE'
=> [
412
'field'
=>
'value'
,
413
'set'
=>
'setValue'
,
414
'get'
=>
'getValue'
,
415
'saveFilter'
=>
'saveValueFilter'
,
416
'loadFilter'
=>
'loadValueFilter'
,
417
],
418
'PARAM_JSON'
=> [
419
'field'
=>
'jsonValue'
,
420
'set'
=>
'setJsonValue'
,
421
'get'
=>
'getJsonValue'
,
422
'saveFilter'
=>
'saveJsonFilter'
,
423
'loadFilter'
=>
'loadJsonFilter'
,
424
],
425
];
426
}
427
431
public
static
function
getDataClass
(): string
432
{
433
return
MessageParamTable::class;
434
}
435
439
public
function
getPrimaryId
(): ?int
440
{
441
return
$this->
getParamId
();
442
}
443
448
public
function
setPrimaryId
(
int
$primaryId): self
449
{
450
return
$this->
setParamId
($primaryId);
451
}
452
453
public
function
isValid
():
Result
454
{
455
return
new
Result
();
456
}
457
462
public
function
saveValueFilter
(
$value
)
463
{
464
$type
=
Params::getType
($this->name);
465
466
if
(
467
isset(
$type
[
'saveValueFilter'
])
468
&& ($saveFilter =
$type
[
'saveValueFilter'
])
469
)
470
{
471
if
(is_string($saveFilter) && is_callable([$this, $saveFilter]))
472
{
473
$value
= $this->$saveFilter(
$value
);
474
}
475
elseif
(is_callable($saveFilter))
476
{
477
$value
= call_user_func($saveFilter,
$value
);
478
}
479
}
480
elseif
(
$type
[
'type'
] ==
Param::TYPE_BOOL
)
481
{
482
$value
=
$value
?
'Y'
:
'N'
;
483
}
484
485
if
(is_string(
$value
) && $this->
shouldProcessEmoji
())
486
{
487
$value
=
Text::encodeEmoji
(
$value
);
488
}
489
490
if
(is_string(
$value
) && mb_strlen(
$value
) > 100)
491
{
492
$value
= mb_substr(
$value
, 0, 97) .
'...'
;
493
}
494
495
return
$value
;
496
}
497
502
public
function
loadValueFilter
(
$value
)
503
{
504
$type
=
Params::getType
($this->name);
505
506
if
(
507
isset(
$type
[
'loadValueFilter'
])
508
&& ($loadFilter =
$type
[
'loadValueFilter'
])
509
)
510
{
511
if
(is_string($loadFilter) && is_callable([$this, $loadFilter]))
512
{
513
$value
= $this->$loadFilter(
$value
);
514
}
515
elseif
(is_callable($loadFilter))
516
{
517
$value
= call_user_func($loadFilter,
$value
);
518
}
519
}
520
elseif
((
$type
[
'type'
] ??
null
) ==
Param::TYPE_BOOL
)
//TODO replace to normal variant
521
{
522
$value
=
$value
==
'Y'
;
523
}
524
525
if
(is_string(
$value
) && $this->
shouldProcessEmoji
())
526
{
527
$value
=
Text::decodeEmoji
(
$value
);
528
}
529
530
return
$value
;
531
}
532
537
public
function
saveJsonFilter
(
$value
)
538
{
539
return
$value
;
540
}
541
546
public
function
loadJsonFilter
(
$value
)
547
{
548
return
$value
;
549
}
550
551
protected
function
shouldProcessEmoji
(): bool
552
{
553
return
in_array($this->
getType
(), [self::TYPE_STRING, self::TYPE_STRING_ARRAY, self::TYPE_JSON]);
554
}
555
556
//endregion
557
}
$defaultValue
if($_SERVER $defaultValue['REQUEST_METHOD']==="GET" &&!empty($RestoreDefaults) && $bizprocPerms==="W" &&check_bitrix_sessid())
Определения
options.php:32
$messageId
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
Определения
callback_ismscenter.php:26
Bitrix\Im\Text\encodeEmoji
static encodeEmoji($text)
Определения
text.php:373
Bitrix\Im\Text\decodeEmoji
static decodeEmoji($text)
Определения
text.php:378
Bitrix\Im\V2\Message\Param\setPrimaryId
setPrimaryId(int $primaryId)
Определения
Param.php:448
Bitrix\Im\V2\Message\Param\$value
$value
Определения
Param.php:46
Bitrix\Im\V2\Message\Param\TYPE_BOOL
const TYPE_BOOL
Определения
Param.php:30
Bitrix\Im\V2\Message\Param\unsetValue
unsetValue()
Определения
Param.php:223
Bitrix\Im\V2\Message\Param\setParamId
setParamId(int $paramId)
Определения
Param.php:273
Bitrix\Im\V2\Message\Param\TYPE_DATE_TIME
const TYPE_DATE_TIME
Определения
Param.php:33
Bitrix\Im\V2\Message\Param\setName
setName(string $name)
Определения
Param.php:302
Bitrix\Im\V2\Message\Param\getName
getName()
Определения
Param.php:315
Bitrix\Im\V2\Message\Param\setJsonValue
setJsonValue($value)
Определения
Param.php:367
Bitrix\Im\V2\Message\Param\toPullFormat
toPullFormat()
Определения
Param.php:264
Bitrix\Im\V2\Message\Param\__construct
__construct($source=null)
Определения
Param.php:57
Bitrix\Im\V2\Message\Param\getPrimaryId
getPrimaryId()
Определения
Param.php:439
Bitrix\Im\V2\Message\Param\detectType
detectType()
Определения
Param.php:356
Bitrix\Im\V2\Message\Param\TYPE_INT_ARRAY
const TYPE_INT_ARRAY
Определения
Param.php:32
Bitrix\Im\V2\Message\Param\getMessageId
getMessageId()
Определения
Param.php:297
Bitrix\Im\V2\Message\Param\$name
string $name
Определения
Param.php:43
Bitrix\Im\V2\Message\Param\addValue
addValue($value)
Определения
Param.php:215
Bitrix\Im\V2\Message\Param\setValue
setValue($value)
Определения
Param.php:96
Bitrix\Im\V2\Message\Param\$jsonValue
string $jsonValue
Определения
Param.php:49
Bitrix\Im\V2\Message\Param\TYPE_STRING
const TYPE_STRING
Определения
Param.php:28
Bitrix\Im\V2\Message\Param\isValid
isValid()
Определения
Param.php:453
Bitrix\Im\V2\Message\Param\getType
getType()
Определения
Param.php:351
Bitrix\Im\V2\Message\Param\saveNameFilter
saveNameFilter($name)
Определения
Param.php:320
Bitrix\Im\V2\Message\Param\load
load($source)
Определения
Param.php:68
Bitrix\Im\V2\Message\Param\saveJsonFilter
saveJsonFilter($value)
Определения
Param.php:537
Bitrix\Im\V2\Message\Param\$paramId
int $paramId
Определения
Param.php:39
Bitrix\Im\V2\Message\Param\getParamId
getParamId()
Определения
Param.php:282
Bitrix\Im\V2\Message\Param\TYPE_INT
const TYPE_INT
Определения
Param.php:29
Bitrix\Im\V2\Message\Param\loadJsonFilter
loadJsonFilter($value)
Определения
Param.php:546
Bitrix\Im\V2\Message\Param\loadValueFilter
loadValueFilter($value)
Определения
Param.php:502
Bitrix\Im\V2\Message\Param\$defaultValue
$defaultValue
Определения
Param.php:52
Bitrix\Im\V2\Message\Param\TYPE_JSON
const TYPE_JSON
Определения
Param.php:34
Bitrix\Im\V2\Message\Param\$type
string $type
Определения
Param.php:37
Bitrix\Im\V2\Message\Param\setMessageId
setMessageId(int $messageId)
Определения
Param.php:287
Bitrix\Im\V2\Message\Param\getValue
getValue()
Определения
Param.php:185
Bitrix\Im\V2\Message\Param\TYPE_STRING_ARRAY
const TYPE_STRING_ARRAY
Определения
Param.php:31
Bitrix\Im\V2\Message\Param\getDataClass
static getDataClass()
Определения
Param.php:431
Bitrix\Im\V2\Message\Param\saveValueFilter
saveValueFilter($value)
Определения
Param.php:462
Bitrix\Im\V2\Message\Param\toRestFormat
toRestFormat()
Определения
Param.php:244
Bitrix\Im\V2\Message\Param\isHidden
isHidden()
Определения
Param.php:236
Bitrix\Im\V2\Message\Param\hasValue
hasValue()
Определения
Param.php:177
Bitrix\Im\V2\Message\Param\$messageId
int $messageId
Определения
Param.php:41
Bitrix\Im\V2\Message\Param\getJsonValue
getJsonValue()
Определения
Param.php:375
Bitrix\Im\V2\Message\Param\mirrorDataEntityFields
static mirrorDataEntityFields()
Определения
Param.php:387
Bitrix\Im\V2\Message\Param\getDefaultValue
getDefaultValue()
Определения
Param.php:142
Bitrix\Im\V2\Message\Param\setType
setType(string $type)
Определения
Param.php:331
Bitrix\Im\V2\Message\Param\shouldProcessEmoji
shouldProcessEmoji()
Определения
Param.php:551
Bitrix\Im\V2\Message\Params\getType
static getType(string $paramName)
Определения
Params.php:288
Bitrix\Im\V2\Message\Send\SendingConfig\TYPE_BOOL
const TYPE_BOOL
Определения
SendingConfig.php:69
Bitrix\Im\V2\Message\Send\SendingConfig\TYPE_INT
const TYPE_INT
Определения
SendingConfig.php:70
Bitrix\Main\DB\Result
Определения
result.php:20
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
Bitrix\Im\V2\ActiveRecord
Определения
ActiveRecord.php:8
Bitrix\Im\V2\ActiveRecord\markChanged
markChanged()
Bitrix\Im\V2\ActiveRecord\markDrop
markDrop()
Bitrix\Im\V2\Message\MessageParameter
Определения
MessageParameter.php:8
Bitrix\Im\V2\RegistryEntry
Определения
RegistryEntry.php:6
Bitrix\Im\V2\RegistryEntry\getRegistry
getRegistry()
Bitrix\Im\V2\Chat\Param
Bitrix\Im\V2\Chat\Param\$value
$value
Определения
Param.php:39
Bitrix\Im\V2\Chat\Param\unsetValue
unsetValue()
Определения
Param.php:47
Bitrix\Im\V2\Chat\Param\setParamId
setParamId(int $paramId)
Определения
Param.php:75
Bitrix\Im\V2\Chat\Param\getName
getName()
Определения
Param.php:99
Bitrix\Im\V2\Chat\Param\TYPE_INT_ARRAY
const TYPE_INT_ARRAY
Определения
Param.php:22
Bitrix\Im\V2\Chat\Param\$name
string $name
Определения
Param.php:37
Bitrix\Im\V2\Chat\Param\setValue
setValue($value)
Определения
Param.php:163
Bitrix\Im\V2\Chat\Param\$jsonValue
string $jsonValue
Определения
Param.php:38
Bitrix\Im\V2\Chat\Param\TYPE_STRING
const TYPE_STRING
Определения
Param.php:17
Bitrix\Im\V2\Chat\Param\getType
getType()
Определения
Param.php:116
Bitrix\Im\V2\Chat\Param\$paramId
int $paramId
Определения
Param.php:35
Bitrix\Im\V2\Chat\Param\getParamId
getParamId()
Определения
Param.php:70
Bitrix\Im\V2\Chat\Param\getValue
getValue()
Определения
Param.php:141
Bitrix\Im\V2\Chat\Param\TYPE_STRING_ARRAY
const TYPE_STRING_ARRAY
Определения
Param.php:21
Bitrix\Im\V2\Chat\Param\toRestFormat
toRestFormat()
Определения
Param.php:305
Bitrix\Im\V2\Chat\Param\setType
setType(string $type)
Определения
Param.php:121
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
bitrix
modules
im
lib
V2
Message
Param.php
Создано системой
1.14.0