Completed
Push — master ( 97cb5e...1302da )
by Valentyn
02:35
created

Movie::getTmdb()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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