|
1
|
|
|
<?php |
|
2
|
|
|
namespace Maknz\Slack\CompositionObject; |
|
3
|
|
|
|
|
4
|
|
|
use InvalidArgumentException; |
|
5
|
|
|
|
|
6
|
|
|
class Filter extends CompositionObject |
|
7
|
|
|
{ |
|
8
|
|
|
/** |
|
9
|
|
|
* Types of conversations to include in the list. |
|
10
|
|
|
* |
|
11
|
|
|
* @var string[] |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $types; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Whether to exclude shared channels from other organisations. |
|
17
|
|
|
* |
|
18
|
|
|
* @var bool |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $exclude_shared_channels = false; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Whether to exclude bot users. |
|
24
|
|
|
* |
|
25
|
|
|
* @var bool |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $exclude_bots = false; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Internal attribute to property map. |
|
31
|
|
|
* |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
protected static $availableAttributes = [ |
|
35
|
|
|
'include' => 'types', |
|
36
|
|
|
'exclude_external_shared_channels' => 'exclude_shared_channels', |
|
37
|
|
|
'exclude_bot_users' => 'exclude_bots', |
|
38
|
|
|
]; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Get the types of conversations to be included. |
|
42
|
|
|
* |
|
43
|
|
|
* @return string[] |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getTypes() |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->types; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Set the types of conversations to be included. |
|
52
|
|
|
* |
|
53
|
|
|
* @param string[] $text |
|
54
|
|
|
* |
|
55
|
|
|
* @return $this |
|
56
|
|
|
* |
|
57
|
|
|
* @throws \InvalidArgumentException |
|
58
|
|
|
*/ |
|
59
|
|
|
public function setTypes(array $types) |
|
60
|
|
|
{ |
|
61
|
|
|
$validTypes = ['im', 'mpim', 'private', 'public']; |
|
62
|
|
|
|
|
63
|
|
|
foreach ($types as $type) { |
|
64
|
|
|
if ( ! in_array($type, $validTypes)) { |
|
65
|
|
|
throw new InvalidArgumentException("Invalid filter include type '$type'; must be one of: ".implode(',', $validTypes)); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$this->types = $types; |
|
70
|
|
|
|
|
71
|
|
|
return $this; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get whether shared channels from other organisations are excluded. |
|
76
|
|
|
* |
|
77
|
|
|
* @return bool |
|
78
|
|
|
*/ |
|
79
|
|
|
public function areSharedChannelsExcluded() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->exclude_shared_channels; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Set whether shared channels from other organisations are excluded. |
|
86
|
|
|
* |
|
87
|
|
|
* @param bool $excludeSharedChannels |
|
88
|
|
|
* |
|
89
|
|
|
* @return $this |
|
90
|
|
|
*/ |
|
91
|
|
|
public function setExcludeSharedChannels($excludeSharedChannels = true) |
|
92
|
|
|
{ |
|
93
|
|
|
$this->exclude_shared_channels = (bool)$excludeSharedChannels; |
|
94
|
|
|
|
|
95
|
|
|
return $this; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Get whether bots are excluded. |
|
100
|
|
|
* |
|
101
|
|
|
* @return bool |
|
102
|
|
|
*/ |
|
103
|
|
|
public function areBotsExcluded() |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->exclude_bots; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Set whether bots are excluded. |
|
110
|
|
|
* |
|
111
|
|
|
* @param bool $excludeBots |
|
112
|
|
|
* |
|
113
|
|
|
* @return $this |
|
114
|
|
|
*/ |
|
115
|
|
|
public function setExcludeBots($excludeBots = true) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->exclude_bots = (bool)$excludeBots; |
|
118
|
|
|
|
|
119
|
|
|
return $this; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Convert the block to its array representation. |
|
124
|
|
|
* |
|
125
|
|
|
* @return array |
|
126
|
|
|
*/ |
|
127
|
|
|
public function toArray() |
|
128
|
|
|
{ |
|
129
|
|
|
$data = [ |
|
130
|
|
|
'include' => $this->getTypes(), |
|
131
|
|
|
'exclude_external_shared_channels' => $this->areSharedChannelsExcluded(), |
|
132
|
|
|
'exclude_bot_users' => $this->areBotsExcluded(), |
|
133
|
|
|
]; |
|
134
|
|
|
|
|
135
|
|
|
return $data; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|