1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace FSi\FixturesBundle\Entity; |
6
|
|
|
|
7
|
|
|
use DateTimeInterface; |
8
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
9
|
|
|
use Doctrine\Common\Collections\Collection; |
10
|
|
|
use Doctrine\ORM\Mapping as ORM; |
11
|
|
|
use FSi\Bundle\DoctrineExtensionsBundle\Validator\Constraints as UploadableAssert; |
12
|
|
|
use FSi\DoctrineExtensions\Uploadable\Mapping\Annotation as Uploadable; |
13
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @ORM\Entity |
17
|
|
|
* @ORM\Table(name="news") |
18
|
|
|
*/ |
19
|
|
|
class News |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @ORM\Column(type="integer") |
23
|
|
|
* @ORM\Id |
24
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
25
|
|
|
*/ |
26
|
|
|
protected $id; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @ORM\Column(type="string", length=100) |
30
|
|
|
*/ |
31
|
|
|
protected $title; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @ORM\Column(type="string", length=100, nullable=true) |
35
|
|
|
*/ |
36
|
|
|
protected $subtitle; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @ORM\Column(type="date", nullable=true) |
40
|
|
|
*/ |
41
|
|
|
protected $date; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @ORM\Column(type="boolean") |
45
|
|
|
*/ |
46
|
|
|
protected $visible = false; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @ORM\Column(type="datetime", name="created_at") |
50
|
|
|
*/ |
51
|
|
|
protected $createdAt; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @ORM\Column(type="text", name="creator_email") |
55
|
|
|
*/ |
56
|
|
|
protected $creatorEmail; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @ORM\Column(length=255, nullable=true) |
60
|
|
|
* @Uploadable\Uploadable(targetField="photo") |
61
|
|
|
*/ |
62
|
|
|
protected $photoKey; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var \FSi\DoctrineExtensions\Uploadable\File|\SplFileInfo |
66
|
|
|
* @UploadableAssert\Image() |
67
|
|
|
*/ |
68
|
|
|
protected $photo; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var Category[]|Collection |
72
|
|
|
* |
73
|
|
|
* @ORM\ManyToMany(targetEntity="Category") |
74
|
|
|
*/ |
75
|
|
|
protected $categories; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var Tag[]|Collection |
79
|
|
|
* |
80
|
|
|
* @Assert\Valid |
81
|
|
|
* @ORM\OneToMany(targetEntity="Tag", mappedBy="news", cascade={"persist"}, orphanRemoval=true) |
82
|
|
|
*/ |
83
|
|
|
protected $tags; |
84
|
|
|
|
85
|
|
|
public function __construct() |
86
|
|
|
{ |
87
|
|
|
$this->categories = new ArrayCollection(); |
88
|
|
|
$this->tags = new ArrayCollection(); |
89
|
|
|
$this->comments = new ArrayCollection(); |
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function getId(): ?int |
93
|
|
|
{ |
94
|
|
|
return $this->id; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function setCreatedAt(DateTimeInterface $createdAt): void |
98
|
|
|
{ |
99
|
|
|
$this->createdAt = $createdAt; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function getCreatedAt(): ?DateTimeInterface |
103
|
|
|
{ |
104
|
|
|
return $this->createdAt; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function setCreatorEmail(?string $creatorEmail): void |
108
|
|
|
{ |
109
|
|
|
$this->creatorEmail = $creatorEmail; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function getCreatorEmail(): ?string |
113
|
|
|
{ |
114
|
|
|
return $this->creatorEmail; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function setTitle(?string $title): void |
118
|
|
|
{ |
119
|
|
|
$this->title = $title; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function getTitle(): ?string |
123
|
|
|
{ |
124
|
|
|
return $this->title; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function setSubtitle(?string $subtitle): void |
128
|
|
|
{ |
129
|
|
|
$this->subtitle = $subtitle; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function getSubtitle(): ?string |
133
|
|
|
{ |
134
|
|
|
return $this->subtitle; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function setDate(?DateTimeInterface $date): void |
138
|
|
|
{ |
139
|
|
|
$this->date = $date; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function getDate(): ?DateTimeInterface |
143
|
|
|
{ |
144
|
|
|
return $this->date; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function setVisible(bool $visible): void |
148
|
|
|
{ |
149
|
|
|
$this->visible = $visible; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function isVisible(): bool |
153
|
|
|
{ |
154
|
|
|
return $this->visible; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function getPhotoKey(): ?string |
158
|
|
|
{ |
159
|
|
|
return $this->photoKey; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function setPhotoKey(?string $photoKey): void |
163
|
|
|
{ |
164
|
|
|
$this->photoKey = $photoKey; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @return \FSi\DoctrineExtensions\Uploadable\File|\SplFileInfo |
169
|
|
|
*/ |
170
|
|
|
public function getPhoto() |
171
|
|
|
{ |
172
|
|
|
return $this->photo; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @param \FSi\DoctrineExtensions\Uploadable\File|\SplFileInfo $photo |
177
|
|
|
*/ |
178
|
|
|
public function setPhoto($photo): void |
179
|
|
|
{ |
180
|
|
|
$this->photo = $photo; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function addCategory(Category $category): void |
184
|
|
|
{ |
185
|
|
|
$this->categories->add($category); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function removeCategory(Category $category): void |
189
|
|
|
{ |
190
|
|
|
$this->categories->removeElement($category); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @return Category[] |
195
|
|
|
*/ |
196
|
|
|
public function getCategories(): array |
197
|
|
|
{ |
198
|
|
|
return $this->categories->toArray(); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @return Tag[]|Collection |
203
|
|
|
*/ |
204
|
|
|
public function getTags(): Collection |
205
|
|
|
{ |
206
|
|
|
return $this->tags; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
public function addTag(Tag $tag): void |
210
|
|
|
{ |
211
|
|
|
if (!$this->tags->contains($tag)) { |
212
|
|
|
$tag->setNews($this); |
213
|
|
|
$this->tags->add($tag); |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
public function removeTag(Tag $tag): void |
218
|
|
|
{ |
219
|
|
|
$tag->setNews(null); |
220
|
|
|
$this->tags->removeElement($tag); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
public function setTags(array $tags): void |
224
|
|
|
{ |
225
|
|
|
$this->tags = new ArrayCollection($tags); |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: