Completed
Push — master ( 6ca798...857129 )
by Rafał
09:18 queued 10s
created

ArticleMedia::getCopyrightHolder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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 Doctrine\Common\Collections\ArrayCollection;
20
use SWP\Component\Bridge\Model\ItemInterface;
21
use SWP\Component\Bridge\Model\License;
22
use SWP\Component\Common\Model\SoftDeletableTrait;
23
use SWP\Component\Common\Model\TimestampableTrait;
24
25
class ArticleMedia implements ArticleMediaInterface
26
{
27
    use TimestampableTrait;
28
    use SoftDeletableTrait;
29
30
    /**
31
     * @var int
32
     */
33
    protected $id;
34
35
    /**
36
     * @var string
37
     */
38
    protected $key;
39
40
    /**
41
     * @var FileInterface
42
     */
43
    protected $file;
44
45
    /**
46
     * @var ImageInterface
47
     */
48
    protected $image;
49
50
    /**
51
     * @var ArticleInterface
52
     */
53
    protected $article;
54
55
    /**
56
     * @var string
57
     */
58
    protected $description;
59
60
    /**
61
     * @var string
62
     */
63
    protected $located;
64
65
    /**
66
     * @var string
67
     */
68
    protected $byLine;
69
70
    /**
71
     * @var string
72
     */
73
    protected $body;
74
75
    /**
76
     * @var string
77
     */
78
    protected $mimetype;
79
80
    /**
81
     * @var string
82
     */
83
    protected $usageTerms;
84
85
    /**
86
     * @var ArrayCollection
87
     */
88
    protected $renditions;
89
90
    /**
91
     * @var string|null
92
     */
93
    protected $headline;
94
95
    /**
96
     * @var string|null
97
     */
98
    protected $copyrightHolder;
99
100
    /**
101
     * @var string/null
102
     */
103
    protected $copyrightNotice;
104
105
    /** @var string|null */
106
    protected $mediaType = ArticleMediaInterface::TYPE_EMBEDDED_IMAGE;
107
108
    /** @var License|null */
109
    protected $license;
110
111
    /**
112
     * ArticleMedia constructor.
113
     */
114
    public function __construct()
115
    {
116
        $this->renditions = new ArrayCollection();
117
    }
118
119
    /**
120
     * {@inheritdoc}
121
     */
122
    public function getRenditions()
123
    {
124
        return $this->renditions;
125
    }
126
127
    /**
128
     * {@inheritdoc}
129
     */
130
    public function addRendition(ImageRenditionInterface $rendition)
131
    {
132
        $this->renditions->add($rendition);
133
    }
134
135
    /**
136
     * {@inheritdoc}
137
     */
138
    public function setRenditions($renditions)
139
    {
140
        $this->renditions = $renditions;
141
    }
142
143
    /**
144
     * {@inheritdoc}
145
     */
146
    public function getId()
147
    {
148
        return $this->id;
149
    }
150
151
    /**
152
     * {@inheritdoc}
153
     */
154
    public function getFile()
155
    {
156
        return $this->file;
157
    }
158
159
    /**
160
     * {@inheritdoc}
161
     */
162
    public function setFile($file)
163
    {
164
        $this->file = $file;
165
166
        return $this;
167
    }
168
169
    /**
170
     * {@inheritdoc}
171
     */
172
    public function getImage()
173
    {
174
        return $this->image;
175
    }
176
177
    /**
178
     * {@inheritdoc}
179
     */
180
    public function setImage($image)
181
    {
182
        $this->image = $image;
183
184
        return $this;
185
    }
186
187
    /**
188
     * {@inheritdoc}
189
     */
190
    public function getArticle()
191
    {
192
        return $this->article;
193
    }
194
195
    /**
196
     * {@inheritdoc}
197
     */
198
    public function setArticle(ArticleInterface $article)
199
    {
200
        $this->article = $article;
201
202
        return $this;
203
    }
204
205
    /**
206
     * {@inheritdoc}
207
     */
208
    public function getAssetId(): ?string
209
    {
210
        if ($this->getImage() instanceof Image) {
211
            return $this->getImage()->getAssetId();
212
        }
213
214
        if ($this->getFile() instanceof File) {
215
            return $this->getFile()->getAssetId();
216
        }
217
    }
218
219
    /**
220
     * {@inheritdoc}
221
     */
222
    public function getDescription()
223
    {
224
        return $this->description;
225
    }
226
227
    /**
228
     * {@inheritdoc}
229
     */
230
    public function setDescription($description)
231
    {
232
        $this->description = $description;
233
234
        return $this;
235
    }
236
237
    /**
238
     * {@inheritdoc}
239
     */
240
    public function getLocated()
241
    {
242
        return $this->located;
243
    }
244
245
    /**
246
     * {@inheritdoc}
247
     */
248
    public function setLocated($located)
249
    {
250
        $this->located = $located;
251
252
        return $this;
253
    }
254
255
    /**
256
     * {@inheritdoc}
257
     */
258
    public function getByLine()
259
    {
260
        return $this->byLine;
261
    }
262
263
    /**
264
     * {@inheritdoc}
265
     */
266
    public function setByLine($byLine)
267
    {
268
        $this->byLine = $byLine;
269
270
        return $this;
271
    }
272
273
    /**
274
     * {@inheritdoc}
275
     */
276
    public function getBody()
277
    {
278
        return $this->body;
279
    }
280
281
    /**
282
     * {@inheritdoc}
283
     */
284
    public function setBody($body)
285
    {
286
        $this->body = $body;
287
288
        return $this;
289
    }
290
291
    /**
292
     * {@inheritdoc}
293
     */
294
    public function getMimetype()
295
    {
296
        return $this->mimetype;
297
    }
298
299
    /**
300
     * {@inheritdoc}
301
     */
302
    public function setMimetype($mimetype)
303
    {
304
        $this->mimetype = $mimetype;
305
306
        return $this;
307
    }
308
309
    /**
310
     * {@inheritdoc}
311
     */
312
    public function getUsageTerms()
313
    {
314
        return $this->usageTerms;
315
    }
316
317
    /**
318
     * {@inheritdoc}
319
     */
320
    public function setUsageTerms($usageTerms)
321
    {
322
        $this->usageTerms = $usageTerms;
323
324
        return $this;
325
    }
326
327
    /**
328
     * {@inheritdoc}
329
     */
330
    public function getKey(): string
331
    {
332
        return $this->key;
333
    }
334
335
    /**
336
     * {@inheritdoc}
337
     */
338
    public function setKey(string $key)
339
    {
340
        $this->key = $key;
341
    }
342
343
    public function getHeadline(): ?string
344
    {
345
        return $this->headline;
346
    }
347
348
    public function setHeadline(?string $headline): void
349
    {
350
        $this->headline = $headline;
351
    }
352
353
    public function getCopyrightNotice(): ?string
354
    {
355
        return $this->copyrightNotice;
356
    }
357
358
    public function setCopyrightNotice(?string $copyrightNotice): void
359
    {
360
        $this->copyrightNotice = $copyrightNotice;
361
    }
362
363
    public function getCopyrightHolder(): ?string
364
    {
365
        return $this->copyrightHolder;
366
    }
367
368
    public function setCopyrightHolder(?string $copyrightHolder): void
369
    {
370
        $this->copyrightHolder = $copyrightHolder;
371
    }
372
373
    public function getMediaType(): ?string
374
    {
375
        return $this->mediaType;
376
    }
377
378
    public function setMediaType(?string $mediaType): void
379
    {
380
        $this->mediaType = $mediaType;
381
    }
382
383
    /**
384
     * {@inheritdoc}
385
     */
386
    public function setFromItem(ItemInterface $item)
387
    {
388
        $this->setBody($item->getBody() ?: $item->getBodyText());
389
        $this->setByLine($item->getByLine());
390
        $this->setLocated($item->getLocated());
391
        $this->setDescription($item->getDescription());
392
        $this->setUsageTerms($item->getUsageTerms());
393
        $this->setHeadline($item->getHeadline());
394
        $this->setCopyrightHolder($item->getCopyrightHolder());
395
        $this->setCopyrightNotice($item->getCopyrightNotice());
396
    }
397
398
    /**
399
     * {@inheritdoc}
400
     */
401
    public static function handleMediaId($mediaId)
402
    {
403
        $mediaId = preg_replace('/\\.[^.\\s]{3,4}$/', '', $mediaId);
404
        $mediaIdElements = explode('/', $mediaId);
405
        if (count($mediaIdElements) > 1) {
406
            return implode('_', $mediaIdElements);
407
        }
408
409
        return $mediaId;
410
    }
411
412
    /**
413
     * {@inheritdoc}
414
     */
415
    public static function getOriginalMediaId(string $mediaId)
416
    {
417
        return str_replace('_', '/', $mediaId);
418
    }
419
420
    public function getLicense(): ?License
421
    {
422
        return $this->license;
423
    }
424
425
    public function setLicense(License $license): void
426
    {
427
        $this->license = $license;
428
    }
429
}
430