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 int |
84
|
|
|
*/ |
85
|
|
|
public function getId() |
86
|
|
|
{ |
87
|
|
|
return $this->id; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return \DateTime|null |
92
|
|
|
*/ |
93
|
|
|
public function getPublishedAt() |
94
|
|
|
{ |
95
|
|
|
return $this->publishedAt; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param \DateTime $publishedAt |
100
|
|
|
* |
101
|
|
|
* @return $this |
102
|
|
|
*/ |
103
|
|
|
public function setPublishedAt($publishedAt) |
104
|
|
|
{ |
105
|
|
|
$this->publishedAt = $publishedAt; |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return Author |
112
|
|
|
*/ |
113
|
|
|
public function getAuthor() |
114
|
|
|
{ |
115
|
|
|
return $this->author; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param Author $author |
120
|
|
|
* |
121
|
|
|
* @return $this |
122
|
|
|
*/ |
123
|
1 |
|
public function setAuthor($author) |
124
|
|
|
{ |
125
|
1 |
|
$this->author = $author; |
126
|
|
|
|
127
|
1 |
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return Category |
132
|
|
|
*/ |
133
|
|
|
public function getCategory() |
134
|
|
|
{ |
135
|
|
|
return $this->category; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return string |
140
|
|
|
*/ |
141
|
|
|
public function getCategoryUrl() |
142
|
|
|
{ |
143
|
|
|
return $this->getCategory()->getUrl(); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param Category $category |
148
|
|
|
* |
149
|
|
|
* @return $this |
150
|
|
|
*/ |
151
|
1 |
|
public function setCategory($category) |
152
|
|
|
{ |
153
|
1 |
|
$this->category = $category; |
154
|
|
|
|
155
|
1 |
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @return ArrayCollection|Tag[] |
160
|
|
|
*/ |
161
|
|
|
public function getTags() |
162
|
|
|
{ |
163
|
|
|
return $this->tags; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param ArrayCollection|Tag[] $tags |
168
|
|
|
* |
169
|
|
|
* @return $this |
170
|
|
|
*/ |
171
|
1 |
|
public function setTags($tags) |
172
|
|
|
{ |
173
|
1 |
|
foreach ($tags as $tag) { |
174
|
1 |
|
$this->addTag($tag); |
175
|
|
|
} |
176
|
|
|
|
177
|
1 |
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param Tag $tag |
182
|
|
|
* |
183
|
|
|
* @return $this |
184
|
|
|
*/ |
185
|
1 |
|
public function addTag($tag) |
186
|
|
|
{ |
187
|
1 |
|
if (!$this->tags->contains($tag)) { |
188
|
1 |
|
$this->tags->add($tag); |
189
|
|
|
} |
190
|
|
|
|
191
|
1 |
|
return $this; |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|