|
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 string |
|
107
|
|
|
*/ |
|
108
|
|
|
protected $lead; |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Article constructor. |
|
112
|
|
|
*/ |
|
113
|
42 |
|
public function __construct() |
|
114
|
|
|
{ |
|
115
|
42 |
|
$this->setCreatedAt(new \DateTime()); |
|
116
|
42 |
|
$this->setPublishable(false); |
|
117
|
42 |
|
$this->setMedia(new ArrayCollection()); |
|
118
|
42 |
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* {@inheritdoc} |
|
122
|
|
|
*/ |
|
123
|
|
|
public function setPublishStartDate(\DateTime $startDate = null) |
|
124
|
|
|
{ |
|
125
|
|
|
$this->publishStartDate = $startDate; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* {@inheritdoc} |
|
130
|
|
|
*/ |
|
131
|
8 |
|
public function getPublishStartDate() |
|
132
|
|
|
{ |
|
133
|
8 |
|
return $this->publishStartDate; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* {@inheritdoc} |
|
138
|
|
|
*/ |
|
139
|
|
|
public function setPublishEndDate(\DateTime $endDate = null) |
|
140
|
|
|
{ |
|
141
|
|
|
$this->publishEndDate = $endDate; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* {@inheritdoc} |
|
146
|
|
|
*/ |
|
147
|
8 |
|
public function getPublishEndDate() |
|
148
|
|
|
{ |
|
149
|
8 |
|
return $this->publishEndDate; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* {@inheritdoc} |
|
154
|
|
|
*/ |
|
155
|
8 |
|
public function isPublishable() |
|
156
|
|
|
{ |
|
157
|
8 |
|
return $this->isPublishable; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* {@inheritdoc} |
|
162
|
|
|
*/ |
|
163
|
42 |
|
public function setPublishable($boolean) |
|
164
|
|
|
{ |
|
165
|
42 |
|
$this->isPublishable = $boolean; |
|
166
|
42 |
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* {@inheritdoc} |
|
170
|
|
|
*/ |
|
171
|
3 |
|
public function isPublished() |
|
172
|
|
|
{ |
|
173
|
3 |
|
return $this->getStatus() === ArticleInterface::STATUS_PUBLISHED; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* {@inheritdoc} |
|
178
|
|
|
*/ |
|
179
|
16 |
|
public function getCreatedAt() |
|
180
|
|
|
{ |
|
181
|
16 |
|
return $this->createdAt; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* {@inheritdoc} |
|
186
|
|
|
*/ |
|
187
|
16 |
|
public function getUpdatedAt() |
|
188
|
|
|
{ |
|
189
|
16 |
|
return $this->updatedAt; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* {@inheritdoc} |
|
194
|
|
|
*/ |
|
195
|
42 |
|
public function setCreatedAt(\DateTime $createdAt) |
|
196
|
|
|
{ |
|
197
|
42 |
|
$this->createdAt = $createdAt; |
|
198
|
42 |
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* {@inheritdoc} |
|
202
|
|
|
*/ |
|
203
|
8 |
|
public function setUpdatedAt(\DateTime $updatedAt) |
|
204
|
|
|
{ |
|
205
|
8 |
|
$this->updatedAt = $updatedAt; |
|
206
|
8 |
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* {@inheritdoc} |
|
210
|
|
|
*/ |
|
211
|
37 |
|
public function setRoute(RouteInterface $route = null) |
|
212
|
|
|
{ |
|
213
|
37 |
|
$this->route = $route; |
|
214
|
37 |
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* {@inheritdoc} |
|
218
|
|
|
*/ |
|
219
|
20 |
|
public function getRoute() |
|
220
|
|
|
{ |
|
221
|
20 |
|
return $this->route; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* {@inheritdoc} |
|
226
|
|
|
*/ |
|
227
|
28 |
|
public function getId() |
|
228
|
|
|
{ |
|
229
|
28 |
|
return $this->id; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* {@inheritdoc} |
|
234
|
|
|
*/ |
|
235
|
18 |
|
public function getBody() |
|
236
|
|
|
{ |
|
237
|
18 |
|
return $this->body; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* {@inheritdoc} |
|
242
|
|
|
*/ |
|
243
|
40 |
|
public function setBody($body) |
|
244
|
|
|
{ |
|
245
|
40 |
|
$this->body = $body; |
|
246
|
40 |
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* {@inheritdoc} |
|
250
|
|
|
*/ |
|
251
|
|
|
public function getMedia() |
|
252
|
|
|
{ |
|
253
|
|
|
return $this->media; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* {@inheritdoc} |
|
258
|
|
|
*/ |
|
259
|
42 |
|
public function setMedia(Collection $media) |
|
260
|
|
|
{ |
|
261
|
42 |
|
$this->media = $media; |
|
262
|
42 |
|
} |
|
263
|
|
|
|
|
264
|
|
|
/** |
|
265
|
|
|
* {@inheritdoc} |
|
266
|
|
|
*/ |
|
267
|
16 |
|
public function getTitle() |
|
268
|
|
|
{ |
|
269
|
16 |
|
return $this->title; |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* {@inheritdoc} |
|
274
|
|
|
*/ |
|
275
|
41 |
|
public function setTitle($title) |
|
276
|
|
|
{ |
|
277
|
41 |
|
$this->title = $title; |
|
278
|
|
|
|
|
279
|
41 |
|
$this->setSlug(Transliterator::urlize($this->title)); |
|
280
|
41 |
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* {@inheritdoc} |
|
284
|
|
|
*/ |
|
285
|
22 |
|
public function getSlug() |
|
286
|
|
|
{ |
|
287
|
22 |
|
return $this->slug; |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* {@inheritdoc} |
|
292
|
|
|
*/ |
|
293
|
41 |
|
public function setSlug($slug) |
|
294
|
|
|
{ |
|
295
|
41 |
|
$this->slug = Transliterator::urlize($slug); |
|
296
|
41 |
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* {@inheritdoc} |
|
300
|
|
|
*/ |
|
301
|
16 |
|
public function getPublishedAt() |
|
302
|
|
|
{ |
|
303
|
16 |
|
return $this->publishedAt; |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
/** |
|
307
|
|
|
* {@inheritdoc} |
|
308
|
|
|
*/ |
|
309
|
31 |
|
public function setPublishedAt(\DateTime $publishedAt) |
|
310
|
|
|
{ |
|
311
|
31 |
|
$this->publishedAt = $publishedAt; |
|
312
|
31 |
|
} |
|
313
|
|
|
|
|
314
|
|
|
/** |
|
315
|
|
|
* {@inheritdoc} |
|
316
|
|
|
*/ |
|
317
|
12 |
|
public function getStatus() |
|
318
|
|
|
{ |
|
319
|
12 |
|
return $this->status; |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
/** |
|
323
|
|
|
* {@inheritdoc} |
|
324
|
|
|
*/ |
|
325
|
31 |
|
public function setStatus($status) |
|
326
|
|
|
{ |
|
327
|
31 |
|
$this->status = $status; |
|
328
|
31 |
|
} |
|
329
|
|
|
|
|
330
|
|
|
/** |
|
331
|
|
|
* {@inheritdoc} |
|
332
|
|
|
*/ |
|
333
|
12 |
|
public function getTemplateName() |
|
334
|
|
|
{ |
|
335
|
12 |
|
return $this->templateName; |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
/** |
|
339
|
|
|
* {@inheritdoc} |
|
340
|
|
|
*/ |
|
341
|
10 |
|
public function setTemplateName($templateName) |
|
342
|
|
|
{ |
|
343
|
10 |
|
$this->templateName = $templateName; |
|
344
|
10 |
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* {@inheritdoc} |
|
348
|
|
|
*/ |
|
349
|
28 |
|
public function getMetadata() |
|
350
|
|
|
{ |
|
351
|
28 |
|
return json_decode($this->metadata, true); |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
|
/** |
|
355
|
|
|
* {@inheritdoc} |
|
356
|
|
|
*/ |
|
357
|
3 |
|
public function getMetadataByKey($key) |
|
358
|
|
|
{ |
|
359
|
3 |
|
$metadata = $this->getMetadata(); |
|
360
|
|
|
|
|
361
|
3 |
|
if (isset($metadata[$key])) { |
|
362
|
3 |
|
return $metadata[$key]; |
|
363
|
|
|
} |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
/** |
|
367
|
|
|
* {@inheritdoc} |
|
368
|
|
|
*/ |
|
369
|
13 |
|
public function setMetadata(array $metadata) |
|
370
|
|
|
{ |
|
371
|
13 |
|
$this->metadata = json_encode($metadata, true); |
|
372
|
13 |
|
} |
|
373
|
|
|
|
|
374
|
|
|
/** |
|
375
|
|
|
* {@inheritdoc} |
|
376
|
|
|
*/ |
|
377
|
3 |
|
public function getSubjectType() |
|
378
|
|
|
{ |
|
379
|
3 |
|
return 'article'; |
|
380
|
|
|
} |
|
381
|
|
|
|
|
382
|
|
|
/** |
|
383
|
|
|
* {@inheritdoc} |
|
384
|
|
|
*/ |
|
385
|
16 |
|
public function getLead() |
|
386
|
|
|
{ |
|
387
|
16 |
|
return $this->lead; |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
|
/** |
|
391
|
|
|
* {@inheritdoc} |
|
392
|
|
|
*/ |
|
393
|
13 |
|
public function setLead($lead) |
|
394
|
|
|
{ |
|
395
|
13 |
|
$this->lead = $lead; |
|
396
|
13 |
|
} |
|
397
|
|
|
|
|
398
|
|
|
/** |
|
399
|
|
|
* Don't serialize values. |
|
400
|
|
|
* |
|
401
|
|
|
* @return array |
|
402
|
|
|
*/ |
|
403
|
|
|
public function __sleep() |
|
404
|
|
|
{ |
|
405
|
|
|
$this->media = 'Cannot be serializable'; |
|
|
|
|
|
|
406
|
|
|
|
|
407
|
|
|
return array_keys(get_object_vars($this)); |
|
408
|
|
|
} |
|
409
|
|
|
} |
|
410
|
|
|
|
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..