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