Completed
Pull Request — master (#68)
by
unknown
06:26
created

Board::getLabels()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Trello\Model;
4
5
use Trello\Exception\InvalidArgumentException;
6
7
/**
8
 * @codeCoverageIgnore
9
 */
10
class Board extends AbstractObject implements BoardInterface
11
{
12
    protected $apiName = 'board';
13
14
    protected $loadParams = array(
15
        'fields'                   => 'all',
16
        'organization'             => true,
17
        'organization_memberships' => 'all',
18
        'members'                  => 'all',
19
        'membersInvited'           => 'all',
20
        'memberships'              => 'all',
21
        'lists'                    => 'all',
22
        'labels'                   => 'all',
23
    );
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function setName($name)
29
    {
30
        $this->data['name'] = $name;
31
32
        return $this;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function getName()
39
    {
40
        return $this->data['name'];
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function setDescription($desc)
47
    {
48
        $this->data['desc'] = $desc;
49
50
        return $this;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function getDescription()
57
    {
58
        return $this->data['desc'];
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function getDescriptionData()
65
    {
66
        return $this->data['descData'];
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function getUrl()
73
    {
74
        return $this->data['url'];
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function getShortUrl()
81
    {
82
        return $this->data['shortUrl'];
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function getShortLink()
89
    {
90
        return $this->data['shortLink'];
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function setOrganizationId($organizationId)
97
    {
98
        $this->data['idOrganization'] = $organizationId;
99
100
        return $this;
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106
    public function getOrganizationId()
107
    {
108
        return $this->data['idOrganization'];
109
    }
110
111
    /**
112
     * {@inheritdoc}
113
     */
114
    public function setOrganization(OrganizationInterface $organization)
115
    {
116
        return $this->setOrganizationId($organization->getId());
117
    }
118
119
    /**
120
     * {@inheritdoc}
121
     */
122
    public function getOrganization()
123
    {
124
        return new Organization($this->client, $this->getOrganizationId());
125
    }
126
127
    /**
128
     * {@inheritdoc}
129
     */
130
    public function getLists()
131
    {
132
        $lists = array();
133
134
        foreach ($this->data['lists'] as $data) {
135
            $lists[$data['id']] = new Cardlist($this->client, $data['id']);
136
        }
137
138
        return $lists;
139
    }
140
141
    /**
142
     * {@inheritdoc}
143
     */
144
    public function getList($idOrName)
145
    {
146
        foreach ($this->getLists() as $list) {
147
            if ($list->getName() === $idOrName || $list->getId() === $idOrName) {
148
                return $list;
149
            }
150
        }
151
152
        throw new InvalidArgumentException(sprintf(
153
            'There is no list with name or id "%s" on this board ("%s")',
154
            $idOrName,
155
            $this->getName()
156
        ));
157
    }
158
159
    /**
160
     * {@inheritdoc}
161
     */
162
    public function setClosed($closed)
163
    {
164
        $this->data['closed'] = $closed;
165
166
        return $this;
167
    }
168
169
    /**
170
     * {@inheritdoc}
171
     */
172
    public function isClosed()
173
    {
174
        return $this->data['closed'];
175
    }
176
177
    /**
178
     * {@inheritdoc}
179
     */
180
    public function setPinned($pinned)
181
    {
182
        $this->data['pinned'] = $pinned;
183
184
        return $this;
185
    }
186
187
    /**
188
     * {@inheritdoc}
189
     */
190
    public function isPinned()
191
    {
192
        return $this->data['pinned'];
193
    }
194
195
    /**
196
     * {@inheritdoc}
197
     */
198
    public function setStarred($starred)
199
    {
200
        $this->data['starred'] = $starred;
201
202
        return $this;
203
    }
204
205
    /**
206
     * {@inheritdoc}
207
     */
208
    public function isStarred()
209
    {
210
        return $this->data['starred'];
211
    }
212
213
    /**
214
     * {@inheritdoc}
215
     */
216
    public function setSubscribed($subscribed)
217
    {
218
        $this->data['subscribed'] = $subscribed;
219
220
        return $this;
221
    }
222
223
    /**
224
     * {@inheritdoc}
225
     */
226
    public function isSubscribed()
227
    {
228
        return $this->data['subscribed'];
229
    }
230
231
    /**
232
     * {@inheritdoc}
233
     */
234
    public function isInvited()
235
    {
236
        return $this->data['invited'];
237
    }
238
239
    /**
240
     * {@inheritdoc}
241
     */
242
    public function setRequiredRoleToInvite($role)
243
    {
244
        $this->data['invitations'] = $role;
245
246
        return $this;
247
    }
248
249
    /**
250
     * {@inheritdoc}
251
     */
252
    public function getRequiredRoleToInvite()
253
    {
254
        return $this->data['invitations'];
255
    }
256
257
    /**
258
     * {@inheritdoc}
259
     */
260
    public function setMemberships(array $memberships)
261
    {
262
        $this->data['memberships'] = $memberships;
263
264
        return $this;
265
    }
266
267
    /**
268
     * {@inheritdoc}
269
     */
270
    public function getMemberships()
271
    {
272
        return $this->data['memberships'];
273
    }
274
275
    /**
276
     * {@inheritdoc}
277
     */
278
    public function setPreferences(array $prefs)
279
    {
280
        $this->data['prefs'] = $prefs;
281
282
        return $this;
283
    }
284
285
    /**
286
     * {@inheritdoc}
287
     */
288
    public function getPreferences()
289
    {
290
        return $this->data['prefs'];
291
    }
292
293
    /**
294
     * {@inheritdoc}
295
     */
296
    public function setLabelNames(array $labelNames)
297
    {
298
        $this->data['labelNames'] = $labelNames;
299
300
        return $this;
301
    }
302
303
    /**
304
     * {@inheritdoc}
305
     */
306
    public function getLabelNames()
307
    {
308
        return $this->data['labelNames'];
309
    }
310
311
    /**
312
     * {@inheritdoc}
313
     */
314
    public function getLabels()
315
    {
316
        $labels = array();
317
318
        foreach ($this->data['labels'] as $data) {
319
            $labels[$data['id']] = new Label($this->client, $data['id']);
320
        }
321
322
        return $labels;
323
    }
324
325
    public function getLabel($name, $color)
326
    {
327
        foreach ($this->data['labels'] as $data) {
328
            if ($data['name'] === $name && $data['color'] === $color) {
329
                return new Label($this->client, $data['id']);
330
            }
331
        }
332
333
        throw new InvalidArgumentException(sprintf(
334
            'There is no list with name "%s" and color "%s" on this board ("%s")',
335
            $name,
336
            $color,
337
            $this->getName()
338
        ));
339
    }
340
341
    /**
342
     * {@inheritdoc}
343
     */
344
    public function setPowerUps(array $powerUps)
345
    {
346
        $this->data['powerUps'] = $powerUps;
347
348
        return $this;
349
    }
350
351
    /**
352
     * {@inheritdoc}
353
     */
354
    public function getPowerUps()
355
    {
356
        return $this->data['powerUps'];
357
    }
358
359
    /**
360
     * {@inheritdoc}
361
     */
362
    public function getDateOfLastActivity()
363
    {
364
        return new \DateTime($this->data['dateLastActivity']);
365
    }
366
367
    /**
368
     * {@inheritdoc}
369
     */
370
    public function getDateOfLastView()
371
    {
372
        return new \DateTime($this->data['dateLastView']);
373
    }
374
}
375