1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Trello\Api\Board; |
4
|
|
|
|
5
|
|
|
use Trello\Api\AbstractApi; |
6
|
|
|
use Trello\Api\Member; |
7
|
|
|
use Trello\Exception\InvalidArgumentException; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Trello Board Members API |
11
|
|
|
* @link https://trello.com/docs/api/board |
12
|
|
|
* |
13
|
|
|
* Fully implemented. |
14
|
|
|
*/ |
15
|
|
|
class Members extends AbstractApi |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Base path of board members api |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $path = 'boards/#id#/members'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Get a given board's members |
25
|
|
|
* @link https://trello.com/docs/api/board/#get-1-boards-board-id-members |
26
|
|
|
* |
27
|
|
|
* @param string $id the board's id |
28
|
|
|
* @param array $params optional parameters |
29
|
|
|
* |
30
|
|
|
* @return array |
31
|
|
|
*/ |
32
|
1 |
|
public function all($id, array $params = array()) |
33
|
|
|
{ |
34
|
1 |
|
return $this->get($this->getPath($id), $params); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Remove a given member from a given board |
39
|
|
|
* @link https://trello.com/docs/api/board/#get-1-boards-board-id-members |
40
|
|
|
* |
41
|
|
|
* @param string $id the board's id |
42
|
|
|
* @param string $memberId the member's id |
43
|
|
|
* |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
1 |
|
public function remove($id, $memberId) |
47
|
|
|
{ |
48
|
1 |
|
return $this->delete($this->getPath($id).'/'.$memberId); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Filter members related to a given board |
53
|
|
|
* @link https://trello.com/docs/api/board/#get-1-boards-board-id-members-filter |
54
|
|
|
* |
55
|
|
|
* @param string $id the board's id |
56
|
|
|
* @param string|array $filter array of / one of 'none', 'normal', 'admins', 'owners', 'all' |
57
|
|
|
* |
58
|
|
|
* @return array |
59
|
|
|
*/ |
60
|
3 |
|
public function filter($id, $filter = 'all') |
61
|
|
|
{ |
62
|
3 |
|
$allowed = array('none', 'normal', 'admins', 'owners', 'all'); |
63
|
3 |
|
$filters = $this->validateAllowedParameters($allowed, $filter, 'filter'); |
64
|
|
|
|
65
|
3 |
|
return $this->get($this->getPath($id).'/'.implode(',', $filters)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get a member's cards related to a given board |
70
|
|
|
* @link https://trello.com/docs/api/board/#get-1-boards-board-id-members-filter |
71
|
|
|
* |
72
|
|
|
* @param string $id the board's id |
73
|
|
|
* @param string $memberId the member's id |
74
|
|
|
* @param array $params optional parameters |
75
|
|
|
* |
76
|
|
|
* @return array |
77
|
|
|
*/ |
78
|
1 |
|
public function cards($id, $memberId, array $params = array()) |
79
|
|
|
{ |
80
|
1 |
|
return $this->get($this->getPath($id).'/'.rawurlencode($memberId).'/cards', $params); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Add member to a given board |
85
|
|
|
* @link https://trello.com/docs/api/board/#put-1-boards-board-id-members |
86
|
|
|
* |
87
|
|
|
* @param string $id the board's id |
88
|
|
|
* @param string $email the member's email address |
89
|
|
|
* @param string $fullName the member's full name |
90
|
|
|
* @param string $role one of 'normal', 'observer' or 'admin' |
91
|
|
|
* |
92
|
|
|
* @return array |
93
|
|
|
*/ |
94
|
2 |
View Code Duplication |
public function invite($id, $email, $fullName, $role = 'normal') |
|
|
|
|
95
|
|
|
{ |
96
|
2 |
|
$roles = array('normal', 'observer', 'admin'); |
97
|
|
|
|
98
|
2 |
|
if (!in_array($role, $roles)) { |
99
|
1 |
|
throw new InvalidArgumentException(sprintf( |
100
|
1 |
|
'The "role" parameter must be one of "%s".', |
101
|
1 |
|
implode(", ", $roles) |
102
|
1 |
|
)); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$params = array( |
106
|
1 |
|
'email' => $email, |
107
|
1 |
|
'fullName' => $fullName, |
108
|
1 |
|
'type' => $role, |
109
|
1 |
|
); |
110
|
|
|
|
111
|
1 |
|
return $this->put($this->getPath($id), $params); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Get members invited to a given board |
116
|
|
|
* @link https://trello.com/docs/api/board/#get-1-boards-board-id-membersinvited |
117
|
|
|
* |
118
|
|
|
* @param string $id the board's id |
119
|
|
|
* @param array $params optional parameters |
120
|
|
|
* |
121
|
|
|
* @return array |
122
|
|
|
*/ |
123
|
1 |
|
public function getInvitedMembers($id, array $params = array()) |
124
|
|
|
{ |
125
|
1 |
|
return $this->get($this->getPath($id).'Invited', $params); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Get a field related to a member invited to a given board |
130
|
|
|
* @link https://trello.com/docs/api/board/#get-1-boards-board-id-membersinvited-field |
131
|
|
|
* |
132
|
|
|
* @param string $id the board's id |
133
|
|
|
* @param string $field the member's field name |
134
|
|
|
* |
135
|
|
|
* @return array |
136
|
|
|
*/ |
137
|
2 |
|
public function getInvitedMembersField($id, $field) |
138
|
|
|
{ |
139
|
2 |
|
$this->validateAllowedParameters(Member::$fields, $field, 'field'); |
140
|
|
|
|
141
|
1 |
|
return $this->get($this->getPath($id).'Invited/'.rawurlencode($field)); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Set the role of a user or an organization on a given board |
146
|
|
|
* @link https://trello.com/docs/api/board/index.html#put-1-boards-board-id-members-idmember |
147
|
|
|
* |
148
|
|
|
* @param string $id the board's id |
149
|
|
|
* @param string $memberOrOrganization the member's id, user name or an organization name |
150
|
|
|
* |
151
|
|
|
* @return array |
152
|
|
|
*/ |
153
|
2 |
View Code Duplication |
public function setRole($id, $memberOrOrganization, $role) |
|
|
|
|
154
|
|
|
{ |
155
|
2 |
|
$roles = array('normal', 'observer', 'admin'); |
156
|
|
|
|
157
|
2 |
|
if (!in_array($role, $roles)) { |
158
|
1 |
|
throw new InvalidArgumentException(sprintf( |
159
|
1 |
|
'The "role" parameter must be one of "%s".', |
160
|
1 |
|
implode(", ", $roles) |
161
|
1 |
|
)); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
$params = array( |
165
|
1 |
|
'idMember' => $memberOrOrganization, |
166
|
1 |
|
'type' => $role, |
167
|
1 |
|
); |
168
|
|
|
|
169
|
1 |
|
return $this->post($this->getPath($id).'/'.rawurlencode($memberOrOrganization), $params); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.