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\UserWatchedMovie; |
13
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
14
|
|
|
use Doctrine\ORM\Mapping as ORM; |
15
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
16
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
17
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
18
|
|
|
|
19
|
|
|
//todo production_countries, production_companies, actors |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @ORM\Entity(repositoryClass="App\Movies\Repository\MovieRepository") |
23
|
|
|
* @ORM\Table(name="movies") |
24
|
|
|
* |
25
|
|
|
* @method MovieTranslations getTranslation(string $locale, bool $useFallbackLocale = true) |
26
|
|
|
* @UniqueEntity("tmdb.id") |
27
|
|
|
*/ |
28
|
|
|
class Movie implements TranslatableInterface |
29
|
|
|
{ |
30
|
|
|
use TranslatableTrait; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @ORM\Id() |
34
|
|
|
* @ORM\GeneratedValue() |
35
|
|
|
* @ORM\Column(type="integer") |
36
|
|
|
* @Groups({"list", "view"}) |
37
|
|
|
*/ |
38
|
|
|
private $id; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var MovieTranslations[]|ArrayCollection |
42
|
|
|
* @ORM\OneToMany(targetEntity="App\Movies\Entity\MovieTranslations", mappedBy="movie", cascade={"persist", "remove"}) |
43
|
|
|
* @Assert\Valid(traverse=true) |
44
|
|
|
* @Groups({"list", "view"}) |
45
|
|
|
*/ |
46
|
|
|
private $translations; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var Genre[]|ArrayCollection |
50
|
|
|
* @ORM\ManyToMany(targetEntity="App\Genres\Entity\Genre") |
51
|
|
|
* @ORM\JoinTable(name="movies_genres", |
52
|
|
|
* joinColumns={@ORM\JoinColumn(name="movie_id", referencedColumnName="id")}, |
53
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="genre_id", referencedColumnName="id")} |
54
|
|
|
* ) |
55
|
|
|
* @ORM\JoinColumn(nullable=false) |
56
|
|
|
* @Assert\Valid(traverse=true) |
57
|
|
|
* @Groups({"list", "view"}) |
58
|
|
|
*/ |
59
|
|
|
private $genres; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @Groups({"list", "view"}) |
63
|
|
|
* @ORM\Column(type="string", length=100) |
64
|
|
|
*/ |
65
|
|
|
private $originalTitle; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @Groups({"list", "view"}) |
69
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
70
|
|
|
*/ |
71
|
|
|
private $originalPosterUrl; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @ORM\Embedded(class="App\Movies\Entity\MovieTMDB", columnPrefix="tmdb_") |
75
|
|
|
* @Assert\Valid(traverse=true) |
76
|
|
|
* @Groups({"list", "view"}) |
77
|
|
|
*/ |
78
|
|
|
private $tmdb; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @ORM\Column(type="string", length=20, nullable=true) |
82
|
|
|
* @Groups({"view"}) |
83
|
|
|
*/ |
84
|
|
|
private $imdbId; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @Groups({"view"}) |
88
|
|
|
* @ORM\Column(type="integer", nullable=true, options={"default": 0}) |
89
|
|
|
*/ |
90
|
|
|
private $runtime; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @Groups({"view"}) |
94
|
|
|
* @ORM\Column(type="integer", nullable=true, options={"default": 0}) |
95
|
|
|
*/ |
96
|
|
|
private $budget; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @Groups({"list", "view"}) |
100
|
|
|
* @ORM\Column(type="date", nullable=true) |
101
|
|
|
*/ |
102
|
|
|
private $releaseDate; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @var GuestWatchedMovie |
106
|
|
|
* @ORM\OneToOne(targetEntity="App\Guests\Entity\GuestWatchedMovie", mappedBy="movie") |
107
|
|
|
* @Groups({"list", "view"}) |
108
|
|
|
*/ |
109
|
|
|
private $guestWatchedMovie; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @var UserWatchedMovie |
113
|
|
|
* @ORM\OneToOne(targetEntity="App\Users\Entity\UserWatchedMovie", mappedBy="movie") |
114
|
|
|
* @Groups({"ROLE_USER"}) |
115
|
|
|
*/ |
116
|
|
|
private $userWatchedMovie; |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @Groups({"list", "view"}) |
120
|
|
|
*/ |
121
|
|
|
private $isWatched; |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @ORM\OneToMany(targetEntity="App\Movies\Entity\SimilarMovie", mappedBy="originalMovie", cascade={"persist", "remove"}) |
125
|
|
|
*/ |
126
|
|
|
private $similarMovies; |
127
|
|
|
|
128
|
3 |
|
public function __construct(MovieDTO $movieDTO, MovieTMDB $tmdb) |
129
|
|
|
{ |
130
|
3 |
|
$this->translations = new ArrayCollection(); |
131
|
3 |
|
$this->genres = new ArrayCollection(); |
132
|
3 |
|
$this->similarMovies = new ArrayCollection(); |
133
|
|
|
|
134
|
3 |
|
$this->originalTitle = $movieDTO->getOriginalTitle(); |
135
|
3 |
|
$this->originalPosterUrl = $movieDTO->getOriginalPosterUrl(); |
136
|
3 |
|
$this->setImdbId($movieDTO->getImdbId()); |
137
|
3 |
|
$this->setBudget($movieDTO->getBudget()); |
138
|
3 |
|
$this->setRuntime($movieDTO->getRuntime()); |
139
|
3 |
|
$this->setReleaseDate($movieDTO->getReleaseDate()); |
140
|
3 |
|
$this->tmdb = $tmdb; |
141
|
3 |
|
} |
142
|
|
|
|
143
|
11 |
|
public function getId(): ?int |
144
|
|
|
{ |
145
|
11 |
|
return $this->id; |
146
|
|
|
} |
147
|
|
|
|
148
|
3 |
|
public function addGenre(Genre $genre) |
149
|
|
|
{ |
150
|
3 |
|
$this->genres->add($genre); |
151
|
|
|
|
152
|
3 |
|
return $this; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function removeAllGenres() |
156
|
|
|
{ |
157
|
|
|
$this->genres->clear(); |
158
|
|
|
|
159
|
|
|
return $this; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return Genre[]|array |
164
|
|
|
*/ |
165
|
8 |
|
public function getGenres() |
166
|
|
|
{ |
167
|
8 |
|
return $this->genres->toArray(); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
public function addSimilarMovie(self $similarMovie) |
171
|
|
|
{ |
172
|
|
|
$similarMovie = new SimilarMovie($this, $similarMovie); |
173
|
|
|
$this->similarMovies->add($similarMovie); |
174
|
|
|
|
175
|
|
|
return $this; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function removeAllSimilarMovies() |
179
|
|
|
{ |
180
|
|
|
$this->similarMovies->clear(); |
181
|
|
|
|
182
|
|
|
return $this; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return Movie[]|array |
187
|
|
|
*/ |
188
|
|
|
public function getSimilarMovies() |
189
|
|
|
{ |
190
|
|
|
return $this->similarMovies->toArray(); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function updateTmdb(MovieTMDB $tmdb) |
194
|
|
|
{ |
195
|
|
|
$this->tmdb = $tmdb; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param string $imdbId |
200
|
|
|
* |
201
|
|
|
* @return Movie |
202
|
|
|
*/ |
203
|
3 |
|
private function setImdbId(?string $imdbId) |
204
|
|
|
{ |
205
|
3 |
|
$this->imdbId = $imdbId; |
206
|
|
|
|
207
|
3 |
|
return $this; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @param int $runtime |
212
|
|
|
* |
213
|
|
|
* @return Movie |
214
|
|
|
*/ |
215
|
3 |
|
private function setRuntime(int $runtime) |
216
|
|
|
{ |
217
|
3 |
|
$this->runtime = $runtime; |
218
|
|
|
|
219
|
3 |
|
return $this; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @param int $budget |
224
|
|
|
* |
225
|
|
|
* @return Movie |
226
|
|
|
*/ |
227
|
3 |
|
private function setBudget(int $budget) |
228
|
|
|
{ |
229
|
3 |
|
$this->budget = $budget; |
230
|
|
|
|
231
|
3 |
|
return $this; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @param \DateTimeInterface $releaseDate |
236
|
|
|
* |
237
|
|
|
* @return Movie |
238
|
|
|
*/ |
239
|
3 |
|
private function setReleaseDate(\DateTimeInterface $releaseDate) |
240
|
|
|
{ |
241
|
3 |
|
$this->releaseDate = $releaseDate; |
242
|
|
|
|
243
|
3 |
|
return $this; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @return mixed |
248
|
|
|
*/ |
249
|
8 |
|
public function getOriginalTitle() |
250
|
|
|
{ |
251
|
8 |
|
return $this->originalTitle; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* @return mixed |
256
|
|
|
*/ |
257
|
8 |
|
public function getOriginalPosterUrl() |
258
|
|
|
{ |
259
|
8 |
|
return $this->originalPosterUrl; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @return MovieTMDB |
264
|
|
|
*/ |
265
|
9 |
|
public function getTmdb() |
266
|
|
|
{ |
267
|
9 |
|
return $this->tmdb; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @return mixed |
272
|
|
|
*/ |
273
|
1 |
|
public function getImdbId() |
274
|
|
|
{ |
275
|
1 |
|
return $this->imdbId; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @return mixed |
280
|
|
|
*/ |
281
|
1 |
|
public function getRuntime() |
282
|
|
|
{ |
283
|
1 |
|
return $this->runtime; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* @return mixed |
288
|
|
|
*/ |
289
|
1 |
|
public function getBudget() |
290
|
|
|
{ |
291
|
1 |
|
return $this->budget; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @return mixed |
296
|
|
|
*/ |
297
|
8 |
|
public function getReleaseDate() |
298
|
|
|
{ |
299
|
8 |
|
return $this->releaseDate; |
300
|
|
|
} |
301
|
|
|
|
302
|
3 |
|
public function getUserWatchedMovie() |
303
|
|
|
{ |
304
|
3 |
|
return $this->userWatchedMovie; |
305
|
|
|
} |
306
|
|
|
|
307
|
8 |
|
public function getGuestWatchedMovie() |
308
|
|
|
{ |
309
|
8 |
|
return $this->guestWatchedMovie; |
310
|
|
|
} |
311
|
|
|
|
312
|
8 |
|
public function isWatched() |
313
|
|
|
{ |
314
|
8 |
|
$this->isWatched = ($this->userWatchedMovie || $this->guestWatchedMovie) ? true : false; |
315
|
|
|
|
316
|
8 |
|
return $this->isWatched; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
public function __toString() |
320
|
|
|
{ |
321
|
|
|
return $this->getId().' | '.$this->getOriginalTitle().' | TMDB: '.$this->getTmdb()->getId(); |
322
|
|
|
} |
323
|
|
|
} |
324
|
|
|
|