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\Bridge\Model\AuthorsAwareTrait; |
23
|
|
|
use SWP\Component\Common\Model\SoftDeletableTrait; |
24
|
|
|
use SWP\Component\Common\Model\TimestampableTrait; |
25
|
|
|
use SWP\Component\Common\Model\TranslatableTrait; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Class Article. |
29
|
|
|
*/ |
30
|
|
|
class Article implements ArticleInterface |
31
|
|
|
{ |
32
|
|
|
use TranslatableTrait, SoftDeletableTrait, TimestampableTrait, AuthorsAwareTrait, KeywordsAwareTrait; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var mixed |
36
|
|
|
*/ |
37
|
|
|
protected $id; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
protected $title; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
protected $body; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
protected $slug; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var \DateTime |
56
|
|
|
*/ |
57
|
|
|
protected $publishedAt; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
protected $status = ArticleInterface::STATUS_NEW; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var RouteInterface |
66
|
|
|
*/ |
67
|
|
|
protected $route; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var string |
71
|
|
|
*/ |
72
|
|
|
protected $templateName; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var \DateTime |
76
|
|
|
*/ |
77
|
|
|
protected $publishStartDate; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var \DateTime |
81
|
|
|
*/ |
82
|
|
|
protected $publishEndDate; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var bool |
86
|
|
|
*/ |
87
|
|
|
protected $isPublishable; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @var array |
91
|
|
|
*/ |
92
|
|
|
protected $metadata = []; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @var Collection |
96
|
|
|
*/ |
97
|
|
|
protected $media; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @var ArticleMediaInterface |
101
|
|
|
*/ |
102
|
|
|
protected $featureMedia; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @var string |
106
|
|
|
*/ |
107
|
|
|
protected $lead; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @var string |
111
|
|
|
*/ |
112
|
|
|
protected $code; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @var Collection|ArticleSourceInterface[] |
116
|
|
|
*/ |
117
|
|
|
protected $sources; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @var array|null |
121
|
|
|
*/ |
122
|
|
|
protected $extra; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @var Collection|SlideshowInterface[] |
126
|
|
|
*/ |
127
|
|
|
protected $slideshows; |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Article constructor. |
131
|
|
|
*/ |
132
|
|
|
public function __construct() |
133
|
|
|
{ |
134
|
|
|
$this->setCreatedAt(new \DateTime()); |
135
|
|
|
$this->setPublishable(false); |
136
|
|
|
$this->setMedia(new ArrayCollection()); |
137
|
|
|
$this->sources = new ArrayCollection(); |
138
|
|
|
$this->authors = new ArrayCollection(); |
139
|
|
|
$this->keywords = new ArrayCollection(); |
140
|
|
|
$this->slideshows = new ArrayCollection(); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* {@inheritdoc} |
145
|
|
|
*/ |
146
|
|
|
public function setPublishStartDate(\DateTime $startDate = null) |
147
|
|
|
{ |
148
|
|
|
$this->publishStartDate = $startDate; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* {@inheritdoc} |
153
|
|
|
*/ |
154
|
|
|
public function getPublishStartDate() |
155
|
|
|
{ |
156
|
|
|
return $this->publishStartDate; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* {@inheritdoc} |
161
|
|
|
*/ |
162
|
|
|
public function setPublishEndDate(\DateTime $endDate = null) |
163
|
|
|
{ |
164
|
|
|
$this->publishEndDate = $endDate; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* {@inheritdoc} |
169
|
|
|
*/ |
170
|
|
|
public function getPublishEndDate() |
171
|
|
|
{ |
172
|
|
|
return $this->publishEndDate; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* {@inheritdoc} |
177
|
|
|
*/ |
178
|
|
|
public function isPublishable() |
179
|
|
|
{ |
180
|
|
|
return $this->isPublishable; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* {@inheritdoc} |
185
|
|
|
*/ |
186
|
|
|
public function setPublishable($boolean) |
187
|
|
|
{ |
188
|
|
|
$this->isPublishable = $boolean; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* {@inheritdoc} |
193
|
|
|
*/ |
194
|
|
|
public function isPublished() |
195
|
|
|
{ |
196
|
|
|
return ArticleInterface::STATUS_PUBLISHED === $this->getStatus(); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* {@inheritdoc} |
201
|
|
|
*/ |
202
|
|
|
public function setRoute(RouteInterface $route = null) |
203
|
|
|
{ |
204
|
|
|
$this->route = $route; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* {@inheritdoc} |
209
|
|
|
*/ |
210
|
|
|
public function getRoute() |
211
|
|
|
{ |
212
|
|
|
return $this->route; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* {@inheritdoc} |
217
|
|
|
*/ |
218
|
|
|
public function getId() |
219
|
|
|
{ |
220
|
|
|
return $this->id; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* {@inheritdoc} |
225
|
|
|
*/ |
226
|
|
|
public function getBody() |
227
|
|
|
{ |
228
|
|
|
return $this->body; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* {@inheritdoc} |
233
|
|
|
*/ |
234
|
|
|
public function setBody($body) |
235
|
|
|
{ |
236
|
|
|
$this->body = $body; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* {@inheritdoc} |
241
|
|
|
*/ |
242
|
|
|
public function getMedia() |
243
|
|
|
{ |
244
|
|
|
return $this->media; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* {@inheritdoc} |
249
|
|
|
*/ |
250
|
|
|
public function setMedia(Collection $media) |
251
|
|
|
{ |
252
|
|
|
$this->media = $media; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* {@inheritdoc} |
257
|
|
|
*/ |
258
|
|
|
public function getTitle() |
259
|
|
|
{ |
260
|
|
|
return $this->title; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* {@inheritdoc} |
265
|
|
|
*/ |
266
|
|
|
public function setTitle($title) |
267
|
|
|
{ |
268
|
|
|
$this->title = $title; |
269
|
|
|
|
270
|
|
|
if (null !== $this->slug) { |
271
|
|
|
$this->setSlug($this->slug); |
272
|
|
|
|
273
|
|
|
return; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
$this->setSlug($this->title); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* {@inheritdoc} |
281
|
|
|
*/ |
282
|
|
|
public function getSlug() |
283
|
|
|
{ |
284
|
|
|
return $this->slug; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* {@inheritdoc} |
289
|
|
|
*/ |
290
|
|
|
public function setSlug($slug) |
291
|
|
|
{ |
292
|
|
|
$urlizedSlug = Transliterator::urlize($slug); |
293
|
|
|
|
294
|
|
|
if ('' === $urlizedSlug) { |
295
|
|
|
$slug = str_replace('\'', '-', $slug); |
296
|
|
|
$this->slug = Transliterator::transliterate($slug); |
297
|
|
|
|
298
|
|
|
return; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
$this->slug = $urlizedSlug; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* {@inheritdoc} |
306
|
|
|
*/ |
307
|
|
|
public function getPublishedAt() |
308
|
|
|
{ |
309
|
|
|
return $this->publishedAt; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* {@inheritdoc} |
314
|
|
|
*/ |
315
|
|
|
public function setPublishedAt(\DateTime $publishedAt) |
316
|
|
|
{ |
317
|
|
|
$this->publishedAt = $publishedAt; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* {@inheritdoc} |
322
|
|
|
*/ |
323
|
|
|
public function getStatus() |
324
|
|
|
{ |
325
|
|
|
return $this->status; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* {@inheritdoc} |
330
|
|
|
*/ |
331
|
|
|
public function setStatus($status) |
332
|
|
|
{ |
333
|
|
|
$this->status = $status; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* {@inheritdoc} |
338
|
|
|
*/ |
339
|
|
|
public function getTemplateName() |
340
|
|
|
{ |
341
|
|
|
return $this->templateName; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* {@inheritdoc} |
346
|
|
|
*/ |
347
|
|
|
public function setTemplateName($templateName) |
348
|
|
|
{ |
349
|
|
|
$this->templateName = $templateName; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* {@inheritdoc} |
354
|
|
|
*/ |
355
|
|
|
public function getMetadata() |
356
|
|
|
{ |
357
|
|
|
return $this->metadata; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* {@inheritdoc} |
362
|
|
|
*/ |
363
|
|
|
public function getMetadataByKey(string $key) |
364
|
|
|
{ |
365
|
|
|
$metadata = $this->getMetadata(); |
366
|
|
|
|
367
|
|
|
if (isset($metadata[$key])) { |
368
|
|
|
return $metadata[$key]; |
369
|
|
|
} |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* {@inheritdoc} |
374
|
|
|
*/ |
375
|
|
|
public function setMetadata(array $metadata) |
376
|
|
|
{ |
377
|
|
|
$this->metadata = $metadata; |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* {@inheritdoc} |
382
|
|
|
*/ |
383
|
|
|
public function getSubjectType() |
384
|
|
|
{ |
385
|
|
|
return 'article'; |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* {@inheritdoc} |
390
|
|
|
*/ |
391
|
|
|
public function getLead() |
392
|
|
|
{ |
393
|
|
|
return $this->lead; |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
/** |
397
|
|
|
* {@inheritdoc} |
398
|
|
|
*/ |
399
|
|
|
public function setLead($lead) |
400
|
|
|
{ |
401
|
|
|
$this->lead = $lead; |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
/** |
405
|
|
|
* {@inheritdoc} |
406
|
|
|
*/ |
407
|
|
|
public function getFeatureMedia() |
408
|
|
|
{ |
409
|
|
|
return $this->featureMedia; |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* {@inheritdoc} |
414
|
|
|
*/ |
415
|
|
|
public function setFeatureMedia(ArticleMediaInterface $featureMedia = null) |
416
|
|
|
{ |
417
|
|
|
$this->featureMedia = $featureMedia; |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
/** |
421
|
|
|
* {@inheritdoc} |
422
|
|
|
*/ |
423
|
|
|
public function getCode(): string |
424
|
|
|
{ |
425
|
|
|
return $this->code; |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
/** |
429
|
|
|
* {@inheritdoc} |
430
|
|
|
*/ |
431
|
|
|
public function setCode(string $code) |
432
|
|
|
{ |
433
|
|
|
$this->code = $code; |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* {@inheritdoc} |
438
|
|
|
*/ |
439
|
|
|
public function addSourceReference(ArticleSourceReferenceInterface $source) |
440
|
|
|
{ |
441
|
|
|
if (!$this->hasSourceReference($source)) { |
442
|
|
|
$this->sources->add($source); |
443
|
|
|
} |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* {@inheritdoc} |
448
|
|
|
*/ |
449
|
|
|
public function removeSourceReference(ArticleSourceReferenceInterface $source) |
450
|
|
|
{ |
451
|
|
|
$this->sources->removeElement($source); |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
/** |
455
|
|
|
* {@inheritdoc} |
456
|
|
|
*/ |
457
|
|
|
public function hasSourceReference(ArticleSourceReferenceInterface $source): bool |
458
|
|
|
{ |
459
|
|
|
return $this->sources->contains($source); |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
/** |
463
|
|
|
* {@inheritdoc} |
464
|
|
|
*/ |
465
|
|
|
public function getSources(): Collection |
466
|
|
|
{ |
467
|
|
|
if (0 < $this->sources->count()) { |
468
|
|
|
$sources = new ArrayCollection(); |
469
|
|
|
/** @var ArticleSourceReferenceInterface $source */ |
470
|
|
|
foreach ($this->sources as $source) { |
471
|
|
|
$sources->add($source->getArticleSource()); |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
return $sources; |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
return $this->sources; |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
/** |
481
|
|
|
* {@inheritdoc} |
482
|
|
|
*/ |
483
|
|
|
public function getExtra(): ?array |
484
|
|
|
{ |
485
|
|
|
return $this->extra; |
486
|
|
|
} |
487
|
|
|
|
488
|
|
|
/** |
489
|
|
|
* {@inheritdoc} |
490
|
|
|
*/ |
491
|
|
|
public function setExtra(?array $extra): void |
492
|
|
|
{ |
493
|
|
|
$this->extra = $extra; |
494
|
|
|
} |
495
|
|
|
|
496
|
|
|
public function getSlideshows(): Collection |
497
|
|
|
{ |
498
|
|
|
return $this->slideshows; |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
public function hasSlideshow(SlideshowInterface $slideshow): bool |
502
|
|
|
{ |
503
|
|
|
return $this->slideshows->contains($slideshow); |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
public function addSlideshow(SlideshowInterface $slideshow): void |
507
|
|
|
{ |
508
|
|
|
if (!$this->hasSlideshow($slideshow)) { |
509
|
|
|
$slideshow->setArticle($this); |
510
|
|
|
$this->slideshows->add($slideshow); |
511
|
|
|
} |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
public function removeSlideshow(SlideshowInterface $slideshow): void |
515
|
|
|
{ |
516
|
|
|
if ($this->hasSlideshow($slideshow)) { |
517
|
|
|
$slideshow->setArticle(null); |
518
|
|
|
$this->slideshows->removeElement($slideshow); |
519
|
|
|
} |
520
|
|
|
} |
521
|
|
|
} |
522
|
|
|
|