1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Application\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Profile Entity. |
9
|
|
|
* |
10
|
|
|
* @ORM\Table(name="profiles") |
11
|
|
|
* @ORM\Entity(repositoryClass="Application\Repository\ProfileRepository") |
12
|
|
|
* @ORM\HasLifecycleCallbacks() |
13
|
|
|
* |
14
|
|
|
* @author Borut Balažek <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class ProfileEntity extends AbstractImageUpload |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var int |
20
|
|
|
* |
21
|
|
|
* @ORM\Column(name="id", type="integer") |
22
|
|
|
* @ORM\Id |
23
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY") |
24
|
|
|
*/ |
25
|
|
|
protected $id; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Mr., Mrs., Ms., Ing., ... |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
* |
32
|
|
|
* @ORM\Column(name="title", type="string", length=8, nullable=true) |
33
|
|
|
*/ |
34
|
|
|
protected $title; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
* |
39
|
|
|
* @ORM\Column(name="first_name", type="string", length=32, nullable=true) |
40
|
|
|
*/ |
41
|
|
|
protected $firstName; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string |
45
|
|
|
* |
46
|
|
|
* @ORM\Column(name="middle_name", type="string", length=32, nullable=true) |
47
|
|
|
*/ |
48
|
|
|
protected $middleName; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string |
52
|
|
|
* |
53
|
|
|
* @ORM\Column(name="last_name", type="string", length=32, nullable=true) |
54
|
|
|
*/ |
55
|
|
|
protected $lastName; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* male or female? |
59
|
|
|
* |
60
|
|
|
* @var string |
61
|
|
|
* |
62
|
|
|
* @ORM\Column(name="gender", type="string", length=8, nullable=true) |
63
|
|
|
*/ |
64
|
|
|
protected $gender; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var \DateTime |
68
|
|
|
* |
69
|
|
|
* @ORM\Column(name="birthdate", type="datetime", nullable=true) |
70
|
|
|
*/ |
71
|
|
|
protected $birthdate; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @var string |
75
|
|
|
* |
76
|
|
|
* @ORM\Column(name="image_url", type="text", nullable=true) |
77
|
|
|
*/ |
78
|
|
|
protected $imageUrl; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @ORM\OneToOne(targetEntity="Application\Entity\UserEntity", inversedBy="profile") |
82
|
|
|
* @ORM\JoinColumn(name="user_id", referencedColumnName="id") |
83
|
|
|
*/ |
84
|
|
|
protected $user; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @var bool |
88
|
|
|
*/ |
89
|
|
|
protected $removeImage = false; |
90
|
|
|
|
91
|
|
|
/*** Id ***/ |
92
|
|
|
/** |
93
|
|
|
* @return int |
94
|
|
|
*/ |
95
|
|
|
public function getId() |
96
|
|
|
{ |
97
|
|
|
return $this->id; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param int $id |
102
|
|
|
* |
103
|
|
|
* @return ProfileEntity |
104
|
|
|
*/ |
105
|
|
|
public function setId($id) |
106
|
|
|
{ |
107
|
|
|
$this->id = $id; |
108
|
|
|
|
109
|
|
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/*** Title ***/ |
113
|
|
|
/** |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
|
|
public function getTitle() |
117
|
|
|
{ |
118
|
|
|
return $this->title; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param string $title |
123
|
|
|
* |
124
|
|
|
* @return ProfileEntity |
125
|
|
|
*/ |
126
|
|
|
public function setTitle($title) |
127
|
|
|
{ |
128
|
|
|
$this->title = $title; |
129
|
|
|
|
130
|
|
|
return $this; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/*** Name ***/ |
134
|
|
|
/** |
135
|
|
|
* @return string |
136
|
|
|
*/ |
137
|
|
|
public function getName() |
138
|
|
|
{ |
139
|
|
|
return $this->getFirstName().' '.$this->getLastName(); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/*** First name ***/ |
143
|
|
|
/** |
144
|
|
|
* @return string |
145
|
|
|
*/ |
146
|
|
|
public function getFirstName() |
147
|
|
|
{ |
148
|
|
|
return $this->firstName; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param string $firstName |
153
|
|
|
* |
154
|
|
|
* @return ProfileEntity |
155
|
|
|
*/ |
156
|
|
|
public function setFirstName($firstName) |
157
|
|
|
{ |
158
|
|
|
$this->firstName = $firstName; |
159
|
|
|
|
160
|
|
|
return $this; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/*** Middle name ***/ |
164
|
|
|
/** |
165
|
|
|
* @return string |
166
|
|
|
*/ |
167
|
|
|
public function getMiddleName() |
168
|
|
|
{ |
169
|
|
|
return $this->middleName; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param string $middleName |
174
|
|
|
* |
175
|
|
|
* @return ProfileEntity |
176
|
|
|
*/ |
177
|
|
|
public function setMiddleName($middleName) |
178
|
|
|
{ |
179
|
|
|
$this->middleName = $middleName; |
180
|
|
|
|
181
|
|
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/*** Last name ***/ |
185
|
|
|
/** |
186
|
|
|
* @return string |
187
|
|
|
*/ |
188
|
|
|
public function getLastName() |
189
|
|
|
{ |
190
|
|
|
return $this->lastName; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param string $lastName |
195
|
|
|
* |
196
|
|
|
* @return ProfileEntity |
197
|
|
|
*/ |
198
|
|
|
public function setLastName($lastName) |
199
|
|
|
{ |
200
|
|
|
$this->lastName = $lastName; |
201
|
|
|
|
202
|
|
|
return $this; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/*** Full name ***/ |
206
|
|
|
/** |
207
|
|
|
* @return string |
208
|
|
|
*/ |
209
|
|
|
public function getFullName() |
210
|
|
|
{ |
211
|
|
|
return trim( |
212
|
|
|
$this->getTitle().' '. |
213
|
|
|
$this->getFirstName().' '. |
214
|
|
|
$this->getMiddleName().' '. |
215
|
|
|
$this->getLastName() |
216
|
|
|
); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/*** Gender ***/ |
220
|
|
|
/** |
221
|
|
|
* @return string |
222
|
|
|
*/ |
223
|
|
|
public function getGender() |
224
|
|
|
{ |
225
|
|
|
return $this->gender; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* @param string $gender |
230
|
|
|
* |
231
|
|
|
* @return ProfileEntity |
232
|
|
|
*/ |
233
|
|
|
public function setGender($gender) |
234
|
|
|
{ |
235
|
|
|
$this->gender = $gender; |
236
|
|
|
|
237
|
|
|
return $this; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/*** Birthdate ***/ |
241
|
|
|
/** |
242
|
|
|
* @return string |
243
|
|
|
*/ |
244
|
|
|
public function getBirthdate() |
245
|
|
|
{ |
246
|
|
|
return $this->birthdate; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* @param mixed $birthdate |
251
|
|
|
* |
252
|
|
|
* @return ProfileEntity |
253
|
|
|
*/ |
254
|
|
|
public function setBirthdate($birthdate = null) |
255
|
|
|
{ |
256
|
|
|
if ($birthdate === null) { |
257
|
|
|
$this->birthdate = null; |
258
|
|
|
} elseif ($birthdate instanceof \DateTime) { |
259
|
|
|
$this->birthdate = $birthdate; |
260
|
|
|
} else { |
261
|
|
|
$this->birthdate = new \DateTime($birthdate); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
return $this; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/*** Age ***/ |
268
|
|
|
/** |
269
|
|
|
* @return string |
270
|
|
|
*/ |
271
|
|
|
public function getAge($format = '%y') |
272
|
|
|
{ |
273
|
|
|
return $this->getBirthdate() |
274
|
|
|
? $this->getBirthdate()->diff(new \DateTime())->format($format) |
275
|
|
|
: null |
276
|
|
|
; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/*** User ***/ |
280
|
|
|
/** |
281
|
|
|
* @return UserEntity |
282
|
|
|
*/ |
283
|
|
|
public function getUser() |
284
|
|
|
{ |
285
|
|
|
return $this->user; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @param UserEntity $user |
290
|
|
|
* |
291
|
|
|
* @return ProfileEntity |
292
|
|
|
*/ |
293
|
|
|
public function setUser(UserEntity $user) |
294
|
|
|
{ |
295
|
|
|
$this->user = $user; |
296
|
|
|
|
297
|
|
|
return $this; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/*** Remove image ***/ |
301
|
|
|
/** |
302
|
|
|
* @return bool |
303
|
|
|
*/ |
304
|
|
|
public function getRemoveImage() |
305
|
|
|
{ |
306
|
|
|
return $this->removeImage; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* @param bool $removeImage |
311
|
|
|
* |
312
|
|
|
* @return PostEntity |
313
|
|
|
*/ |
314
|
|
|
public function setRemoveImage($removeImage) |
315
|
|
|
{ |
316
|
|
|
$this->removeImage = $removeImage; |
317
|
|
|
|
318
|
|
|
return $this; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* @return array |
323
|
|
|
*/ |
324
|
|
|
public function toArray() |
325
|
|
|
{ |
326
|
|
|
return array( |
327
|
|
|
'id' => $this->getId(), |
328
|
|
|
'title' => $this->getTitle(), |
329
|
|
|
'full_name' => $this->getFullName(), |
330
|
|
|
'first_name' => $this->getFirstName(), |
331
|
|
|
'middle_name' => $this->getMiddleName(), |
332
|
|
|
'last_name' => $this->getLastName(), |
333
|
|
|
'gender' => $this->getGender(), |
334
|
|
|
'birthdate' => $this->getBirthdate() |
335
|
|
|
? $this->getBirthdate()->format(DATE_ATOM) |
336
|
|
|
: null, |
337
|
|
|
'image_url' => $this->getImageUrl(), |
338
|
|
|
); |
339
|
|
|
} |
340
|
|
|
} |
341
|
|
|
|