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->name; |
|
|
|
|
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
|
|
|
* Get the published at property. |
202
|
|
|
* |
203
|
|
|
* @return \DateTime |
204
|
|
|
*/ |
205
|
|
|
public function getPublishedAt() |
206
|
|
|
{ |
207
|
|
|
if ($this->status == PageStatus::PUBLISHED && $this->publishedAt === null) { |
208
|
|
|
$this->setPublishedAt($this->getCreatedAt()); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
return $this->publishedAt; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Set publishedAt. |
216
|
|
|
* |
217
|
|
|
* @param \DateTime $publishedAt |
218
|
|
|
* |
219
|
|
|
* @return $this |
220
|
|
|
*/ |
221
|
|
|
public function setPublishedAt($publishedAt) |
222
|
|
|
{ |
223
|
|
|
$this->publishedAt = $publishedAt; |
|
|
|
|
224
|
|
|
|
225
|
|
|
return $this; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Get deletedAt. |
230
|
|
|
* |
231
|
|
|
* @return \DateTime |
232
|
|
|
*/ |
233
|
|
|
public function getDeletedAt() |
234
|
|
|
{ |
235
|
|
|
return $this->deletedAt; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Set deletedAt. |
240
|
|
|
* |
241
|
|
|
* @param \DateTime $deletedAt |
242
|
|
|
* |
243
|
|
|
* @return $this |
244
|
|
|
*/ |
245
|
|
|
public function setDeletedAt($deletedAt) |
246
|
|
|
{ |
247
|
|
|
$this->deletedAt = $deletedAt; |
248
|
|
|
|
249
|
|
|
return $this; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Get the blog. |
254
|
|
|
* |
255
|
|
|
* @return Blog |
256
|
|
|
*/ |
257
|
|
|
public function getBlog() |
258
|
|
|
{ |
259
|
|
|
return $this->blog; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Set the blog. |
264
|
|
|
* |
265
|
|
|
* @param Blog $blog |
266
|
|
|
*/ |
267
|
|
|
public function setBlog(Blog $blog) |
268
|
|
|
{ |
269
|
|
|
$this->blog = $blog; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Set tags. |
274
|
|
|
* |
275
|
|
|
* @param string $tags |
276
|
|
|
* |
277
|
|
|
* @return Article |
278
|
|
|
*/ |
279
|
|
|
public function setTags($tags) |
280
|
|
|
{ |
281
|
|
|
$this->tags = $tags; |
282
|
|
|
|
283
|
|
|
return $this; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Add tag. |
288
|
|
|
* |
289
|
|
|
* @param string $tag |
290
|
|
|
* |
291
|
|
|
* @return Article |
292
|
|
|
*/ |
293
|
|
|
public function addTag($tag) |
294
|
|
|
{ |
295
|
|
|
$this->tags[] = $tag; |
296
|
|
|
|
297
|
|
|
return $this; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* Remove tag. |
302
|
|
|
* |
303
|
|
|
* @param string $tag |
304
|
|
|
* |
305
|
|
|
* @return Article |
306
|
|
|
*/ |
307
|
|
|
public function removeTag($tag) |
308
|
|
|
{ |
309
|
|
|
$this->tags->removeElement($tag); |
|
|
|
|
310
|
|
|
|
311
|
|
|
return $this; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* Get tags. |
316
|
|
|
* |
317
|
|
|
* @return [Tag] |
|
|
|
|
318
|
|
|
*/ |
319
|
|
|
public function getTags() |
320
|
|
|
{ |
321
|
|
|
return $this->tags; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Get businessEntity. |
326
|
|
|
* |
327
|
|
|
* @return Article |
328
|
|
|
*/ |
329
|
|
|
public function getBusinessEntity() |
330
|
|
|
{ |
331
|
|
|
return $this; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* Set template. |
336
|
|
|
* |
337
|
|
|
* @param ArticleTemplate $template |
338
|
|
|
* |
339
|
|
|
* @return Article |
340
|
|
|
*/ |
341
|
|
|
public function setTemplate(ArticleTemplate $template) |
342
|
|
|
{ |
343
|
|
|
$this->template = $template; |
344
|
|
|
|
345
|
|
|
return $this; |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* Get template. |
350
|
|
|
* |
351
|
|
|
* @return ArticleTemplate |
352
|
|
|
*/ |
353
|
|
|
public function getTemplate() |
354
|
|
|
{ |
355
|
|
|
return $this->template; |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* Set status. |
360
|
|
|
* |
361
|
|
|
* @param status $status |
362
|
|
|
*/ |
363
|
|
|
public function setStatus($status) |
364
|
|
|
{ |
365
|
|
|
if ($status == PageStatus::PUBLISHED && $this->publishedAt === null) { |
366
|
|
|
$this->setPublishedAt(new \DateTime()); |
367
|
|
|
} |
368
|
|
|
$this->status = $status; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* Get status. |
373
|
|
|
* |
374
|
|
|
* @return status |
375
|
|
|
*/ |
376
|
|
|
public function getStatus() |
377
|
|
|
{ |
378
|
|
|
return $this->status; |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* Get categoryTitle. |
383
|
|
|
* |
384
|
|
|
* @return string |
385
|
|
|
*/ |
386
|
|
|
public function getCategoryTitle() |
387
|
|
|
{ |
388
|
|
|
$this->categoryTitle = $this->category ? $this->category->getTitle() : null; |
389
|
|
|
|
390
|
|
|
return $this->categoryTitle; |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* Get publishedAtString. |
395
|
|
|
* |
396
|
|
|
* @return string |
397
|
|
|
*/ |
398
|
|
|
public function getPublishedAtString() |
399
|
|
|
{ |
400
|
|
|
setlocale(LC_TIME, 'fr_FR'); |
401
|
|
|
|
402
|
|
|
if ($this->publishedAt) { |
403
|
|
|
return strftime('%d %B %Y', $this->publishedAt->getTimestamp()); |
404
|
|
|
} else { |
405
|
|
|
return ''; |
406
|
|
|
} |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* Get author. |
411
|
|
|
* |
412
|
|
|
* @return string |
413
|
|
|
*/ |
414
|
|
|
public function getAuthor() |
415
|
|
|
{ |
416
|
|
|
return $this->author; |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
/** |
420
|
|
|
* Set author. |
421
|
|
|
* |
422
|
|
|
* @param string $author |
423
|
|
|
* |
424
|
|
|
* @return $this |
425
|
|
|
*/ |
426
|
|
|
public function setAuthor($author) |
427
|
|
|
{ |
428
|
|
|
$this->author = $author; |
429
|
|
|
|
430
|
|
|
return $this; |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
public function getAuthorAvatar() |
434
|
|
|
{ |
435
|
|
|
$this->authorAvatar = 'http://www.gravatar.com/avatar/'.md5($this->author->getEmail()).'?s=70'; |
|
|
|
|
436
|
|
|
|
437
|
|
|
return $this->authorAvatar; |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
public function getAuthorFullname() |
441
|
|
|
{ |
442
|
|
|
$this->authorFullName = $this->author->getFullname(); |
|
|
|
|
443
|
|
|
|
444
|
|
|
return $this->authorFullName; |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
public function setLocale($locale) |
448
|
|
|
{ |
449
|
|
|
$this->locale = $locale; |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
/** |
453
|
|
|
* @return string |
454
|
|
|
*/ |
455
|
|
|
public function getLocale() |
456
|
|
|
{ |
457
|
|
|
return $this->locale; |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
public function getName() |
461
|
|
|
{ |
462
|
|
|
return PropertyAccess::createPropertyAccessor()->getValue($this->translate(), 'getName'); |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
public function setName($name, $locale = null) |
466
|
|
|
{ |
467
|
|
|
$this->translate($locale, false)->setName($name); |
|
|
|
|
468
|
|
|
$this->mergeNewTranslations(); |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
public function getSlug() |
472
|
|
|
{ |
473
|
|
|
return PropertyAccess::createPropertyAccessor()->getValue($this->translate(), 'getSlug'); |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
public function setSlug($slug, $locale = null) |
477
|
|
|
{ |
478
|
|
|
$this->translate($locale, false)->setSlug($slug); |
|
|
|
|
479
|
|
|
$this->mergeNewTranslations(); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
public function getDescription() |
483
|
|
|
{ |
484
|
|
|
return PropertyAccess::createPropertyAccessor()->getValue($this->translate(), 'getDescription'); |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
public function setDescription($description, $locale = null) |
488
|
|
|
{ |
489
|
|
|
$this->translate($locale, false)->setDescription($description); |
|
|
|
|
490
|
|
|
$this->mergeNewTranslations(); |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
public function getImage() |
494
|
|
|
{ |
495
|
|
|
return PropertyAccess::createPropertyAccessor()->getValue($this->translate(), 'getImage'); |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
public function setImage($image, $locale = null) |
499
|
|
|
{ |
500
|
|
|
$this->translate($locale, false)->setImage($image); |
|
|
|
|
501
|
|
|
$this->mergeNewTranslations(); |
502
|
|
|
} |
503
|
|
|
} |
504
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.