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\Groups({"reviews"}) |
91
|
|
|
*/ |
92
|
|
|
protected $reviews; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @var ArrayCollection|User[] |
96
|
|
|
* |
97
|
|
|
* @ORM\ManyToMany(targetEntity="App\Entity\User", mappedBy="movies") |
98
|
|
|
* |
99
|
|
|
* @JMS\Groups({"audience"}) |
100
|
|
|
*/ |
101
|
|
|
protected $audience; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Movie constructor. |
105
|
|
|
*/ |
106
|
|
|
public function __construct() |
107
|
|
|
{ |
108
|
|
|
$this->reviews = new ArrayCollection(); |
109
|
|
|
$this->audience = new ArrayCollection(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return int|null |
114
|
|
|
*/ |
115
|
|
|
public function getDuration(): ?int |
116
|
|
|
{ |
117
|
|
|
return $this->duration; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param int $duration |
122
|
|
|
* |
123
|
|
|
* @return Movie |
124
|
|
|
*/ |
125
|
|
|
public function setDuration(int $duration): self |
126
|
|
|
{ |
127
|
|
|
$this->duration = $duration; |
128
|
|
|
|
129
|
|
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return string|null |
134
|
|
|
*/ |
135
|
|
|
public function getTitle(): ?string |
136
|
|
|
{ |
137
|
|
|
return $this->title; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param string|null $title |
142
|
|
|
* |
143
|
|
|
* @return Movie |
144
|
|
|
*/ |
145
|
|
|
public function setTitle(string $title): self |
146
|
|
|
{ |
147
|
|
|
$this->title = $title; |
148
|
|
|
|
149
|
|
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return string|null |
154
|
|
|
*/ |
155
|
|
|
public function getDescription(): ?string |
156
|
|
|
{ |
157
|
|
|
return $this->description; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param string $description |
162
|
|
|
* |
163
|
|
|
* @return Movie |
164
|
|
|
*/ |
165
|
|
|
public function setDescription(string $description): self |
166
|
|
|
{ |
167
|
|
|
$this->description = $description; |
168
|
|
|
|
169
|
|
|
return $this; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return string|null |
174
|
|
|
*/ |
175
|
|
|
public function getDirector(): ?string |
176
|
|
|
{ |
177
|
|
|
return $this->director; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param string $director |
182
|
|
|
* |
183
|
|
|
* @return Movie |
184
|
|
|
*/ |
185
|
|
|
public function setDirector(string $director): self |
186
|
|
|
{ |
187
|
|
|
$this->director = $director; |
188
|
|
|
|
189
|
|
|
return $this; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @return \DateTimeInterface|null |
194
|
|
|
*/ |
195
|
|
|
public function getPublicationDate(): ?\DateTimeInterface |
196
|
|
|
{ |
197
|
|
|
return $this->publicationDate; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param \DateTimeInterface $publicationDate |
202
|
|
|
* |
203
|
|
|
* @return Movie |
204
|
|
|
*/ |
205
|
|
|
public function setPublicationDate(?\DateTimeInterface $publicationDate): self |
206
|
|
|
{ |
207
|
|
|
$this->publicationDate = $publicationDate; |
208
|
|
|
|
209
|
|
|
return $this; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @return Collection|Review[] |
214
|
|
|
*/ |
215
|
|
|
public function getReviews(): Collection |
216
|
|
|
{ |
217
|
|
|
return $this->reviews; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @param Review $review |
222
|
|
|
* |
223
|
|
|
* @return Movie |
224
|
|
|
*/ |
225
|
|
|
public function addReview(Review $review): self |
226
|
|
|
{ |
227
|
|
|
if (!$this->reviews->contains($review)) { |
228
|
|
|
$this->reviews[] = $review; |
229
|
|
|
$review->setMovie($this); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
return $this; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @param Review $review |
237
|
|
|
* |
238
|
|
|
* @return Movie |
239
|
|
|
*/ |
240
|
|
|
public function removeReview(Review $review): self |
241
|
|
|
{ |
242
|
|
|
if ($this->reviews->contains($review)) { |
243
|
|
|
$this->reviews->removeElement($review); |
244
|
|
|
// set the owning side to null (unless already changed) |
245
|
|
|
if ($review->getMovie() === $this) { |
246
|
|
|
$review->setMovie(null); |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
return $this; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @return Collection|User[] |
255
|
|
|
*/ |
256
|
|
|
public function getAudience(): Collection |
257
|
|
|
{ |
258
|
|
|
return $this->audience; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* @param User $audience |
263
|
|
|
* |
264
|
|
|
* @return Movie |
265
|
|
|
*/ |
266
|
|
|
public function addAudience(User $audience): self |
267
|
|
|
{ |
268
|
|
|
if (!$this->audience->contains($audience)) { |
269
|
|
|
$this->audience[] = $audience; |
270
|
|
|
$audience->addMovie($this); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
return $this; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @param User $audience |
278
|
|
|
* |
279
|
|
|
* @return Movie |
280
|
|
|
*/ |
281
|
|
|
public function removeAudience(User $audience): self |
282
|
|
|
{ |
283
|
|
|
if ($this->audience->contains($audience)) { |
284
|
|
|
$this->audience->removeElement($audience); |
285
|
|
|
$audience->removeMovie($this); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
return $this; |
289
|
|
|
} |
290
|
|
|
} |
291
|
|
|
|