1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace App\Movies\Entity; |
6
|
|
|
|
7
|
|
|
use App\Genres\Entity\Genre; |
8
|
|
|
use App\Guests\Entity\GuestWatchedMovie; |
9
|
|
|
use App\Movies\DTO\MovieDTO; |
10
|
|
|
use App\Translation\TranslatableInterface; |
11
|
|
|
use App\Translation\TranslatableTrait; |
12
|
|
|
use App\Users\Entity\User; |
13
|
|
|
use App\Users\Entity\UserWatchedMovie; |
14
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
15
|
|
|
use Doctrine\ORM\Mapping as ORM; |
16
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
17
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
18
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
19
|
|
|
|
20
|
|
|
//todo production_countries, production_companies, actors |
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 Genre[]|ArrayCollection |
51
|
|
|
* @ORM\ManyToMany(targetEntity="App\Genres\Entity\Genre") |
52
|
|
|
* @ORM\JoinTable(name="movies_genres", |
53
|
|
|
* joinColumns={@ORM\JoinColumn(name="movie_id", referencedColumnName="id")}, |
54
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="genre_id", referencedColumnName="id")} |
55
|
|
|
* ) |
56
|
|
|
* @ORM\JoinColumn(nullable=false) |
57
|
|
|
* @Assert\Valid(traverse=true) |
58
|
|
|
* @Groups({"list", "view"}) |
59
|
|
|
*/ |
60
|
|
|
private $genres; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @Groups({"list", "view"}) |
64
|
|
|
* @ORM\Column(type="string", length=100) |
65
|
|
|
*/ |
66
|
|
|
private $originalTitle; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @Groups({"list", "view"}) |
70
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
71
|
|
|
*/ |
72
|
|
|
private $originalPosterUrl; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @ORM\Embedded(class="App\Movies\Entity\MovieTMDB", columnPrefix="tmdb_") |
76
|
|
|
* @Assert\Valid(traverse=true) |
77
|
|
|
* @Groups({"list", "view"}) |
78
|
|
|
*/ |
79
|
|
|
private $tmdb; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @ORM\Column(type="string", length=20, nullable=true) |
83
|
|
|
* @Groups({"view"}) |
84
|
|
|
*/ |
85
|
|
|
private $imdbId; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @Groups({"view"}) |
89
|
|
|
* @ORM\Column(type="integer", nullable=true, options={"default": 0}) |
90
|
|
|
*/ |
91
|
|
|
private $runtime; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @Groups({"view"}) |
95
|
|
|
* @ORM\Column(type="integer", nullable=true, options={"default": 0}) |
96
|
|
|
*/ |
97
|
|
|
private $budget; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @Groups({"list", "view"}) |
101
|
|
|
* @ORM\Column(type="date", nullable=true) |
102
|
|
|
*/ |
103
|
|
|
private $releaseDate; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @var GuestWatchedMovie |
107
|
|
|
* @ORM\OneToOne(targetEntity="App\Guests\Entity\GuestWatchedMovie", mappedBy="movie") |
108
|
|
|
* @Groups({"list", "view"}) |
109
|
|
|
*/ |
110
|
|
|
private $guestWatchedMovie; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @var UserWatchedMovie |
114
|
|
|
* @ORM\OneToOne(targetEntity="App\Users\Entity\UserWatchedMovie", mappedBy="movie") |
115
|
|
|
* @Groups({"ROLE_USER"}) |
116
|
|
|
*/ |
117
|
|
|
private $userWatchedMovie; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @Groups({"list", "view"}) |
121
|
|
|
*/ |
122
|
|
|
private $isWatched; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @var MovieRecommendation |
126
|
|
|
* @ORM\OneToOne(targetEntity="App\Movies\Entity\MovieRecommendation", mappedBy="recommendedMovie") |
127
|
|
|
* @Groups({"ROLE_USER"}) |
128
|
|
|
*/ |
129
|
|
|
private $userRecommendedMovie; |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @ORM\OneToMany(targetEntity="App\Movies\Entity\SimilarMovie", mappedBy="originalMovie", cascade={"persist", "remove"}) |
133
|
|
|
*/ |
134
|
|
|
private $similarMovies; |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @ORM\OneToMany(targetEntity="App\Movies\Entity\MovieRecommendation", mappedBy="originalMovie", cascade={"persist", "remove"}) |
138
|
|
|
*/ |
139
|
|
|
private $recommendations; |
140
|
|
|
|
141
|
3 |
|
public function __construct(MovieDTO $movieDTO, MovieTMDB $tmdb) |
142
|
|
|
{ |
143
|
3 |
|
$this->translations = new ArrayCollection(); |
144
|
3 |
|
$this->genres = new ArrayCollection(); |
145
|
3 |
|
$this->similarMovies = new ArrayCollection(); |
146
|
3 |
|
$this->recommendations = new ArrayCollection(); |
147
|
|
|
|
148
|
3 |
|
$this->originalTitle = $movieDTO->getOriginalTitle(); |
149
|
3 |
|
$this->originalPosterUrl = $movieDTO->getOriginalPosterUrl(); |
150
|
3 |
|
$this->setImdbId($movieDTO->getImdbId()); |
151
|
3 |
|
$this->setBudget($movieDTO->getBudget()); |
152
|
3 |
|
$this->setRuntime($movieDTO->getRuntime()); |
153
|
3 |
|
$this->setReleaseDate($movieDTO->getReleaseDate()); |
154
|
3 |
|
$this->tmdb = $tmdb; |
155
|
3 |
|
} |
156
|
|
|
|
157
|
12 |
|
public function getId(): ?int |
158
|
|
|
{ |
159
|
12 |
|
return $this->id; |
160
|
|
|
} |
161
|
|
|
|
162
|
3 |
|
public function addGenre(Genre $genre) |
163
|
|
|
{ |
164
|
3 |
|
$this->genres->add($genre); |
165
|
|
|
|
166
|
3 |
|
return $this; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function removeAllGenres() |
170
|
|
|
{ |
171
|
|
|
$this->genres->clear(); |
172
|
|
|
|
173
|
|
|
return $this; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @return Genre[]|array |
178
|
|
|
*/ |
179
|
9 |
|
public function getGenres() |
180
|
|
|
{ |
181
|
9 |
|
return $this->genres->toArray(); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
public function addSimilarMovie(self $similarMovie) |
185
|
|
|
{ |
186
|
|
|
$similarMovie = new SimilarMovie($this, $similarMovie); |
187
|
|
|
$this->similarMovies->add($similarMovie); |
188
|
|
|
|
189
|
|
|
return $this; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
public function removeAllSimilarMovies() |
193
|
|
|
{ |
194
|
|
|
$this->similarMovies->clear(); |
195
|
|
|
|
196
|
|
|
return $this; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @return Movie[]|array |
201
|
|
|
*/ |
202
|
|
|
public function getSimilarMovies() |
203
|
|
|
{ |
204
|
|
|
return $this->similarMovies->toArray(); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @return Movie[]|array |
209
|
|
|
*/ |
210
|
|
|
public function getRecommendations() |
211
|
|
|
{ |
212
|
|
|
return $this->recommendations->toArray(); |
213
|
|
|
} |
214
|
|
|
|
215
|
1 |
|
public function addRecommendation(User $user, self $recommendedMovie) |
216
|
|
|
{ |
217
|
1 |
|
$recommendedMovie = new MovieRecommendation($user, $this, $recommendedMovie); |
218
|
1 |
|
$this->recommendations->add($recommendedMovie); |
219
|
|
|
|
220
|
1 |
|
return $this; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
public function removeAllRecommendations() |
224
|
|
|
{ |
225
|
|
|
$this->recommendations->clear(); |
226
|
|
|
|
227
|
|
|
return $this; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
public function updateTmdb(MovieTMDB $tmdb) |
231
|
|
|
{ |
232
|
|
|
$this->tmdb = $tmdb; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @param string $imdbId |
237
|
|
|
* |
238
|
|
|
* @return Movie |
239
|
|
|
*/ |
240
|
3 |
|
private function setImdbId(?string $imdbId) |
241
|
|
|
{ |
242
|
3 |
|
$this->imdbId = $imdbId; |
243
|
|
|
|
244
|
3 |
|
return $this; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @param int $runtime |
249
|
|
|
* |
250
|
|
|
* @return Movie |
251
|
|
|
*/ |
252
|
3 |
|
private function setRuntime(int $runtime) |
253
|
|
|
{ |
254
|
3 |
|
$this->runtime = $runtime; |
255
|
|
|
|
256
|
3 |
|
return $this; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @param int $budget |
261
|
|
|
* |
262
|
|
|
* @return Movie |
263
|
|
|
*/ |
264
|
3 |
|
private function setBudget(int $budget) |
265
|
|
|
{ |
266
|
3 |
|
$this->budget = $budget; |
267
|
|
|
|
268
|
3 |
|
return $this; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* @param \DateTimeInterface $releaseDate |
273
|
|
|
* |
274
|
|
|
* @return Movie |
275
|
|
|
*/ |
276
|
3 |
|
private function setReleaseDate(\DateTimeInterface $releaseDate) |
277
|
|
|
{ |
278
|
3 |
|
$this->releaseDate = $releaseDate; |
279
|
|
|
|
280
|
3 |
|
return $this; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @return string |
285
|
|
|
*/ |
286
|
9 |
|
public function getOriginalTitle() |
287
|
|
|
{ |
288
|
9 |
|
return $this->originalTitle; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @param string $title |
293
|
|
|
* @return $this |
294
|
|
|
*/ |
295
|
|
|
public function changeOriginalTitle(string $title) |
296
|
|
|
{ |
297
|
|
|
$this->originalTitle = $title; |
298
|
|
|
|
299
|
|
|
return $this; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* @return mixed |
304
|
|
|
*/ |
305
|
9 |
|
public function getOriginalPosterUrl() |
306
|
|
|
{ |
307
|
9 |
|
return $this->originalPosterUrl; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* @return MovieTMDB |
312
|
|
|
*/ |
313
|
10 |
|
public function getTmdb() |
314
|
|
|
{ |
315
|
10 |
|
return $this->tmdb; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @return mixed |
320
|
|
|
*/ |
321
|
1 |
|
public function getImdbId() |
322
|
|
|
{ |
323
|
1 |
|
return $this->imdbId; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* @return mixed |
328
|
|
|
*/ |
329
|
1 |
|
public function getRuntime() |
330
|
|
|
{ |
331
|
1 |
|
return $this->runtime; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* @return mixed |
336
|
|
|
*/ |
337
|
1 |
|
public function getBudget() |
338
|
|
|
{ |
339
|
1 |
|
return $this->budget; |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* @return mixed |
344
|
|
|
*/ |
345
|
9 |
|
public function getReleaseDate() |
346
|
|
|
{ |
347
|
9 |
|
return $this->releaseDate; |
348
|
|
|
} |
349
|
|
|
|
350
|
3 |
|
public function getUserWatchedMovie() |
351
|
|
|
{ |
352
|
3 |
|
return $this->userWatchedMovie; |
353
|
|
|
} |
354
|
|
|
|
355
|
9 |
|
public function getGuestWatchedMovie() |
356
|
|
|
{ |
357
|
9 |
|
return $this->guestWatchedMovie; |
358
|
|
|
} |
359
|
|
|
|
360
|
9 |
|
public function isWatched() |
361
|
|
|
{ |
362
|
9 |
|
$this->isWatched = ($this->userWatchedMovie || $this->guestWatchedMovie) ? true : false; |
363
|
|
|
|
364
|
9 |
|
return $this->isWatched; |
365
|
|
|
} |
366
|
|
|
|
367
|
3 |
|
public function getUserRecommendedMovie() |
368
|
|
|
{ |
369
|
3 |
|
return $this->userRecommendedMovie; |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
public function __toString() |
373
|
|
|
{ |
374
|
|
|
return $this->getId().' | '.$this->getOriginalTitle().' | TMDB: '.$this->getTmdb()->getId(); |
375
|
|
|
} |
376
|
|
|
} |
377
|
|
|
|