Completed
Pull Request — master (#8)
by Nicolas
28:01
created

Post::getPublishedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Smart\ContentBundle\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Smart\ContentBundle\Entity\Traits\ContentTrait;
8
use Smart\ContentBundle\Entity\Traits\ImageTrait;
9
use Smart\ContentBundle\Entity\Traits\SeoTrait;
10
use Symfony\Component\HttpFoundation\File\File;
11
use Symfony\Component\HttpFoundation\File\UploadedFile;
12
use Vich\UploaderBundle\Mapping\Annotation as Vich;
13
use Symfony\Component\Validator\Constraints as Assert;
14
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
15
16
/**
17
 * @ORM\Entity(repositoryClass="Smart\ContentBundle\Entity\Repository\PostRepository")
18
 * @ORM\Table(name="smart_content_post")
19
 *
20
 * @UniqueEntity({"url"})
21
 *
22
 * @Vich\Uploadable
23
 */
24
class Post
25
{
26
    use ContentTrait;
27
    use SeoTrait;
28
    use ImageTrait;
29
30
    /**
31
     * @var int
32
     *
33
     * @ORM\Id
34
     * @ORM\Column(name="id", type="integer")
35
     * @ORM\GeneratedValue(strategy="AUTO")
36
     */
37
    protected $id;
38
    
39
    /**
40
     * @var \DateTime
41
     *
42
     * @ORM\Column(name="published_at", type="datetime", nullable=true)
43
     */
44
    protected $publishedAt;
45
46
    /**
47
     * @var Author
48
     *
49
     * @ORM\ManyToOne(targetEntity="Smart\ContentBundle\Entity\Author")
50
     */
51
    protected $author;
52
53
    /**
54
     * @var Category
55
     *
56
     * @ORM\ManyToOne(targetEntity="Smart\ContentBundle\Entity\Category", inversedBy="posts")
57
     * @Assert\NotNull()
58
     */
59
    protected $category;
60
61
    /**
62
     * @var ArrayCollection|Tag[]
63
     *
64
     * @ORM\ManyToMany(targetEntity="Smart\ContentBundle\Entity\Tag", inversedBy="posts")
65
     */
66
    protected $tags;
67
68 1
    public function __construct()
69
    {
70 1
        $this->publishedAt      = new \DateTime();
71 1
        $this->tags             = new ArrayCollection();
72 1
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function __toString()
78
    {
79
        return (string) $this->getTitle();
80
    }
81
82
    /**
83
     * @return \DateTime
84
     */
85
    public function getPublishedAt()
86
    {
87
        return $this->publishedAt;
88
    }
89
90
    /**
91
     * @param \DateTime $publishedAt
92
     *
93
     * @return $this
94
     */
95
    public function setPublishedAt($publishedAt)
96
    {
97
        $this->publishedAt = $publishedAt;
98
99
        return $this;
100
    }
101
102
    /**
103
     * @return Author
104
     */
105
    public function getAuthor()
106
    {
107
        return $this->author;
108
    }
109
110
    /**
111
     * @param Author $author
112
     *
113
     * @return $this
114
     */
115 1
    public function setAuthor($author)
116
    {
117 1
        $this->author = $author;
118
119 1
        return $this;
120
    }
121
122
    /**
123
     * @return Category
124
     */
125
    public function getCategory()
126
    {
127
        return $this->category;
128
    }
129
130
    /**
131
     * @return string
132
     */
133
    public function getCategoryUrl()
134
    {
135
        return $this->getCategory()->getUrl();
136
    }
137
138
    /**
139
     * @param Category $category
140
     *
141
     * @return $this
142
     */
143 1
    public function setCategory($category)
144
    {
145 1
        $this->category = $category;
146
147 1
        return $this;
148
    }
149
150
    /**
151
     * @return ArrayCollection|Tag[]
152
     */
153
    public function getTags()
154
    {
155
        return $this->tags;
156
    }
157
158
    /**
159
     * @param ArrayCollection|Tag[] $tags
160
     *
161
     * @return $this
162
     */
163 1
    public function setTags($tags)
164
    {
165 1
        foreach ($tags as $tag) {
166 1
            $this->addTag($tag);
167
        }
168
169 1
        return $this;
170
    }
171
172
    /**
173
     * @param Tag $tag
174
     *
175
     * @return $this
176
     */
177 1
    public function addTag($tag)
178
    {
179 1
        if (!$this->tags->contains($tag)) {
180 1
            $this->tags->add($tag);
181
        }
182
183 1
        return $this;
184
    }
185
}
186