1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace App\Movies\Entity; |
6
|
|
|
|
7
|
|
|
use App\Actors\Entity\Actor; |
8
|
|
|
use App\Genres\Entity\Genre; |
9
|
|
|
use App\Guests\Entity\GuestWatchedMovie; |
10
|
|
|
use App\Movies\DTO\MovieDTO; |
11
|
|
|
use App\Translation\TranslatableInterface; |
12
|
|
|
use App\Translation\TranslatableTrait; |
13
|
|
|
use App\Users\Entity\User; |
14
|
|
|
use App\Users\Entity\UserInterestedMovie; |
15
|
|
|
use App\Users\Entity\UserWatchedMovie; |
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
17
|
|
|
use Doctrine\ORM\Mapping as ORM; |
18
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
19
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
20
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @ORM\Entity(repositoryClass="App\Movies\Repository\MovieRepository") |
24
|
|
|
* @ORM\Table(name="movies") |
25
|
|
|
* |
26
|
|
|
* @method MovieTranslations getTranslation(string $locale, bool $useFallbackLocale = true) |
27
|
|
|
* @UniqueEntity("tmdb.id") |
28
|
|
|
*/ |
29
|
|
|
class Movie implements TranslatableInterface |
30
|
|
|
{ |
31
|
|
|
use TranslatableTrait; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @ORM\Id() |
35
|
|
|
* @ORM\GeneratedValue() |
36
|
|
|
* @ORM\Column(type="integer") |
37
|
|
|
* @Groups({"list", "view"}) |
38
|
|
|
*/ |
39
|
|
|
private $id; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var MovieTranslations[]|ArrayCollection |
43
|
|
|
* @ORM\OneToMany(targetEntity="App\Movies\Entity\MovieTranslations", mappedBy="movie", cascade={"persist", "remove"}) |
44
|
|
|
* @Assert\Valid(traverse=true) |
45
|
|
|
* @Groups({"list", "view"}) |
46
|
|
|
*/ |
47
|
|
|
private $translations; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var Actor[]|ArrayCollection |
51
|
|
|
* @ORM\OneToMany(targetEntity="App\Movies\Entity\MovieActor", mappedBy="movie", cascade={"persist", "remove"}) |
52
|
|
|
* @Assert\Valid(traverse=true) |
53
|
|
|
* @Groups({"view"}) |
54
|
|
|
*/ |
55
|
|
|
private $actors; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var Genre[]|ArrayCollection |
59
|
|
|
* @ORM\ManyToMany(targetEntity="App\Genres\Entity\Genre") |
60
|
|
|
* @ORM\JoinTable(name="movies_genres", |
61
|
|
|
* joinColumns={@ORM\JoinColumn(name="movie_id", referencedColumnName="id")}, |
62
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="genre_id", referencedColumnName="id")} |
63
|
|
|
* ) |
64
|
|
|
* @ORM\JoinColumn(nullable=false) |
65
|
|
|
* @Assert\Valid(traverse=true) |
66
|
|
|
* @Groups({"list", "view"}) |
67
|
|
|
*/ |
68
|
|
|
private $genres; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @Groups({"list", "view"}) |
72
|
|
|
* @ORM\Column(type="string", length=100) |
73
|
|
|
*/ |
74
|
|
|
private $originalTitle; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @Groups({"list", "view"}) |
78
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
79
|
|
|
*/ |
80
|
|
|
private $originalPosterUrl; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @ORM\Embedded(class="App\Movies\Entity\MovieTMDB", columnPrefix="tmdb_") |
84
|
|
|
* @Assert\Valid(traverse=true) |
85
|
|
|
* @Groups({"list", "view"}) |
86
|
|
|
*/ |
87
|
|
|
private $tmdb; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @ORM\Column(type="string", length=20, nullable=true) |
91
|
|
|
* @Groups({"view"}) |
92
|
|
|
*/ |
93
|
|
|
private $imdbId; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @Groups({"view"}) |
97
|
|
|
* @ORM\Column(type="integer", nullable=true, options={"default": 0}) |
98
|
|
|
*/ |
99
|
|
|
private $runtime; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @Groups({"view"}) |
103
|
|
|
* @ORM\Column(type="integer", nullable=true, options={"default": 0}) |
104
|
|
|
*/ |
105
|
|
|
private $budget; |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @Groups({"list", "view"}) |
109
|
|
|
* @ORM\Column(type="date", nullable=true) |
110
|
|
|
*/ |
111
|
|
|
private $releaseDate; |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @var GuestWatchedMovie |
115
|
|
|
* @ORM\OneToOne(targetEntity="App\Guests\Entity\GuestWatchedMovie", mappedBy="movie") |
116
|
|
|
* @Groups({"list", "view"}) |
117
|
|
|
*/ |
118
|
|
|
private $guestWatchedMovie; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @var UserWatchedMovie |
122
|
|
|
* @ORM\OneToOne(targetEntity="App\Users\Entity\UserWatchedMovie", mappedBy="movie") |
123
|
|
|
* @Groups({"ROLE_USER"}) |
124
|
|
|
*/ |
125
|
|
|
private $userWatchedMovie; |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @var UserWatchedMovie |
129
|
|
|
* @ORM\OneToOne(targetEntity="App\Users\Entity\UserWatchedMovie", mappedBy="movie") |
130
|
|
|
* @Groups({"userWatchedMovies"}) |
131
|
|
|
*/ |
132
|
|
|
private $ownerWatchedMovie; |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @var UserInterestedMovie |
136
|
|
|
* @ORM\OneToOne(targetEntity="App\Users\Entity\UserInterestedMovie", mappedBy="movie") |
137
|
|
|
* @Groups({"ROLE_USER"}) |
138
|
|
|
*/ |
139
|
|
|
private $userInterestedMovie; |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @Groups({"list", "view"}) |
143
|
|
|
*/ |
144
|
|
|
private $isWatched; |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @var MovieRecommendation |
148
|
|
|
* @ORM\OneToOne(targetEntity="App\Movies\Entity\MovieRecommendation", mappedBy="recommendedMovie") |
149
|
|
|
* @Groups({"ROLE_USER"}) |
150
|
|
|
*/ |
151
|
|
|
private $userRecommendedMovie; |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @ORM\OneToMany(targetEntity="App\Movies\Entity\SimilarMovie", mappedBy="originalMovie", cascade={"persist", "remove"}) |
155
|
|
|
*/ |
156
|
|
|
private $similarMovies; |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @ORM\OneToMany(targetEntity="App\Movies\Entity\MovieRecommendation", mappedBy="originalMovie", cascade={"persist", "remove"}) |
160
|
|
|
*/ |
161
|
|
|
private $recommendations; |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @ORM\OneToMany(targetEntity="App\Movies\Entity\MovieCard", mappedBy="movie", cascade={"persist", "remove"}) |
165
|
|
|
* @Groups({"view"}) |
166
|
|
|
*/ |
167
|
|
|
private $cards; |
168
|
|
|
|
169
|
3 |
|
public function __construct(MovieDTO $movieDTO, MovieTMDB $tmdb) |
170
|
|
|
{ |
171
|
3 |
|
$this->translations = new ArrayCollection(); |
172
|
3 |
|
$this->genres = new ArrayCollection(); |
173
|
3 |
|
$this->similarMovies = new ArrayCollection(); |
174
|
3 |
|
$this->recommendations = new ArrayCollection(); |
175
|
3 |
|
$this->actors = new ArrayCollection(); |
176
|
3 |
|
$this->cards = new ArrayCollection(); |
177
|
|
|
|
178
|
3 |
|
$this->originalTitle = $movieDTO->getOriginalTitle(); |
179
|
3 |
|
$this->originalPosterUrl = $movieDTO->getOriginalPosterUrl(); |
180
|
3 |
|
$this->setImdbId($movieDTO->getImdbId()); |
181
|
3 |
|
$this->setBudget($movieDTO->getBudget()); |
182
|
3 |
|
$this->setRuntime($movieDTO->getRuntime()); |
183
|
3 |
|
$this->setReleaseDate($movieDTO->getReleaseDate()); |
184
|
3 |
|
$this->tmdb = $tmdb; |
185
|
3 |
|
} |
186
|
|
|
|
187
|
24 |
|
public function getId(): ?int |
188
|
|
|
{ |
189
|
24 |
|
return $this->id; |
190
|
|
|
} |
191
|
|
|
|
192
|
3 |
|
public function addGenre(Genre $genre) |
193
|
|
|
{ |
194
|
3 |
|
$this->genres->add($genre); |
195
|
|
|
|
196
|
3 |
|
return $this; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
public function removeAllGenres() |
200
|
|
|
{ |
201
|
|
|
$this->genres->clear(); |
202
|
|
|
|
203
|
|
|
return $this; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return Genre[]|array |
208
|
|
|
*/ |
209
|
14 |
|
public function getGenres() |
210
|
|
|
{ |
211
|
14 |
|
return $this->genres->toArray(); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
public function addActor(Actor $actor) |
215
|
|
|
{ |
216
|
|
|
$movieActor = new MovieActor($this, $actor); |
217
|
|
|
$this->actors->add($movieActor); |
218
|
|
|
|
219
|
|
|
return $this; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* todo return MovieActor[] because sometimes we need to remove entities like this. |
224
|
|
|
* |
225
|
|
|
* @return Actor[]|array |
226
|
|
|
*/ |
227
|
4 |
|
public function getActors(): array |
228
|
|
|
{ |
229
|
4 |
|
$movieActors = $this->actors->toArray(); |
230
|
|
|
|
231
|
|
|
return array_map(function (MovieActor $movieActor) { |
232
|
3 |
|
return $movieActor->getActor(); |
233
|
4 |
|
}, $movieActors); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
public function addSimilarMovie(Movie $similarMovie) |
237
|
|
|
{ |
238
|
|
|
$similarMovie = new SimilarMovie($this, $similarMovie); |
239
|
|
|
$this->similarMovies->add($similarMovie); |
240
|
|
|
|
241
|
|
|
return $this; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
public function removeAllSimilarMovies() |
245
|
|
|
{ |
246
|
|
|
$this->similarMovies->clear(); |
247
|
|
|
|
248
|
|
|
return $this; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @return SimilarMovie[]|array |
253
|
|
|
*/ |
254
|
11 |
|
public function getSimilarMovies() |
255
|
|
|
{ |
256
|
11 |
|
return $this->similarMovies->toArray(); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @return MovieRecommendation[]|array |
261
|
|
|
*/ |
262
|
|
|
public function getRecommendations() |
263
|
|
|
{ |
264
|
|
|
return $this->recommendations->toArray(); |
265
|
|
|
} |
266
|
|
|
|
267
|
6 |
|
public function addRecommendation(User $user, self $recommendedMovie) |
268
|
|
|
{ |
269
|
6 |
|
$recommendedMovie = new MovieRecommendation($user, $this, $recommendedMovie); |
270
|
6 |
|
$this->recommendations->add($recommendedMovie); |
271
|
|
|
|
272
|
6 |
|
return $this; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
public function removeAllRecommendations() |
276
|
|
|
{ |
277
|
|
|
$this->recommendations->clear(); |
278
|
|
|
|
279
|
|
|
return $this; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
public function updateTmdb(MovieTMDB $tmdb) |
283
|
|
|
{ |
284
|
|
|
$this->tmdb = $tmdb; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @param string $imdbId |
289
|
|
|
* |
290
|
|
|
* @return Movie |
291
|
|
|
*/ |
292
|
4 |
|
public function setImdbId(?string $imdbId) |
293
|
|
|
{ |
294
|
4 |
|
$this->imdbId = $imdbId; |
295
|
|
|
|
296
|
4 |
|
return $this; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* @param int $runtime |
301
|
|
|
* |
302
|
|
|
* @return Movie |
303
|
|
|
*/ |
304
|
4 |
|
public function setRuntime(int $runtime) |
305
|
|
|
{ |
306
|
4 |
|
$this->runtime = $runtime; |
307
|
|
|
|
308
|
4 |
|
return $this; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @param int $budget |
313
|
|
|
* |
314
|
|
|
* @return Movie |
315
|
|
|
*/ |
316
|
4 |
|
public function setBudget(int $budget) |
317
|
|
|
{ |
318
|
4 |
|
$this->budget = $budget; |
319
|
|
|
|
320
|
4 |
|
return $this; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @param \DateTimeInterface $releaseDate |
325
|
|
|
* |
326
|
|
|
* @return Movie |
327
|
|
|
*/ |
328
|
4 |
|
public function setReleaseDate(?\DateTimeInterface $releaseDate = null) |
329
|
|
|
{ |
330
|
4 |
|
$this->releaseDate = $releaseDate; |
331
|
|
|
|
332
|
4 |
|
return $this; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* @return string |
337
|
|
|
*/ |
338
|
14 |
|
public function getOriginalTitle() |
339
|
|
|
{ |
340
|
14 |
|
return $this->originalTitle; |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* @param string $title |
345
|
|
|
* |
346
|
|
|
* @return $this |
347
|
|
|
*/ |
348
|
|
|
public function changeOriginalTitle(string $title) |
349
|
|
|
{ |
350
|
|
|
$this->originalTitle = $title; |
351
|
|
|
|
352
|
|
|
return $this; |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* @return mixed |
357
|
|
|
*/ |
358
|
14 |
|
public function getOriginalPosterUrl() |
359
|
|
|
{ |
360
|
14 |
|
return $this->originalPosterUrl; |
361
|
|
|
} |
362
|
|
|
|
363
|
1 |
|
public function setOriginalPosterUrl(string $url) |
364
|
|
|
{ |
365
|
1 |
|
return $this->originalPosterUrl = $url; |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* @return MovieTMDB |
370
|
|
|
*/ |
371
|
15 |
|
public function getTmdb() |
372
|
|
|
{ |
373
|
15 |
|
return $this->tmdb; |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
/** |
377
|
|
|
* @return mixed |
378
|
|
|
*/ |
379
|
4 |
|
public function getImdbId() |
380
|
|
|
{ |
381
|
4 |
|
return $this->imdbId; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* @return mixed |
386
|
|
|
*/ |
387
|
4 |
|
public function getRuntime() |
388
|
|
|
{ |
389
|
4 |
|
return $this->runtime; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* @return mixed |
394
|
|
|
*/ |
395
|
4 |
|
public function getBudget() |
396
|
|
|
{ |
397
|
4 |
|
return $this->budget; |
398
|
|
|
} |
399
|
|
|
|
400
|
14 |
|
public function getReleaseDate(): ?\DateTimeInterface |
401
|
|
|
{ |
402
|
14 |
|
return $this->releaseDate; |
403
|
|
|
} |
404
|
|
|
|
405
|
7 |
|
public function getUserWatchedMovie() |
406
|
|
|
{ |
407
|
7 |
|
return $this->userWatchedMovie; |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
public function getOwnerWatchedMovie() |
411
|
|
|
{ |
412
|
|
|
return $this->ownerWatchedMovie; |
413
|
|
|
} |
414
|
|
|
|
415
|
14 |
|
public function getGuestWatchedMovie() |
416
|
|
|
{ |
417
|
14 |
|
return $this->guestWatchedMovie; |
418
|
|
|
} |
419
|
|
|
|
420
|
14 |
|
public function isWatched() |
421
|
|
|
{ |
422
|
14 |
|
$this->isWatched = ($this->userWatchedMovie || $this->guestWatchedMovie) ? true : false; |
423
|
|
|
|
424
|
14 |
|
return $this->isWatched; |
425
|
|
|
} |
426
|
|
|
|
427
|
7 |
|
public function getUserInterestedMovie() |
428
|
|
|
{ |
429
|
7 |
|
return $this->userInterestedMovie; |
430
|
|
|
} |
431
|
|
|
|
432
|
7 |
|
public function getUserRecommendedMovie() |
433
|
|
|
{ |
434
|
7 |
|
return $this->userRecommendedMovie; |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
/** |
438
|
|
|
* @param string $originalTitle |
439
|
|
|
*/ |
440
|
1 |
|
public function setOriginalTitle(string $originalTitle): void |
441
|
|
|
{ |
442
|
1 |
|
$this->originalTitle = $originalTitle; |
443
|
1 |
|
} |
444
|
|
|
|
445
|
|
|
/** |
446
|
|
|
* @return ArrayCollection|MovieCard[] |
447
|
|
|
*/ |
448
|
4 |
|
public function getCards() |
449
|
|
|
{ |
450
|
4 |
|
return $this->cards; |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
public function __toString() |
454
|
|
|
{ |
455
|
|
|
return $this->getId().' | '.$this->getOriginalTitle().' | TMDB: '.$this->getTmdb()->getId(); |
456
|
|
|
} |
457
|
|
|
} |
458
|
|
|
|