Completed
Push — master ( 6cd8ca...cbb2b9 )
by Paweł
63:35
created

Article::setMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Content Bundle.
7
 *
8
 * Copyright 2016 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2016 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\ContentBundle\Model;
18
19
use Behat\Transliterator\Transliterator;
20
use Doctrine\Common\Collections\ArrayCollection;
21
use Doctrine\Common\Collections\Collection;
22
use SWP\Component\Common\Model\SoftDeletableTrait;
23
use SWP\Component\Common\Model\TimestampableTrait;
24
use SWP\Component\Common\Model\TranslatableTrait;
25
26
/**
27
 * Class Article.
28
 */
29
class Article implements ArticleInterface, MediaAwareArticleInterface
30
{
31
    use TranslatableTrait, SoftDeletableTrait, TimestampableTrait;
32
33
    /**
34
     * @var mixed
35
     */
36
    protected $id;
37
38
    /**
39
     * @var string
40
     */
41
    protected $title;
42
43
    /**
44
     * @var string
45
     */
46
    protected $body;
47
48
    /**
49
     * @var string
50
     */
51
    protected $slug;
52
53
    /**
54
     * @var \DateTime
55
     */
56
    protected $publishedAt;
57
58
    /**
59
     * @var string
60
     */
61
    protected $status = ArticleInterface::STATUS_NEW;
62
63
    /**
64
     * @var RouteInterface
65
     */
66
    protected $route;
67
68
    /**
69
     * @var string
70
     */
71
    protected $templateName;
72
73
    /**
74
     * @var \DateTime
75
     */
76
    protected $publishStartDate;
77
78
    /**
79
     * @var \DateTime
80
     */
81
    protected $publishEndDate;
82
83
    /**
84
     * @var bool
85
     */
86
    protected $isPublishable;
87
88
    /**
89
     * @var array
90
     */
91
    protected $metadata = [];
92
93
    /**
94
     * @var Collection
95
     */
96
    protected $media;
97
98
    /**
99
     * @var ArticleMediaInterface
100
     */
101
    protected $featureMedia;
102
103
    /**
104
     * @var string
105
     */
106
    protected $lead;
107
108
    /**
109
     * @var array
110
     */
111
    protected $keywords = [];
112
113
    /**
114
     * @var string
115
     */
116
    protected $code;
117
118 32
    /**
119
     * Article constructor.
120 32
     */
121 32
    public function __construct()
122 32
    {
123 32
        $this->setCreatedAt(new \DateTime());
124
        $this->setPublishable(false);
125
        $this->setMedia(new ArrayCollection());
126
    }
127
128
    /**
129
     * {@inheritdoc}
130
     */
131
    public function setPublishStartDate(\DateTime $startDate = null)
132
    {
133
        $this->publishStartDate = $startDate;
134
    }
135
136 8
    /**
137
     * {@inheritdoc}
138 8
     */
139
    public function getPublishStartDate()
140
    {
141
        return $this->publishStartDate;
142
    }
143
144
    /**
145
     * {@inheritdoc}
146
     */
147
    public function setPublishEndDate(\DateTime $endDate = null)
148
    {
149
        $this->publishEndDate = $endDate;
150
    }
151
152 8
    /**
153
     * {@inheritdoc}
154 8
     */
155
    public function getPublishEndDate()
156
    {
157
        return $this->publishEndDate;
158
    }
159
160 5
    /**
161
     * {@inheritdoc}
162 5
     */
163
    public function isPublishable()
164
    {
165
        return $this->isPublishable;
166
    }
167
168 31
    /**
169
     * {@inheritdoc}
170 31
     */
171 31
    public function setPublishable($boolean)
172
    {
173
        $this->isPublishable = $boolean;
174
    }
175
176 10
    /**
177
     * {@inheritdoc}
178 10
     */
179
    public function isPublished()
180
    {
181
        return $this->getStatus() === ArticleInterface::STATUS_PUBLISHED;
182
    }
183
184 9
    /**
185
     * {@inheritdoc}
186 9
     */
187
    public function setRoute(RouteInterface $route = null)
188
    {
189
        $this->route = $route;
190
    }
191
192 9
    /**
193
     * {@inheritdoc}
194 9
     */
195
    public function getRoute()
196
    {
197
        return $this->route;
198
    }
199
200 31
    /**
201
     * {@inheritdoc}
202 31
     */
203 31
    public function getId()
204
    {
205
        return $this->id;
206
    }
207
208 4
    /**
209
     * {@inheritdoc}
210 4
     */
211 4
    public function getBody()
212
    {
213
        return $this->body;
214
    }
215
216 26
    /**
217
     * {@inheritdoc}
218 26
     */
219 26
    public function setBody($body)
220
    {
221
        $this->body = $body;
222
    }
223
224 22
    /**
225
     * {@inheritdoc}
226 22
     */
227
    public function getMedia()
228
    {
229
        return $this->media;
230
    }
231
232 12
    /**
233
     * {@inheritdoc}
234 12
     */
235
    public function setMedia(Collection $media)
236
    {
237
        $this->media = $media;
238
    }
239
240 9
    /**
241
     * {@inheritdoc}
242 9
     */
243
    public function getTitle()
244
    {
245
        return $this->title;
246
    }
247
248 31
    /**
249
     * {@inheritdoc}
250 31
     */
251 31
    public function setTitle($title)
252
    {
253
        $this->title = $title;
254
255
        $this->setSlug(Transliterator::urlize($this->title));
256
    }
257
258
    /**
259
     * {@inheritdoc}
260
     */
261
    public function getSlug()
262
    {
263
        return $this->slug;
264 31
    }
265
266 31
    /**
267 31
     * {@inheritdoc}
268
     */
269
    public function setSlug($slug)
270
    {
271
        $this->slug = Transliterator::urlize($slug);
272 9
    }
273
274 9
    /**
275
     * {@inheritdoc}
276
     */
277
    public function getPublishedAt()
278
    {
279
        return $this->publishedAt;
280 31
    }
281
282 31
    /**
283
     * {@inheritdoc}
284 31
     */
285 31
    public function setPublishedAt(\DateTime $publishedAt)
286
    {
287
        $this->publishedAt = $publishedAt;
288
    }
289
290 26
    /**
291
     * {@inheritdoc}
292 26
     */
293
    public function getStatus()
294
    {
295
        return $this->status;
296
    }
297
298 31
    /**
299
     * {@inheritdoc}
300 31
     */
301 31
    public function setStatus($status)
302
    {
303
        $this->status = $status;
304
    }
305
306 11
    /**
307
     * {@inheritdoc}
308 11
     */
309
    public function getTemplateName()
310
    {
311
        return $this->templateName;
312
    }
313
314 18
    /**
315
     * {@inheritdoc}
316 18
     */
317 18
    public function setTemplateName($templateName)
318
    {
319
        $this->templateName = $templateName;
320
    }
321
322 10
    /**
323
     * {@inheritdoc}
324 10
     */
325
    public function getMetadata()
326
    {
327
        return $this->metadata;
328
    }
329
330 23
    /**
331
     * {@inheritdoc}
332 23
     */
333 23
    public function getMetadataByKey(string $key)
334
    {
335
        $metadata = $this->getMetadata();
336
337
        if (isset($metadata[$key])) {
338 9
            return $metadata[$key];
339
        }
340 9
    }
341
342
    /**
343
     * {@inheritdoc}
344
     */
345
    public function setMetadata(array $metadata)
346 12
    {
347
        $this->metadata = $metadata;
348 12
    }
349 12
350
    /**
351
     * {@inheritdoc}
352
     */
353
    public function getSubjectType()
354 22
    {
355
        return 'article';
356 22
    }
357
358
    /**
359
     * {@inheritdoc}
360
     */
361
    public function getLead()
362 8
    {
363
        return $this->lead;
364 8
    }
365
366 8
    /**
367 8
     * {@inheritdoc}
368
     */
369
    public function setLead($lead)
370
    {
371
        $this->lead = $lead;
372
    }
373
374 11
    /**
375
     * {@inheritdoc}
376 11
     */
377 11
    public function getKeywords(): array
378
    {
379
        return $this->keywords;
380
    }
381
382 7
    /**
383
     * {@inheritdoc}
384 7
     */
385
    public function setKeywords(array $keywords)
386
    {
387
        $this->keywords = $keywords;
388
    }
389
390 9
    /**
391
     * {@inheritdoc}
392 9
     */
393
    public function getFeatureMedia()
394
    {
395
        return $this->featureMedia;
396
    }
397
398 11
    /**
399
     * {@inheritdoc}
400 11
     */
401 11
    public function setFeatureMedia(ArticleMediaInterface $featureMedia = null)
402
    {
403
        $this->featureMedia = $featureMedia;
404
    }
405
406 9
    /**
407
     * {@inheritdoc}
408 9
     */
409
    public function getCode(): string
410
    {
411
        return $this->code;
412
    }
413
414 11
    /**
415
     * {@inheritdoc}
416 11
     */
417 11
    public function setCode(string $code)
418
    {
419
        $this->code = $code;
420
    }
421
}
422