1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace App\Actors\Entity; |
6
|
|
|
|
7
|
|
|
use App\Translation\TranslatableInterface; |
8
|
|
|
use App\Translation\TranslatableTrait; |
9
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
10
|
|
|
use Doctrine\ORM\Mapping as ORM; |
11
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
12
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
13
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @ORM\Entity(repositoryClass="App\Actors\Repository\ActorRepository") |
17
|
|
|
* @ORM\Table(name="actors") |
18
|
|
|
* |
19
|
|
|
* @method ActorTranslations getTranslation(string $locale, bool $useFallbackLocale = true) |
20
|
|
|
* @UniqueEntity("tmdb.id") |
21
|
|
|
*/ |
22
|
|
|
class Actor implements TranslatableInterface |
23
|
|
|
{ |
24
|
|
|
use TranslatableTrait; |
25
|
|
|
|
26
|
|
|
const GENDER_MALE = 2; |
27
|
|
|
const GENDER_FEMALE = 1; |
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 ActorTranslations[]|ArrayCollection |
39
|
|
|
* @ORM\OneToMany(targetEntity="App\Actors\Entity\ActorTranslations", mappedBy="actor", cascade={"persist", "remove"}) |
40
|
|
|
* @Assert\Valid(traverse=true) |
41
|
|
|
* @Groups({"list", "view"}) |
42
|
|
|
*/ |
43
|
|
|
private $translations; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var ActorContacts[]|ArrayCollection |
47
|
|
|
* @ORM\OneToMany(targetEntity="App\Actors\Entity\ActorContacts", mappedBy="actor", cascade={"persist", "remove"}) |
48
|
|
|
* @ORM\JoinColumn(nullable=true) |
49
|
|
|
* @Groups({"view"}) |
50
|
|
|
*/ |
51
|
|
|
private $contacts; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @Groups({"list", "view"}) |
55
|
|
|
* @ORM\Column(type="string", length=100) |
56
|
|
|
*/ |
57
|
|
|
private $originalName; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @Groups({"list", "view"}) |
61
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
62
|
|
|
*/ |
63
|
|
|
private $photo; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @ORM\Embedded(class="App\Actors\Entity\ActorTMDB", columnPrefix="tmdb_") |
67
|
|
|
* @Assert\Valid(traverse=true) |
68
|
|
|
* @Groups({"list", "view"}) |
69
|
|
|
*/ |
70
|
|
|
private $tmdb; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @ORM\Column(type="string", length=20, nullable=true) |
74
|
|
|
* @Groups({"view"}) |
75
|
|
|
*/ |
76
|
|
|
private $imdbId; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @Groups({"list", "view"}) |
80
|
|
|
* @ORM\Column(type="date", nullable=true) |
81
|
|
|
*/ |
82
|
|
|
private $birthday; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @Groups({"list", "view"}) |
86
|
|
|
* @ORM\Column(type="integer", length=1, nullable=false) |
87
|
|
|
*/ |
88
|
|
|
private $gender; |
89
|
|
|
|
90
|
2 |
|
public function __construct(string $originalName, ActorTMDB $actorTMDB) |
91
|
|
|
{ |
92
|
2 |
|
$this->translations = new ArrayCollection(); |
93
|
2 |
|
$this->contacts = new ArrayCollection(); |
94
|
|
|
|
95
|
2 |
|
$this->originalName = $originalName; |
96
|
2 |
|
$this->tmdb = $actorTMDB; |
97
|
2 |
|
$this->gender = self::GENDER_MALE; |
98
|
2 |
|
} |
99
|
|
|
|
100
|
4 |
|
public function getId(): int |
101
|
|
|
{ |
102
|
4 |
|
return $this->id; |
103
|
|
|
} |
104
|
|
|
|
105
|
6 |
|
public function getOriginalName(): string |
106
|
|
|
{ |
107
|
6 |
|
return $this->originalName; |
108
|
|
|
} |
109
|
|
|
|
110
|
2 |
|
public function setOriginalName(string $originalName): void |
111
|
|
|
{ |
112
|
2 |
|
$this->originalName = $originalName; |
113
|
2 |
|
} |
114
|
|
|
|
115
|
6 |
|
public function getPhoto(): ?string |
116
|
|
|
{ |
117
|
6 |
|
return $this->photo; |
118
|
|
|
} |
119
|
|
|
|
120
|
2 |
|
public function setPhoto(string $photo): void |
121
|
|
|
{ |
122
|
2 |
|
$this->photo = $photo; |
123
|
2 |
|
} |
124
|
|
|
|
125
|
6 |
|
public function getTmdb(): ActorTMDB |
126
|
|
|
{ |
127
|
6 |
|
return $this->tmdb; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function setTmdb(ActorTMDB $tmdb): void |
131
|
|
|
{ |
132
|
|
|
$this->tmdb = $tmdb; |
133
|
|
|
} |
134
|
|
|
|
135
|
5 |
|
public function getImdbId(): ?string |
136
|
|
|
{ |
137
|
5 |
|
return $this->imdbId; |
138
|
|
|
} |
139
|
|
|
|
140
|
4 |
|
public function setImdbId(string $imdbId): void |
141
|
|
|
{ |
142
|
4 |
|
$this->imdbId = $imdbId; |
143
|
4 |
|
} |
144
|
|
|
|
145
|
5 |
|
public function getBirthday(): ?\DateTimeInterface |
146
|
|
|
{ |
147
|
5 |
|
return $this->birthday; |
148
|
|
|
} |
149
|
|
|
|
150
|
4 |
|
public function setBirthday(\DateTimeInterface $birthday): void |
151
|
|
|
{ |
152
|
4 |
|
$this->birthday = $birthday; |
153
|
4 |
|
} |
154
|
|
|
|
155
|
6 |
|
public function getGender(): int |
156
|
|
|
{ |
157
|
6 |
|
return $this->gender; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param int $gender |
162
|
|
|
* |
163
|
|
|
* @throws \InvalidArgumentException |
164
|
|
|
*/ |
165
|
4 |
|
public function setGender(int $gender): void |
166
|
|
|
{ |
167
|
4 |
|
if (false === in_array($gender, [self::GENDER_FEMALE, self::GENDER_MALE], true)) { |
168
|
|
|
throw new \InvalidArgumentException('Invalid gender value'); |
169
|
|
|
} |
170
|
4 |
|
$this->gender = $gender; |
171
|
4 |
|
} |
172
|
|
|
|
173
|
3 |
|
public function getContacts() |
174
|
|
|
{ |
175
|
3 |
|
return $this->contacts->toArray(); |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|