1
|
|
|
<?php |
2
|
|
|
namespace Maknz\Slack\Object; |
3
|
|
|
|
4
|
|
|
use Maknz\Slack\BlockElement\Text; |
5
|
|
|
|
6
|
|
|
class Option extends CompositionObject |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Option text. |
10
|
|
|
* |
11
|
|
|
* @var \Maknz\Slack\BlockElement\Text |
12
|
|
|
*/ |
13
|
|
|
protected $text; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Option value. |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $value; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Option group description. |
24
|
|
|
* |
25
|
|
|
* @var \Maknz\Slack\BlockElement\Text |
26
|
|
|
*/ |
27
|
|
|
protected $description; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* URL to be loaded when the option is clicked. |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $url; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Whether this option is initially selected. |
38
|
|
|
* |
39
|
|
|
* @var bool |
40
|
|
|
*/ |
41
|
|
|
protected $initially_selected = false; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Internal attribute to property map. |
45
|
|
|
* |
46
|
|
|
* @var array |
47
|
|
|
*/ |
48
|
|
|
protected static $availableAttributes = [ |
49
|
|
|
'text' => 'text', |
50
|
|
|
'value' => 'value', |
51
|
|
|
'description' => 'description', |
52
|
|
|
'url' => 'url', |
53
|
|
|
'selected' => 'initially_selected', |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get the option text. |
58
|
|
|
* |
59
|
|
|
* @return \Maknz\Slack\BlockElement\Text |
60
|
|
|
*/ |
61
|
24 |
|
public function getText() |
62
|
|
|
{ |
63
|
24 |
|
return $this->text; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Set the option text. |
68
|
|
|
* |
69
|
|
|
* @param mixed $text |
70
|
|
|
* |
71
|
|
|
* @return $this |
72
|
|
|
* |
73
|
|
|
* @throws \InvalidArgumentException |
74
|
|
|
*/ |
75
|
37 |
|
public function setText($text) |
76
|
|
|
{ |
77
|
37 |
|
$this->text = Text::create($text, Text::TYPE_PLAIN); |
78
|
|
|
|
79
|
37 |
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Get the option value. |
84
|
|
|
* |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
21 |
|
public function getValue() |
88
|
|
|
{ |
89
|
21 |
|
return $this->value; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Set the option value. |
94
|
|
|
* |
95
|
|
|
* @param string $value |
96
|
|
|
* |
97
|
|
|
* @return $this |
98
|
|
|
*/ |
99
|
37 |
|
public function setValue($value) |
100
|
|
|
{ |
101
|
37 |
|
$this->value = $value; |
102
|
|
|
|
103
|
37 |
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Get the option description. |
108
|
|
|
* |
109
|
|
|
* @return \Maknz\Slack\BlockElement\Text |
110
|
|
|
*/ |
111
|
14 |
|
public function getDescription() |
112
|
|
|
{ |
113
|
14 |
|
return $this->description; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Set the option description. |
118
|
|
|
* |
119
|
|
|
* @param mixed $description |
120
|
|
|
* |
121
|
|
|
* @return $this |
122
|
|
|
* |
123
|
|
|
* @throws \InvalidArgumentException |
124
|
|
|
*/ |
125
|
1 |
|
public function setDescription($description) |
126
|
|
|
{ |
127
|
1 |
|
$this->description = Text::create($description, Text::TYPE_PLAIN); |
128
|
|
|
|
129
|
1 |
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Get the option URL. |
134
|
|
|
* |
135
|
|
|
* @return string |
136
|
|
|
*/ |
137
|
14 |
|
public function getUrl() |
138
|
|
|
{ |
139
|
14 |
|
return $this->url; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Set the option URL. |
144
|
|
|
* |
145
|
|
|
* @param string $url |
146
|
|
|
* |
147
|
|
|
* @return $this |
148
|
|
|
*/ |
149
|
1 |
|
public function setUrl($url) |
150
|
|
|
{ |
151
|
1 |
|
$this->url = $url; |
152
|
|
|
|
153
|
1 |
|
return $this; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Get whether the option group has a selected option. |
158
|
|
|
* |
159
|
|
|
* @return bool |
160
|
|
|
*/ |
161
|
18 |
|
public function isInitiallySelected() |
162
|
|
|
{ |
163
|
18 |
|
return $this->initially_selected; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Set whether the option group has a selected option. |
168
|
|
|
* |
169
|
|
|
* @param bool $selected |
170
|
|
|
* |
171
|
|
|
* @return $this |
172
|
|
|
*/ |
173
|
21 |
|
public function setInitiallySelected($selected) |
174
|
|
|
{ |
175
|
21 |
|
$this->initially_selected = (bool)$selected; |
176
|
|
|
|
177
|
21 |
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Convert the block to its array representation. |
182
|
|
|
* |
183
|
|
|
* @return array |
184
|
|
|
*/ |
185
|
14 |
|
public function toArray() |
186
|
|
|
{ |
187
|
|
|
$data = [ |
188
|
14 |
|
'text' => $this->getText()->toArray(), |
189
|
14 |
|
'value' => $this->getValue(), |
190
|
|
|
]; |
191
|
|
|
|
192
|
14 |
|
if ($this->getDescription()) { |
193
|
1 |
|
$data['description'] = $this->getDescription()->toArray(); |
194
|
|
|
} |
195
|
|
|
|
196
|
14 |
|
if ($this->getUrl()) { |
197
|
1 |
|
$data['url'] = $this->getUrl(); |
198
|
|
|
} |
199
|
|
|
|
200
|
14 |
|
return $data; |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|