Completed
Push — master ( 2c86a7...690ed0 )
by
unknown
36:26 queued 28:50
created

Article::setCategory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 1
cc 1
eloc 2
nc 1
nop 1
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;
0 ignored issues
show
Unused Code introduced by
The property $name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
43
44
    /**
45
     * @deprecated
46
     * @ORM\Column(name="slug", type="string", length=255, nullable=true)
47
     */
48
    private $slug;
0 ignored issues
show
Unused Code introduced by
The property $slug is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
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;
0 ignored issues
show
Unused Code introduced by
The property $description is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
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;
0 ignored issues
show
Unused Code introduced by
The property $image is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
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;
0 ignored issues
show
Unused Code introduced by
The property $publishedAtString is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
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;
0 ignored issues
show
Documentation Bug introduced by
It seems like $publishedAt of type object<DateTime> is incompatible with the declared type object<Victoire\Bundle\B...Bundle\Entity\datetime> of property $publishedAt.

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..

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method removeElement cannot be called on $this->tags (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
322
323
        return $this;
324
    }
325
326
    /**
327
     * Get tags.
328
     *
329
     * @return [Tag]
0 ignored issues
show
Documentation introduced by
The doc-type [Tag] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
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';
0 ignored issues
show
Bug introduced by
The method getEmail cannot be called on $this->author (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
448
449
        return $this->authorAvatar;
450
    }
451
452
    public function getAuthorFullname()
453
    {
454
        $this->authorFullName = $this->author->getFullname();
0 ignored issues
show
Bug introduced by
The method getFullname cannot be called on $this->author (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
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);
0 ignored issues
show
Bug introduced by
It seems like setName() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
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);
0 ignored issues
show
Bug introduced by
It seems like setSlug() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
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);
0 ignored issues
show
Bug introduced by
It seems like setDescription() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
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);
0 ignored issues
show
Bug introduced by
It seems like setImage() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
513
        $this->mergeNewTranslations();
514
    }
515
}
516