1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace App\Movies\Entity; |
5
|
|
|
|
6
|
|
|
use App\Genres\Entity\Genre; |
7
|
|
|
use App\Movies\DTO\MovieDTO; |
8
|
|
|
use App\Translation\TranslatableTrait; |
9
|
|
|
use App\Translation\TranslatableInterface; |
10
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
11
|
|
|
use Doctrine\ORM\Mapping as ORM; |
12
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
13
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
14
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
15
|
|
|
|
16
|
|
|
//todo production_countries, production_companies, actors |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @ORM\Entity(repositoryClass="App\Movies\Repository\MovieRepository") |
20
|
|
|
* @ORM\Table(name="movies") |
21
|
|
|
* @method MovieTranslations getTranslation(string $locale, bool $useFallbackLocale = true) |
22
|
|
|
*/ |
23
|
|
|
class Movie implements TranslatableInterface |
24
|
|
|
{ |
25
|
|
|
use TranslatableTrait; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @ORM\Id() |
29
|
|
|
* @ORM\GeneratedValue() |
30
|
|
|
* @ORM\Column(type="integer") |
31
|
|
|
* @Groups({"list", "view"}) |
32
|
|
|
*/ |
33
|
|
|
private $id; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var $translations MovieTranslations[]|ArrayCollection |
37
|
|
|
* @ORM\OneToMany(targetEntity="App\Movies\Entity\MovieTranslations", mappedBy="movie", cascade={"persist", "remove"}) |
38
|
|
|
* @Assert\Valid(traverse=true) |
39
|
|
|
* @Groups({"list", "view"}) |
40
|
|
|
*/ |
41
|
|
|
private $translations; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var $genres Genre[]|ArrayCollection |
45
|
|
|
* @ORM\ManyToMany(targetEntity="App\Genres\Entity\Genre", cascade={"persist"}) |
46
|
|
|
* @ORM\JoinTable(name="movies_genres", |
47
|
|
|
* joinColumns={@ORM\JoinColumn(name="movie_id", referencedColumnName="id")}, |
48
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="genre_id", referencedColumnName="id")} |
49
|
|
|
* ) |
50
|
|
|
* @ORM\JoinColumn(nullable=false) |
51
|
|
|
* @Assert\Valid(traverse=true) |
52
|
|
|
* @Groups({"list", "view"}) |
53
|
|
|
*/ |
54
|
|
|
private $genres; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @Groups({"list", "view"}) |
58
|
|
|
* @ORM\Column(type="string", length=100) |
59
|
|
|
*/ |
60
|
|
|
private $originalTitle; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @Groups({"list", "view"}) |
64
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
65
|
|
|
*/ |
66
|
|
|
private $originalPosterUrl; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @ORM\Embedded(class="App\Movies\Entity\MovieTMDB", columnPrefix="tmdb_") |
70
|
|
|
* @Assert\Valid(traverse=true) |
71
|
|
|
* @Groups({"list", "view"}) |
72
|
|
|
*/ |
73
|
|
|
private $tmdb; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @ORM\Column(type="string", length=20, nullable=true) |
77
|
|
|
* @Groups({"list", "view"}) |
78
|
|
|
*/ |
79
|
|
|
private $imdbId; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @Groups({"list", "view"}) |
83
|
|
|
* @ORM\Column(type="integer", nullable=true, options={"default": 0}) |
84
|
|
|
*/ |
85
|
|
|
private $runtime; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @Groups({"list", "view"}) |
89
|
|
|
* @ORM\Column(type="integer", nullable=true, options={"default": 0}) |
90
|
|
|
*/ |
91
|
|
|
private $budget; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @Groups({"list", "view"}) |
95
|
|
|
* @ORM\Column(type="date", nullable=true) |
96
|
|
|
*/ |
97
|
|
|
private $releaseDate; |
98
|
|
|
|
99
|
2 |
|
public function __construct(MovieDTO $movieDTO, MovieTMDB $tmdb) |
100
|
|
|
{ |
101
|
2 |
|
$this->translations = new ArrayCollection(); |
102
|
2 |
|
$this->genres = new ArrayCollection(); |
103
|
|
|
|
104
|
2 |
|
$this->originalTitle = $movieDTO->getOriginalTitle(); |
105
|
2 |
|
$this->originalPosterUrl = $movieDTO->getOriginalPosterUrl(); |
106
|
2 |
|
$this->tmdb = $tmdb; |
107
|
2 |
|
} |
108
|
|
|
|
109
|
4 |
|
public function getId() |
110
|
|
|
{ |
111
|
4 |
|
return $this->id; |
112
|
|
|
} |
113
|
|
|
|
114
|
1 |
|
public function addGenre(Genre $genre) |
115
|
|
|
{ |
116
|
1 |
|
$this->genres->add($genre); |
117
|
1 |
|
return $this; |
118
|
|
|
} |
119
|
|
|
|
120
|
4 |
|
public function getGenres() |
121
|
|
|
{ |
122
|
4 |
|
return $this->genres->toArray(); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function updateTmdb(MovieTMDB $tmdb) |
126
|
|
|
{ |
127
|
|
|
$this->tmdb = $tmdb; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param string $imdbId |
132
|
|
|
* @return Movie |
133
|
|
|
*/ |
134
|
|
|
public function setImdbId(string $imdbId) |
135
|
|
|
{ |
136
|
|
|
$this->imdbId = $imdbId; |
137
|
|
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param int $runtime |
142
|
|
|
* @return Movie |
143
|
|
|
*/ |
144
|
|
|
public function setRuntime(int $runtime) |
145
|
|
|
{ |
146
|
|
|
$this->runtime = $runtime; |
147
|
|
|
return $this; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param int $budget |
152
|
|
|
* @return Movie |
153
|
|
|
*/ |
154
|
|
|
public function setBudget(int $budget) |
155
|
|
|
{ |
156
|
|
|
$this->budget = $budget; |
157
|
|
|
return $this; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param \DateTimeInterface $releaseDate |
162
|
|
|
* @return Movie |
163
|
|
|
*/ |
164
|
|
|
public function setReleaseDate(\DateTimeInterface $releaseDate) |
165
|
|
|
{ |
166
|
|
|
$this->releaseDate = $releaseDate; |
167
|
|
|
return $this; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return mixed |
172
|
|
|
*/ |
173
|
4 |
|
public function getOriginalTitle() |
174
|
|
|
{ |
175
|
4 |
|
return $this->originalTitle; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @return mixed |
180
|
|
|
*/ |
181
|
4 |
|
public function getOriginalPosterUrl() |
182
|
|
|
{ |
183
|
4 |
|
return $this->originalPosterUrl; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @return MovieTMDB |
188
|
|
|
*/ |
189
|
4 |
|
public function getTmdb() |
190
|
|
|
{ |
191
|
4 |
|
return $this->tmdb; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @return mixed |
196
|
|
|
*/ |
197
|
4 |
|
public function getImdbId() |
198
|
|
|
{ |
199
|
4 |
|
return $this->imdbId; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @return mixed |
204
|
|
|
*/ |
205
|
4 |
|
public function getRuntime() |
206
|
|
|
{ |
207
|
4 |
|
return $this->runtime; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @return mixed |
212
|
|
|
*/ |
213
|
4 |
|
public function getBudget() |
214
|
|
|
{ |
215
|
4 |
|
return $this->budget; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @return mixed |
220
|
|
|
*/ |
221
|
4 |
|
public function getReleaseDate() |
222
|
|
|
{ |
223
|
4 |
|
return $this->releaseDate; |
224
|
|
|
} |
225
|
|
|
} |