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