|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Victoire\Bundle\BlogBundle\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
6
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
|
7
|
|
|
use Gedmo\Timestampable\Traits\TimestampableEntity; |
|
8
|
|
|
use Knp\DoctrineBehaviors\Model\Translatable\Translatable; |
|
9
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccess; |
|
10
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
11
|
|
|
use Victoire\Bundle\BusinessEntityBundle\Entity\Traits\BusinessEntityTrait; |
|
12
|
|
|
use Victoire\Bundle\BusinessPageBundle\Entity\BusinessTemplate; |
|
13
|
|
|
use Victoire\Bundle\CoreBundle\Annotations as VIC; |
|
14
|
|
|
use Victoire\Bundle\PageBundle\Entity\PageStatus; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @ORM\Entity(repositoryClass="Victoire\Bundle\BlogBundle\Repository\ArticleRepository")) |
|
18
|
|
|
* @ORM\Table("vic_article") |
|
19
|
|
|
* @VIC\BusinessEntity({"Date", "Force", "Redactor", "Listing", "BlogArticles", "Title", "CKEditor", "Text", "UnderlineTitle", "Cover", "Image", "Authorship", "ArticleList", "SliderNav"}) |
|
20
|
|
|
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false) |
|
21
|
|
|
*/ |
|
22
|
|
|
class Article |
|
23
|
|
|
{ |
|
24
|
|
|
use BusinessEntityTrait; |
|
25
|
|
|
use TimestampableEntity; |
|
26
|
|
|
use Translatable; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @VIC\BusinessProperty("businessParameter") |
|
30
|
|
|
* @ORM\Column(name="id", type="integer") |
|
31
|
|
|
* @ORM\Id |
|
32
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
|
33
|
|
|
*/ |
|
34
|
|
|
private $id; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @deprecated |
|
38
|
|
|
* Title is inherited from Page, just add the BusinessProperty annotation. |
|
39
|
|
|
* |
|
40
|
|
|
* @ORM\Column(name="name", type="string", length=255, nullable=true) |
|
41
|
|
|
*/ |
|
42
|
|
|
private $name; |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @deprecated |
|
46
|
|
|
* @ORM\Column(name="slug", type="string", length=255, nullable=true) |
|
47
|
|
|
*/ |
|
48
|
|
|
private $slug; |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @deprecated |
|
52
|
|
|
* Description is inherited from Page, just add the BusinessProperty annotation. |
|
53
|
|
|
* |
|
54
|
|
|
* @ORM\Column(name="description", type="text", nullable=true) |
|
55
|
|
|
*/ |
|
56
|
|
|
private $description; |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @deprecated |
|
60
|
|
|
* |
|
61
|
|
|
* @var string |
|
62
|
|
|
* |
|
63
|
|
|
* @ORM\ManyToOne(targetEntity="\Victoire\Bundle\MediaBundle\Entity\Media") |
|
64
|
|
|
* @ORM\JoinColumn(name="image_id", referencedColumnName="id", onDelete="CASCADE") |
|
65
|
|
|
* @VIC\BusinessProperty("imageable") |
|
66
|
|
|
*/ |
|
67
|
|
|
private $image; |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @ORM\Column(name="status", type="string", nullable=false) |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $status; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Categories of the article. |
|
76
|
|
|
* |
|
77
|
|
|
* @ORM\ManyToOne(targetEntity="Category", inversedBy="articles") |
|
78
|
|
|
* @ORM\JoinColumn(onDelete="SET NULL") |
|
79
|
|
|
* @VIC\BusinessProperty({"textable", "seoable"}) |
|
80
|
|
|
*/ |
|
81
|
|
|
private $category; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @var datetime |
|
85
|
|
|
* |
|
86
|
|
|
* @ORM\Column(name="publishedAt", type="datetime", nullable=true) |
|
87
|
|
|
* @VIC\BusinessProperty({"dateable", "textable"}) |
|
88
|
|
|
*/ |
|
89
|
|
|
private $publishedAt; |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* This relation is dynamically added by ArticleSubscriber |
|
93
|
|
|
* The property is needed here. |
|
94
|
|
|
* |
|
95
|
|
|
* @VIC\BusinessProperty({"textable", "seoable"}) |
|
96
|
|
|
*/ |
|
97
|
|
|
private $author; |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Tags of the article. |
|
101
|
|
|
* |
|
102
|
|
|
* @ORM\ManyToMany(targetEntity="Tag", inversedBy="articles") |
|
103
|
|
|
* @ORM\JoinTable(name="vic_article_tags") |
|
104
|
|
|
* @Assert\Valid() |
|
105
|
|
|
*/ |
|
106
|
|
|
private $tags; |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @ORM\ManyToOne(targetEntity="\Victoire\Bundle\BlogBundle\Entity\Blog", inversedBy="articles", cascade={"persist"}) |
|
110
|
|
|
* @ORM\JoinColumn(name="blog_id", referencedColumnName="id", onDelete="CASCADE") |
|
111
|
|
|
*/ |
|
112
|
|
|
private $blog; |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @var BusinessTemplate |
|
116
|
|
|
* @ORM\ManyToOne(targetEntity="ArticleTemplate") |
|
117
|
|
|
* @ORM\JoinColumn(name="template_id", referencedColumnName="id", onDelete="SET NULL") |
|
118
|
|
|
* @Assert\NotNull() |
|
119
|
|
|
*/ |
|
120
|
|
|
private $template; |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @VIC\BusinessProperty("textable") |
|
124
|
|
|
*/ |
|
125
|
|
|
private $categoryTitle; |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @VIC\BusinessProperty("textable") |
|
129
|
|
|
*/ |
|
130
|
|
|
private $publishedAtString; |
|
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @VIC\BusinessProperty("textable") |
|
134
|
|
|
*/ |
|
135
|
|
|
private $authorAvatar; |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @VIC\BusinessProperty("textable") |
|
139
|
|
|
*/ |
|
140
|
|
|
private $authorFullName; |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @ORM\Column(name="deletedAt", type="datetime", nullable=true) |
|
144
|
|
|
*/ |
|
145
|
|
|
private $deletedAt; |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @Gedmo\Locale |
|
149
|
|
|
*/ |
|
150
|
|
|
protected $locale; |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* to string method. |
|
154
|
|
|
* |
|
155
|
|
|
* @return string |
|
156
|
|
|
*/ |
|
157
|
|
|
public function __toString() |
|
158
|
|
|
{ |
|
159
|
|
|
return $this->getName(); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Constructor. |
|
164
|
|
|
*/ |
|
165
|
|
|
public function __construct() |
|
166
|
|
|
{ |
|
167
|
|
|
$this->status = PageStatus::DRAFT; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Get id. |
|
172
|
|
|
* |
|
173
|
|
|
* @return int |
|
174
|
|
|
*/ |
|
175
|
|
|
public function getId() |
|
176
|
|
|
{ |
|
177
|
|
|
return $this->id; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Set id. |
|
182
|
|
|
* |
|
183
|
|
|
* @param int $id |
|
184
|
|
|
*/ |
|
185
|
|
|
public function setId($id) |
|
186
|
|
|
{ |
|
187
|
|
|
$this->id = $id; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Get category. |
|
192
|
|
|
* |
|
193
|
|
|
* @return string |
|
194
|
|
|
*/ |
|
195
|
|
|
public function getCategory() |
|
196
|
|
|
{ |
|
197
|
|
|
return $this->category; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* Set category. |
|
202
|
|
|
* |
|
203
|
|
|
* @param Category $category |
|
204
|
|
|
* |
|
205
|
|
|
* @return Article |
|
206
|
|
|
*/ |
|
207
|
|
|
public function setCategory(Category $category) |
|
208
|
|
|
{ |
|
209
|
|
|
$this->category = $category; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* Get the published at property. |
|
214
|
|
|
* |
|
215
|
|
|
* @return \DateTime |
|
216
|
|
|
*/ |
|
217
|
|
|
public function getPublishedAt() |
|
218
|
|
|
{ |
|
219
|
|
|
if ($this->status == PageStatus::PUBLISHED && $this->publishedAt === null) { |
|
220
|
|
|
$this->setPublishedAt($this->getCreatedAt()); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
return $this->publishedAt; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* Set publishedAt. |
|
228
|
|
|
* |
|
229
|
|
|
* @param \DateTime $publishedAt |
|
230
|
|
|
* |
|
231
|
|
|
* @return $this |
|
232
|
|
|
*/ |
|
233
|
|
|
public function setPublishedAt($publishedAt) |
|
234
|
|
|
{ |
|
235
|
|
|
$this->publishedAt = $publishedAt; |
|
|
|
|
|
|
236
|
|
|
|
|
237
|
|
|
return $this; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* Get deletedAt. |
|
242
|
|
|
* |
|
243
|
|
|
* @return \DateTime |
|
244
|
|
|
*/ |
|
245
|
|
|
public function getDeletedAt() |
|
246
|
|
|
{ |
|
247
|
|
|
return $this->deletedAt; |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* Set deletedAt. |
|
252
|
|
|
* |
|
253
|
|
|
* @param \DateTime $deletedAt |
|
254
|
|
|
* |
|
255
|
|
|
* @return $this |
|
256
|
|
|
*/ |
|
257
|
|
|
public function setDeletedAt($deletedAt) |
|
258
|
|
|
{ |
|
259
|
|
|
$this->deletedAt = $deletedAt; |
|
260
|
|
|
|
|
261
|
|
|
return $this; |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
/** |
|
265
|
|
|
* Get the blog. |
|
266
|
|
|
* |
|
267
|
|
|
* @return Blog |
|
268
|
|
|
*/ |
|
269
|
|
|
public function getBlog() |
|
270
|
|
|
{ |
|
271
|
|
|
return $this->blog; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* Set the blog. |
|
276
|
|
|
* |
|
277
|
|
|
* @param Blog $blog |
|
278
|
|
|
*/ |
|
279
|
|
|
public function setBlog(Blog $blog) |
|
280
|
|
|
{ |
|
281
|
|
|
$this->blog = $blog; |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
/** |
|
285
|
|
|
* Set tags. |
|
286
|
|
|
* |
|
287
|
|
|
* @param string $tags |
|
288
|
|
|
* |
|
289
|
|
|
* @return Article |
|
290
|
|
|
*/ |
|
291
|
|
|
public function setTags($tags) |
|
292
|
|
|
{ |
|
293
|
|
|
$this->tags = $tags; |
|
294
|
|
|
|
|
295
|
|
|
return $this; |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* Add tag. |
|
300
|
|
|
* |
|
301
|
|
|
* @param string $tag |
|
302
|
|
|
* |
|
303
|
|
|
* @return Article |
|
304
|
|
|
*/ |
|
305
|
|
|
public function addTag($tag) |
|
306
|
|
|
{ |
|
307
|
|
|
$this->tags[] = $tag; |
|
308
|
|
|
|
|
309
|
|
|
return $this; |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
/** |
|
313
|
|
|
* Remove tag. |
|
314
|
|
|
* |
|
315
|
|
|
* @param string $tag |
|
316
|
|
|
* |
|
317
|
|
|
* @return Article |
|
318
|
|
|
*/ |
|
319
|
|
|
public function removeTag($tag) |
|
320
|
|
|
{ |
|
321
|
|
|
$this->tags->removeElement($tag); |
|
|
|
|
|
|
322
|
|
|
|
|
323
|
|
|
return $this; |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
/** |
|
327
|
|
|
* Get tags. |
|
328
|
|
|
* |
|
329
|
|
|
* @return [Tag] |
|
|
|
|
|
|
330
|
|
|
*/ |
|
331
|
|
|
public function getTags() |
|
332
|
|
|
{ |
|
333
|
|
|
return $this->tags; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/** |
|
337
|
|
|
* Get businessEntity. |
|
338
|
|
|
* |
|
339
|
|
|
* @return Article |
|
340
|
|
|
*/ |
|
341
|
|
|
public function getBusinessEntity() |
|
342
|
|
|
{ |
|
343
|
|
|
return $this; |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* Set template. |
|
348
|
|
|
* |
|
349
|
|
|
* @param ArticleTemplate $template |
|
350
|
|
|
* |
|
351
|
|
|
* @return Article |
|
352
|
|
|
*/ |
|
353
|
|
|
public function setTemplate(ArticleTemplate $template) |
|
354
|
|
|
{ |
|
355
|
|
|
$this->template = $template; |
|
356
|
|
|
|
|
357
|
|
|
return $this; |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
/** |
|
361
|
|
|
* Get template. |
|
362
|
|
|
* |
|
363
|
|
|
* @return ArticleTemplate |
|
364
|
|
|
*/ |
|
365
|
|
|
public function getTemplate() |
|
366
|
|
|
{ |
|
367
|
|
|
return $this->template; |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
/** |
|
371
|
|
|
* Set status. |
|
372
|
|
|
* |
|
373
|
|
|
* @param status $status |
|
374
|
|
|
*/ |
|
375
|
|
|
public function setStatus($status) |
|
376
|
|
|
{ |
|
377
|
|
|
if ($status == PageStatus::PUBLISHED && $this->publishedAt === null) { |
|
378
|
|
|
$this->setPublishedAt(new \DateTime()); |
|
379
|
|
|
} |
|
380
|
|
|
$this->status = $status; |
|
381
|
|
|
} |
|
382
|
|
|
|
|
383
|
|
|
/** |
|
384
|
|
|
* Get status. |
|
385
|
|
|
* |
|
386
|
|
|
* @return status |
|
387
|
|
|
*/ |
|
388
|
|
|
public function getStatus() |
|
389
|
|
|
{ |
|
390
|
|
|
return $this->status; |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
|
|
/** |
|
394
|
|
|
* Get categoryTitle. |
|
395
|
|
|
* |
|
396
|
|
|
* @return string |
|
397
|
|
|
*/ |
|
398
|
|
|
public function getCategoryTitle() |
|
399
|
|
|
{ |
|
400
|
|
|
$this->categoryTitle = $this->category ? $this->category->getTitle() : null; |
|
401
|
|
|
|
|
402
|
|
|
return $this->categoryTitle; |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
/** |
|
406
|
|
|
* Get publishedAtString. |
|
407
|
|
|
* |
|
408
|
|
|
* @return string |
|
409
|
|
|
*/ |
|
410
|
|
|
public function getPublishedAtString() |
|
411
|
|
|
{ |
|
412
|
|
|
setlocale(LC_TIME, 'fr_FR'); |
|
413
|
|
|
|
|
414
|
|
|
if ($this->publishedAt) { |
|
415
|
|
|
return strftime('%d %B %Y', $this->publishedAt->getTimestamp()); |
|
416
|
|
|
} else { |
|
417
|
|
|
return ''; |
|
418
|
|
|
} |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
/** |
|
422
|
|
|
* Get author. |
|
423
|
|
|
* |
|
424
|
|
|
* @return string |
|
425
|
|
|
*/ |
|
426
|
|
|
public function getAuthor() |
|
427
|
|
|
{ |
|
428
|
|
|
return $this->author; |
|
429
|
|
|
} |
|
430
|
|
|
|
|
431
|
|
|
/** |
|
432
|
|
|
* Set author. |
|
433
|
|
|
* |
|
434
|
|
|
* @param string $author |
|
435
|
|
|
* |
|
436
|
|
|
* @return $this |
|
437
|
|
|
*/ |
|
438
|
|
|
public function setAuthor($author) |
|
439
|
|
|
{ |
|
440
|
|
|
$this->author = $author; |
|
441
|
|
|
|
|
442
|
|
|
return $this; |
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
|
|
public function getAuthorAvatar() |
|
446
|
|
|
{ |
|
447
|
|
|
$this->authorAvatar = 'http://www.gravatar.com/avatar/'.md5($this->author->getEmail()).'?s=70'; |
|
|
|
|
|
|
448
|
|
|
|
|
449
|
|
|
return $this->authorAvatar; |
|
450
|
|
|
} |
|
451
|
|
|
|
|
452
|
|
|
public function getAuthorFullname() |
|
453
|
|
|
{ |
|
454
|
|
|
$this->authorFullName = $this->author->getFullname(); |
|
|
|
|
|
|
455
|
|
|
|
|
456
|
|
|
return $this->authorFullName; |
|
457
|
|
|
} |
|
458
|
|
|
|
|
459
|
|
|
public function setLocale($locale) |
|
460
|
|
|
{ |
|
461
|
|
|
$this->locale = $locale; |
|
462
|
|
|
} |
|
463
|
|
|
|
|
464
|
|
|
/** |
|
465
|
|
|
* @return string |
|
466
|
|
|
*/ |
|
467
|
|
|
public function getLocale() |
|
468
|
|
|
{ |
|
469
|
|
|
return $this->locale; |
|
470
|
|
|
} |
|
471
|
|
|
|
|
472
|
|
|
public function getName() |
|
473
|
|
|
{ |
|
474
|
|
|
return PropertyAccess::createPropertyAccessor()->getValue($this->translate(), 'getName'); |
|
475
|
|
|
} |
|
476
|
|
|
|
|
477
|
|
|
public function setName($name, $locale = null) |
|
478
|
|
|
{ |
|
479
|
|
|
$this->translate($locale, false)->setName($name); |
|
|
|
|
|
|
480
|
|
|
$this->mergeNewTranslations(); |
|
481
|
|
|
} |
|
482
|
|
|
|
|
483
|
|
|
public function getSlug() |
|
484
|
|
|
{ |
|
485
|
|
|
return PropertyAccess::createPropertyAccessor()->getValue($this->translate(), 'getSlug'); |
|
486
|
|
|
} |
|
487
|
|
|
|
|
488
|
|
|
public function setSlug($slug, $locale = null) |
|
489
|
|
|
{ |
|
490
|
|
|
$this->translate($locale, false)->setSlug($slug); |
|
|
|
|
|
|
491
|
|
|
$this->mergeNewTranslations(); |
|
492
|
|
|
} |
|
493
|
|
|
|
|
494
|
|
|
public function getDescription() |
|
495
|
|
|
{ |
|
496
|
|
|
return PropertyAccess::createPropertyAccessor()->getValue($this->translate(), 'getDescription'); |
|
497
|
|
|
} |
|
498
|
|
|
|
|
499
|
|
|
public function setDescription($description, $locale = null) |
|
500
|
|
|
{ |
|
501
|
|
|
$this->translate($locale, false)->setDescription($description); |
|
|
|
|
|
|
502
|
|
|
$this->mergeNewTranslations(); |
|
503
|
|
|
} |
|
504
|
|
|
|
|
505
|
|
|
public function getImage() |
|
506
|
|
|
{ |
|
507
|
|
|
return PropertyAccess::createPropertyAccessor()->getValue($this->translate(), 'getImage'); |
|
508
|
|
|
} |
|
509
|
|
|
|
|
510
|
|
|
public function setImage($image, $locale = null) |
|
511
|
|
|
{ |
|
512
|
|
|
$this->translate($locale, false)->setImage($image); |
|
|
|
|
|
|
513
|
|
|
$this->mergeNewTranslations(); |
|
514
|
|
|
} |
|
515
|
|
|
} |
|
516
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.