|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace App\Movies\Entity; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
8
|
|
|
use Doctrine\ORM\Mapping\MappedSuperclass; |
|
9
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
|
10
|
|
|
|
|
11
|
|
|
/** @MappedSuperclass */ |
|
12
|
|
|
class WatchedMovie |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @ORM\ManyToOne(targetEntity="App\Movies\Entity\Movie") |
|
16
|
|
|
* @ORM\JoinColumn(nullable=false) |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $movie; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @Groups({"list", "view"}) |
|
22
|
|
|
* @ORM\Column(type="decimal", nullable=true) |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $vote; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @Groups({"list", "view"}) |
|
28
|
|
|
* @ORM\Column(type="datetime", nullable=false) |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $addedAt; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @Groups({"list", "view"}) |
|
34
|
|
|
* @ORM\Column(type="date", nullable=true) |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $watchedAt; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* WatchedMovie constructor. |
|
40
|
|
|
* |
|
41
|
|
|
* @param Movie $movie |
|
42
|
|
|
* @param float|null $vote |
|
43
|
|
|
* @param \DateTimeInterface|null $watchedAt |
|
44
|
|
|
* |
|
45
|
|
|
* @throws \Exception |
|
46
|
|
|
*/ |
|
47
|
10 |
|
public function __construct(Movie $movie, ?float $vote, ?\DateTimeInterface $watchedAt) |
|
48
|
|
|
{ |
|
49
|
10 |
|
$this->movie = $movie; |
|
50
|
10 |
|
$this->addedAt = new \DateTimeImmutable(); |
|
51
|
10 |
|
$this->watchedAt = $watchedAt; |
|
52
|
10 |
|
$this->changeVote($vote); |
|
53
|
10 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function updateMovie(Movie $movie) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->movie = $movie; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
10 |
|
public function changeVote(?float $vote) |
|
61
|
|
|
{ |
|
62
|
10 |
|
if ($vote === null) { |
|
63
|
|
|
$this->vote = $vote; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
10 |
|
if ($vote < 0.0 || $vote > 10.0) { |
|
67
|
|
|
throw new \InvalidArgumentException('Vote can\'t be less than 0 or greater than 10'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
10 |
|
$this->vote = (float) $vote; |
|
71
|
10 |
|
} |
|
72
|
|
|
|
|
73
|
2 |
|
public function changeWatchedAt(?\DateTimeInterface $watchedAt) |
|
74
|
|
|
{ |
|
75
|
2 |
|
$this->watchedAt = $watchedAt; |
|
76
|
2 |
|
} |
|
77
|
|
|
|
|
78
|
10 |
|
public function getMovie(): ?Movie |
|
79
|
|
|
{ |
|
80
|
10 |
|
return $this->movie; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
1 |
|
public function getVote(): ?float |
|
84
|
|
|
{ |
|
85
|
1 |
|
return (float) $this->vote; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function getAddedAt(): ?\DateTimeInterface |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->addedAt; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
1 |
|
public function getWatchedAt(): ?\DateTimeInterface |
|
94
|
|
|
{ |
|
95
|
1 |
|
return $this->watchedAt; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|