1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* (c) Lukasz D. Tulikowski <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace App\Entity; |
13
|
|
|
|
14
|
|
|
use App\Traits\IdColumnTrait; |
15
|
|
|
use App\Traits\TimeAwareTrait; |
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
17
|
|
|
use Doctrine\Common\Collections\Collection; |
18
|
|
|
use Doctrine\ORM\Mapping as ORM; |
19
|
|
|
use JMS\Serializer\Annotation as JMS; |
20
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\MovieRepository") |
24
|
|
|
* |
25
|
|
|
* @JMS\ExclusionPolicy("ALL") |
26
|
|
|
*/ |
27
|
|
|
class Movie |
28
|
|
|
{ |
29
|
|
|
use IdColumnTrait; |
30
|
|
|
use TimeAwareTrait; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var int |
34
|
|
|
* |
35
|
|
|
* @ORM\Column(type="integer") |
36
|
|
|
* |
37
|
|
|
* @Assert\NotBlank |
38
|
|
|
* |
39
|
|
|
* @JMS\Expose |
40
|
|
|
*/ |
41
|
|
|
protected $duration; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string |
45
|
|
|
* |
46
|
|
|
* @ORM\Column(type="string") |
47
|
|
|
* |
48
|
|
|
* @Assert\NotBlank |
49
|
|
|
* |
50
|
|
|
* @JMS\Expose |
51
|
|
|
*/ |
52
|
|
|
protected $title; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var string |
56
|
|
|
* |
57
|
|
|
* @ORM\Column(type="text") |
58
|
|
|
* |
59
|
|
|
* @Assert\NotBlank |
60
|
|
|
*/ |
61
|
|
|
protected $description; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var string |
65
|
|
|
* |
66
|
|
|
* @ORM\Column(type="text") |
67
|
|
|
* |
68
|
|
|
* @Assert\NotBlank |
69
|
|
|
* |
70
|
|
|
* @JMS\Expose |
71
|
|
|
*/ |
72
|
|
|
protected $director; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var \DateTimeInterface |
76
|
|
|
* |
77
|
|
|
* @ORM\Column(type="datetime") |
78
|
|
|
* |
79
|
|
|
* @Assert\NotBlank |
80
|
|
|
* |
81
|
|
|
* @JMS\Expose |
82
|
|
|
*/ |
83
|
|
|
protected $publicationDate; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @var ArrayCollection|Review[] |
87
|
|
|
* |
88
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Review", mappedBy="movie") |
89
|
|
|
* |
90
|
|
|
* @JMS\Expose |
91
|
|
|
* @JMS\Groups("reviews") |
92
|
|
|
*/ |
93
|
|
|
protected $reviews; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @var ArrayCollection|User[] |
97
|
|
|
* |
98
|
|
|
* @ORM\ManyToMany(targetEntity="App\Entity\User", mappedBy="movies") |
99
|
|
|
* |
100
|
|
|
* @JMS\Expose |
101
|
|
|
* @JMS\Groups("audience") |
102
|
|
|
*/ |
103
|
|
|
protected $audience; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Movie constructor. |
107
|
|
|
*/ |
108
|
2 |
|
public function __construct() |
109
|
|
|
{ |
110
|
2 |
|
$this->reviews = new ArrayCollection(); |
111
|
2 |
|
$this->audience = new ArrayCollection(); |
112
|
2 |
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return int|null |
116
|
|
|
*/ |
117
|
3 |
|
public function getDuration(): ?int |
118
|
|
|
{ |
119
|
3 |
|
return $this->duration; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param int $duration |
124
|
|
|
* |
125
|
|
|
* @return Movie |
126
|
|
|
*/ |
127
|
3 |
|
public function setDuration(int $duration): self |
128
|
|
|
{ |
129
|
3 |
|
$this->duration = $duration; |
130
|
|
|
|
131
|
3 |
|
return $this; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return string|null |
136
|
|
|
*/ |
137
|
3 |
|
public function getTitle(): ?string |
138
|
|
|
{ |
139
|
3 |
|
return $this->title; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param string|null $title |
144
|
|
|
* |
145
|
|
|
* @return Movie |
146
|
|
|
*/ |
147
|
2 |
|
public function setTitle(string $title): self |
148
|
|
|
{ |
149
|
2 |
|
$this->title = $title; |
150
|
|
|
|
151
|
2 |
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return string|null |
156
|
|
|
*/ |
157
|
3 |
|
public function getDescription(): ?string |
158
|
|
|
{ |
159
|
3 |
|
return $this->description; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param string $description |
164
|
|
|
* |
165
|
|
|
* @return Movie |
166
|
|
|
*/ |
167
|
2 |
|
public function setDescription(string $description): self |
168
|
|
|
{ |
169
|
2 |
|
$this->description = $description; |
170
|
|
|
|
171
|
2 |
|
return $this; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @return string|null |
176
|
|
|
*/ |
177
|
3 |
|
public function getDirector(): ?string |
178
|
|
|
{ |
179
|
3 |
|
return $this->director; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @param string $director |
184
|
|
|
* |
185
|
|
|
* @return Movie |
186
|
|
|
*/ |
187
|
2 |
|
public function setDirector(string $director): self |
188
|
|
|
{ |
189
|
2 |
|
$this->director = $director; |
190
|
|
|
|
191
|
2 |
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @return \DateTimeInterface|null |
196
|
|
|
*/ |
197
|
3 |
|
public function getPublicationDate(): ?\DateTimeInterface |
198
|
|
|
{ |
199
|
3 |
|
return $this->publicationDate; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @param \DateTimeInterface $publicationDate |
204
|
|
|
* |
205
|
|
|
* @return Movie |
206
|
|
|
*/ |
207
|
2 |
|
public function setPublicationDate(?\DateTimeInterface $publicationDate): self |
208
|
|
|
{ |
209
|
2 |
|
$this->publicationDate = $publicationDate; |
210
|
|
|
|
211
|
2 |
|
return $this; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @return Collection|Review[] |
216
|
|
|
*/ |
217
|
|
|
public function getReviews(): Collection |
218
|
|
|
{ |
219
|
|
|
return $this->reviews; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @param Review $review |
224
|
|
|
* |
225
|
|
|
* @return Movie |
226
|
|
|
*/ |
227
|
|
|
public function addReview(Review $review): self |
228
|
|
|
{ |
229
|
|
|
if (!$this->reviews->contains($review)) { |
230
|
|
|
$this->reviews[] = $review; |
231
|
|
|
$review->setMovie($this); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
return $this; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @param Review $review |
239
|
|
|
* |
240
|
|
|
* @return Movie |
241
|
|
|
*/ |
242
|
|
|
public function removeReview(Review $review): self |
243
|
|
|
{ |
244
|
|
|
if ($this->reviews->contains($review)) { |
245
|
|
|
$this->reviews->removeElement($review); |
246
|
|
|
// set the owning side to null (unless already changed) |
247
|
|
|
if ($review->getMovie() === $this) { |
248
|
|
|
$review->setMovie(null); |
249
|
|
|
} |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
return $this; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* @return Collection|User[] |
257
|
|
|
*/ |
258
|
|
|
public function getAudience(): Collection |
259
|
|
|
{ |
260
|
|
|
return $this->audience; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @param User $audience |
265
|
|
|
* |
266
|
|
|
* @return Movie |
267
|
|
|
*/ |
268
|
|
|
public function addAudience(User $audience): self |
269
|
|
|
{ |
270
|
|
|
if (!$this->audience->contains($audience)) { |
271
|
|
|
$this->audience[] = $audience; |
272
|
|
|
$audience->addMovie($this); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
return $this; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @param User $audience |
280
|
|
|
* |
281
|
|
|
* @return Movie |
282
|
|
|
*/ |
283
|
|
|
public function removeAudience(User $audience): self |
284
|
|
|
{ |
285
|
|
|
if ($this->audience->contains($audience)) { |
286
|
|
|
$this->audience->removeElement($audience); |
287
|
|
|
$audience->removeMovie($this); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
return $this; |
291
|
|
|
} |
292
|
|
|
} |
293
|
|
|
|