1
|
|
|
<?php |
2
|
|
|
namespace Maknz\Slack\BlockElement; |
3
|
|
|
|
4
|
|
|
use InvalidArgumentException; |
5
|
|
|
use Maknz\Slack\Object\Option; |
6
|
|
|
|
7
|
|
|
class MultiUserSelect extends MultiDynamicSelect |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Block type. |
11
|
|
|
* |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
protected $type = 'multi_users_select'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Initially selected users. |
18
|
|
|
* |
19
|
|
|
* @var string[] |
20
|
|
|
*/ |
21
|
|
|
protected $initial_users; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Internal attribute to property map. |
25
|
|
|
* |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected static $availableAttributes = [ |
29
|
|
|
'placeholder' => 'placeholder', |
30
|
|
|
'action_id' => 'action_id', |
31
|
|
|
'initial_users' => 'initial_users', |
32
|
|
|
'confirm' => 'confirm', |
33
|
|
|
'max_selected_items' => 'max_selected_items', |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get the initially selected users. |
38
|
|
|
* |
39
|
|
|
* @return string[] |
40
|
|
|
*/ |
41
|
4 |
|
public function getInitialUsers() |
42
|
|
|
{ |
43
|
4 |
|
return $this->initial_users; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Set the initially selected users. |
48
|
|
|
* |
49
|
|
|
* @param string[] $initialUsers |
50
|
|
|
* |
51
|
|
|
* @return $this |
52
|
|
|
* |
53
|
|
|
* @throws InvalidArgumentException |
54
|
|
|
*/ |
55
|
4 |
|
public function setInitialUsers(array $initialUsers) |
56
|
|
|
{ |
57
|
4 |
|
$this->clearInitialUsers(); |
58
|
|
|
|
59
|
4 |
|
foreach ($initialUsers as $initialUser) { |
60
|
4 |
|
$this->addInitialUser($initialUser); |
61
|
|
|
} |
62
|
|
|
|
63
|
3 |
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Clear the initially selected users. |
68
|
|
|
* |
69
|
|
|
* @return $this |
70
|
|
|
*/ |
71
|
4 |
|
public function clearInitialUsers() |
72
|
|
|
{ |
73
|
4 |
|
$this->initial_users = []; |
74
|
|
|
|
75
|
4 |
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Add an initially selected user. |
80
|
|
|
* |
81
|
|
|
* @param string $initialUsers |
82
|
|
|
* |
83
|
|
|
* @return $this |
84
|
|
|
* |
85
|
|
|
* @throws InvalidArgumentException |
86
|
|
|
*/ |
87
|
4 |
|
public function addInitialUser($initialUser) |
88
|
|
|
{ |
89
|
4 |
|
if (is_string($initialUser)) { |
90
|
3 |
|
$this->initial_users[] = $initialUser; |
91
|
|
|
|
92
|
3 |
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
1 |
|
throw new InvalidArgumentException('The initial user ID must be a string'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Convert the block to its array representation. |
101
|
|
|
* |
102
|
|
|
* @return array |
103
|
|
|
*/ |
104
|
1 |
|
public function toArray() |
105
|
|
|
{ |
106
|
1 |
|
$data = [ |
107
|
1 |
|
'type' => $this->getType(), |
108
|
1 |
|
'placeholder' => $this->getPlaceholder()->toArray(), |
109
|
1 |
|
'action_id' => $this->getActionId(), |
110
|
|
|
]; |
111
|
|
|
|
112
|
1 |
|
$initialUsers = $this->getInitialUsers(); |
113
|
|
|
|
114
|
1 |
|
if (count($initialUsers)) { |
115
|
1 |
|
$data['initial_users'] = $initialUsers; |
116
|
|
|
} |
117
|
|
|
|
118
|
1 |
|
if ($this->getConfirm()) { |
119
|
1 |
|
$data['confirm'] = $this->getConfirm()->toArray(); |
120
|
|
|
} |
121
|
|
|
|
122
|
1 |
|
if ($this->getMaxSelectedItems()) { |
123
|
1 |
|
$data['max_selected_items'] = $this->getMaxSelectedItems(); |
124
|
|
|
} |
125
|
|
|
|
126
|
1 |
|
return $data; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|