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