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