|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Del\Person\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime; |
|
6
|
|
|
use Del\Entity\Country; |
|
7
|
|
|
use Del\Factory\CountryFactory; |
|
8
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
9
|
|
|
use JsonSerializable; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @ORM\Entity(repositoryClass="\Del\Person\Repository\PersonRepository") |
|
13
|
|
|
*/ |
|
14
|
|
|
class Person implements JsonSerializable |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @ORM\Id |
|
18
|
|
|
* @ORM\Column(type="integer") |
|
19
|
|
|
* @ORM\GeneratedValue |
|
20
|
|
|
*/ |
|
21
|
|
|
private $id; |
|
22
|
|
|
|
|
23
|
|
|
/** @ORM\Column(type="string",length=60,nullable=true) */ |
|
24
|
|
|
private $firstname; |
|
25
|
|
|
|
|
26
|
|
|
/** @ORM\Column(type="string",length=60,nullable=true) */ |
|
27
|
|
|
private $middlename; |
|
28
|
|
|
|
|
29
|
|
|
/** @ORM\Column(type="string",length=60,nullable=true) */ |
|
30
|
|
|
private $lastname; |
|
31
|
|
|
|
|
32
|
|
|
/** @ORM\Column(type="string",length=50,nullable=true) */ |
|
33
|
|
|
private $aka; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @ORM\Column(type="date",nullable=true) |
|
37
|
|
|
* @var DateTime |
|
38
|
|
|
*/ |
|
39
|
|
|
private $dob; |
|
40
|
|
|
|
|
41
|
|
|
/** @ORM\Column(type="string",length=50,nullable=true) */ |
|
42
|
|
|
private $birthplace; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var string $country |
|
46
|
|
|
* @ORM\Column(type="string",length=3,nullable=true) |
|
47
|
|
|
*/ |
|
48
|
|
|
private $country; |
|
49
|
|
|
|
|
50
|
|
|
/** @ORM\Column(type="string",length=255,nullable=true) */ |
|
51
|
|
|
private $image; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return int |
|
55
|
8 |
|
*/ |
|
56
|
|
|
public function getId() |
|
57
|
8 |
|
{ |
|
58
|
|
|
return $this->id; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param int $id |
|
63
|
|
|
* @return Person |
|
64
|
5 |
|
*/ |
|
65
|
|
|
public function setId($id) |
|
66
|
5 |
|
{ |
|
67
|
5 |
|
$this->id = $id; |
|
68
|
|
|
return $this; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return Country|null |
|
73
|
|
|
* @throws \Del\CountryException |
|
74
|
3 |
|
*/ |
|
75
|
|
|
public function getCountry(): ?Country |
|
76
|
3 |
|
{ |
|
77
|
|
|
return $this->country ? CountryFactory::generate($this->country) : null; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param Country $country |
|
82
|
|
|
* @return Person |
|
83
|
5 |
|
*/ |
|
84
|
|
|
public function setCountry(Country $country) |
|
85
|
5 |
|
{ |
|
86
|
5 |
|
$this->country = $country->getIso(); |
|
87
|
|
|
return $this; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return string |
|
92
|
4 |
|
*/ |
|
93
|
|
|
public function getFirstname() |
|
94
|
4 |
|
{ |
|
95
|
|
|
return $this->firstname; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @param string $firstname |
|
100
|
|
|
* @return Person |
|
101
|
6 |
|
*/ |
|
102
|
|
|
public function setFirstname($firstname) |
|
103
|
6 |
|
{ |
|
104
|
6 |
|
$this->firstname = $firstname; |
|
105
|
|
|
return $this; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @return string |
|
110
|
3 |
|
*/ |
|
111
|
|
|
public function getMiddlename() |
|
112
|
3 |
|
{ |
|
113
|
|
|
return $this->middlename; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @param string $middlename |
|
118
|
|
|
* @return Person |
|
119
|
5 |
|
*/ |
|
120
|
|
|
public function setMiddlename($middlename) |
|
121
|
5 |
|
{ |
|
122
|
5 |
|
$this->middlename = $middlename; |
|
123
|
|
|
return $this; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @return string |
|
128
|
3 |
|
*/ |
|
129
|
|
|
public function getLastname() |
|
130
|
3 |
|
{ |
|
131
|
|
|
return $this->lastname; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @param string $lastname |
|
136
|
|
|
* @return Person |
|
137
|
5 |
|
*/ |
|
138
|
|
|
public function setLastname($lastname) |
|
139
|
5 |
|
{ |
|
140
|
5 |
|
$this->lastname = $lastname; |
|
141
|
|
|
return $this; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @return string |
|
146
|
4 |
|
*/ |
|
147
|
|
|
public function getAka() |
|
148
|
4 |
|
{ |
|
149
|
|
|
return $this->aka; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @param string $aka |
|
154
|
|
|
* @return Person |
|
155
|
5 |
|
*/ |
|
156
|
|
|
public function setAka($aka) |
|
157
|
5 |
|
{ |
|
158
|
5 |
|
$this->aka = $aka; |
|
159
|
|
|
return $this; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @return DateTime |
|
164
|
3 |
|
*/ |
|
165
|
|
|
public function getDob() |
|
166
|
3 |
|
{ |
|
167
|
|
|
return $this->dob; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @param $dob |
|
172
|
|
|
* @return Person |
|
173
|
5 |
|
*/ |
|
174
|
|
|
public function setDob(DateTime $dob) |
|
175
|
5 |
|
{ |
|
176
|
5 |
|
$this->dob = $dob; |
|
177
|
|
|
return $this; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @return string |
|
182
|
3 |
|
*/ |
|
183
|
|
|
public function getBirthplace() |
|
184
|
3 |
|
{ |
|
185
|
|
|
return $this->birthplace; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* @param string $birthplace |
|
190
|
|
|
* @return Person |
|
191
|
5 |
|
*/ |
|
192
|
|
|
public function setBirthplace($birthplace) |
|
193
|
5 |
|
{ |
|
194
|
5 |
|
$this->birthplace = $birthplace; |
|
195
|
|
|
return $this; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* @return string |
|
200
|
1 |
|
*/ |
|
201
|
|
|
public function getImage() |
|
202
|
1 |
|
{ |
|
203
|
|
|
return $this->image; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* @param string $image |
|
208
|
|
|
* @return Person |
|
209
|
1 |
|
*/ |
|
210
|
|
|
public function setImage($image) |
|
211
|
1 |
|
{ |
|
212
|
1 |
|
$this->image = $image; |
|
213
|
|
|
return $this; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* @param bool $includeMiddleNames |
|
218
|
|
|
* @return string |
|
219
|
|
|
*/ |
|
220
|
|
|
public function getFullName($includeMiddleNames = false): string |
|
221
|
|
|
{ |
|
222
|
|
|
$middleName = $includeMiddleNames && $this->middlename ? ' ' . $this->middlename : ''; |
|
223
|
|
|
|
|
224
|
|
|
return $this->firstname . $middleName . ' ' . $this->lastname; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* @return array |
|
229
|
|
|
*/ |
|
230
|
|
|
public function toArray(): array |
|
231
|
|
|
{ |
|
232
|
|
|
return [ |
|
233
|
|
|
'id' => $this->getId(), |
|
234
|
|
|
'firstname' => $this->getFirstname(), |
|
235
|
|
|
'middlename' => $this->getMiddlename(), |
|
236
|
|
|
'lastname' => $this->getLastname(), |
|
237
|
|
|
'aka' => $this->getAka(), |
|
238
|
|
|
'dob' => $this->getDob()->format('Y-m-d H:i:s'), |
|
239
|
|
|
'birthplace' => $this->getBirthplace(), |
|
240
|
|
|
'country' => $this->getCountry()->getIso(), |
|
241
|
|
|
'image' => $this->getImage(), |
|
242
|
|
|
]; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
/** |
|
246
|
|
|
* @return array |
|
247
|
|
|
*/ |
|
248
|
|
|
public function jsonSerialize() |
|
249
|
|
|
{ |
|
250
|
|
|
return $this->toArray(); |
|
251
|
|
|
} |
|
252
|
|
|
} |
|
253
|
|
|
|