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