Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
Keyboard.php
1
<?php
2
3
namespace
Bitrix\Im\V2\Message\Param
;
4
5
use
Bitrix\Im
;
6
use
Bitrix\Im\V2\Message\Param
;
7
use
Bitrix\Im\V2\Result
;
8
use
Bitrix\Main\ArgumentException
;
9
10
class
Keyboard
extends
Param
11
{
12
protected
?
Im\Bot\Keyboard
$keyboard
;
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
26
if
(
$value
instanceof Im\
Bot
\
Keyboard
)
27
{
28
$this->keyboard =
$value
;
29
}
30
elseif (!empty(
$value
))
31
{
32
$this->keyboard = Im\Bot\Keyboard::getKeyboardByJson(
$value
);
33
$this->
isValid
= $this->keyboard !==
null
;
34
}
35
36
if
(isset($this->keyboard))
37
{
38
$this->value = $this->keyboard->getArray();
39
$this->jsonValue = $this->keyboard->getJson();
40
}
41
42
return
$this;
43
}
44
48
public
function
getValue
()
49
{
50
return
$this->value ?? $this->
getDefaultValue
();
51
}
52
53
public
function
getDefaultValue
()
54
{
55
return
'N'
;
56
}
57
62
public
function
saveValueFilter
(
$value
)
63
{
64
return
''
;
65
}
66
71
public
function
loadValueFilter
(
$value
)
72
{
73
if
(!empty(
$value
))
74
{
75
$value
= Im\Text::decodeEmoji(
$value
);
76
}
77
else
78
{
79
$value
=
null
;
80
}
81
82
return
$value
;
83
}
84
85
90
public
function
saveJsonFilter
(
$value
)
91
{
92
return
$this->jsonValue
;
93
}
94
99
public
function
loadJsonFilter
(
$value
)
100
{
101
if
(!empty(
$value
))
102
{
103
try
104
{
105
$this->value = \Bitrix\Main\Web\Json::decode(
$value
);
106
}
107
catch
(
ArgumentException
$ext)
108
{}
109
}
110
else
111
{
112
$value
=
null
;
113
}
114
115
return
$value
;
116
}
117
121
public
function
toRestFormat
()
122
{
123
return
$this->
getValue
();
124
}
125
129
public
function
toPullFormat
()
130
{
131
return
$this->
getValue
();
132
}
133
137
public
function
isValid
():
Result
138
{
139
$result =
new
Result
();
140
141
if
($this->
isValid
&& (!isset($this->keyboard) || $this->keyboard->IsAllowSize()))
142
{
143
return
$result;
144
}
145
146
return
$result->addError(
new
ParamError
(
ParamError::KEYBOARD_ERROR
));
147
}
148
}
Bitrix\Im\Bot\Keyboard
Definition
keyboard.php:12
Bitrix\Im\Bot
Definition
bot.php:11
Bitrix\Im\V2\Message\Param\Keyboard
Definition
Keyboard.php:11
Bitrix\Im\V2\Message\Param\Keyboard\$keyboard
Im Bot Keyboard $keyboard
Definition
Keyboard.php:12
Bitrix\Im\V2\Message\Param\Keyboard\$isValid
bool $isValid
Definition
Keyboard.php:13
Bitrix\Im\V2\Message\Param\Keyboard\toPullFormat
toPullFormat()
Definition
Keyboard.php:129
Bitrix\Im\V2\Message\Param\Keyboard\setValue
setValue($value)
Definition
Keyboard.php:19
Bitrix\Im\V2\Message\Param\Keyboard\isValid
isValid()
Definition
Keyboard.php:137
Bitrix\Im\V2\Message\Param\Keyboard\saveJsonFilter
saveJsonFilter($value)
Definition
Keyboard.php:90
Bitrix\Im\V2\Message\Param\Keyboard\loadJsonFilter
loadJsonFilter($value)
Definition
Keyboard.php:99
Bitrix\Im\V2\Message\Param\Keyboard\loadValueFilter
loadValueFilter($value)
Definition
Keyboard.php:71
Bitrix\Im\V2\Message\Param\Keyboard\getValue
getValue()
Definition
Keyboard.php:48
Bitrix\Im\V2\Message\Param\Keyboard\saveValueFilter
saveValueFilter($value)
Definition
Keyboard.php:62
Bitrix\Im\V2\Message\Param\Keyboard\toRestFormat
toRestFormat()
Definition
Keyboard.php:121
Bitrix\Im\V2\Message\Param\Keyboard\getDefaultValue
getDefaultValue()
Definition
Keyboard.php:53
Bitrix\Im\V2\Message\Param\ParamError
Definition
ParamError.php:9
Bitrix\Im\V2\Message\Param\ParamError\KEYBOARD_ERROR
const KEYBOARD_ERROR
Definition
ParamError.php:12
Bitrix\Im\V2\Message\Param
Definition
Param.php:19
Bitrix\Im\V2\Message\Param\$value
$value
Definition
Param.php:45
Bitrix\Im\V2\Message\Param\unsetValue
unsetValue()
Definition
Param.php:222
Bitrix\Im\V2\Message\Param\$jsonValue
string $jsonValue
Definition
Param.php:48
Bitrix\Im\V2\Result
Definition
Result.php:9
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Im\V2\Message\Param
Definition
Attach.php:3
Bitrix\Im
modules
im
lib
V2
Message
Param
Keyboard.php
Создано системой
1.10.0