1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
7
|
|
|
use Knp\DoctrineBehaviors\Model as ORMBehaviors; |
8
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
9
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
10
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
11
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* User. |
15
|
|
|
* |
16
|
|
|
* @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository") |
17
|
|
|
* @UniqueEntity("email") |
18
|
|
|
*/ |
19
|
|
|
class User implements UserInterface, \Serializable |
20
|
|
|
{ |
21
|
|
|
use ORMBehaviors\Timestampable\Timestampable; |
22
|
|
|
/** |
23
|
|
|
* @var int |
24
|
|
|
* |
25
|
|
|
* @ORM\Column(type="integer") |
26
|
|
|
* @ORM\Id |
27
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
28
|
|
|
* @Groups({"Default", "Short", "Detail"}) |
29
|
|
|
*/ |
30
|
|
|
private $id; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
* @Assert\NotBlank() |
35
|
|
|
* @Assert\Regex( |
36
|
|
|
* pattern="/\d/", |
37
|
|
|
* match=false, |
38
|
|
|
* message="Your name cannot contain a number" |
39
|
|
|
* ) |
40
|
|
|
* @Assert\Type("string") |
41
|
|
|
* @Assert\Length( |
42
|
|
|
* min = 2, |
43
|
|
|
* max = 190 |
44
|
|
|
* ) |
45
|
|
|
* @ORM\Column(type="string", length=190) |
46
|
|
|
* @Groups({"Default", "Short", "Detail"}) |
47
|
|
|
*/ |
48
|
|
|
private $firstName; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string |
52
|
|
|
* @Assert\NotBlank() |
53
|
|
|
* @Assert\Regex( |
54
|
|
|
* pattern="/\d/", |
55
|
|
|
* match=false, |
56
|
|
|
* message="Your lastname cannot contain a number" |
57
|
|
|
* ) |
58
|
|
|
* @Assert\Type("string") |
59
|
|
|
* @Assert\Length( |
60
|
|
|
* max = 190 |
61
|
|
|
* ) |
62
|
|
|
* @ORM\Column(type="string", length=190, nullable=true) |
63
|
|
|
* @Groups({"Default", "Short", "Detail"}) |
64
|
|
|
*/ |
65
|
|
|
private $lastName; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var string |
69
|
|
|
* @ORM\OneToOne(targetEntity="Image", cascade={"persist", "remove"}, fetch="EAGER", orphanRemoval=true) |
70
|
|
|
* @Groups({"Short", "Detail"}) |
71
|
|
|
*/ |
72
|
|
|
private $image; |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var string |
77
|
|
|
* @Assert\NotBlank() |
78
|
|
|
* @Assert\Email( |
79
|
|
|
* checkMX = true |
80
|
|
|
* ) |
81
|
|
|
* @Assert\Type("string") |
82
|
|
|
* @Assert\Length( |
83
|
|
|
* max = 250 |
84
|
|
|
* ) |
85
|
|
|
* @ORM\Column(type="string", length=250, unique=true) |
86
|
|
|
* @Groups({"Short", "Detail"}) |
87
|
|
|
*/ |
88
|
|
|
private $email; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @var string |
92
|
|
|
* @ORM\Column(type="string", length=255) |
93
|
|
|
*/ |
94
|
|
|
private $password; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @var string |
98
|
|
|
* @Assert\Type("string") |
99
|
|
|
* @Assert\Length( |
100
|
|
|
* max = 255 |
101
|
|
|
* ) |
102
|
|
|
* @Assert\NotBlank(groups={"registration"}) |
103
|
|
|
*/ |
104
|
|
|
private $plainPassword; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @var bool |
108
|
|
|
* @ORM\Column(type="boolean") |
109
|
|
|
*/ |
110
|
|
|
private $enabled = true; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @var |
114
|
|
|
* @ORM\Column(type="json_array") |
115
|
|
|
*/ |
116
|
|
|
protected $roles; |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @var string |
120
|
|
|
* |
121
|
|
|
* @ORM\Column(type="string", unique=true, nullable=true) |
122
|
|
|
*/ |
123
|
|
|
private $apiToken; |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @var ArrayCollection[Event] |
127
|
|
|
* @ORM\ManyToMany(targetEntity="Event", inversedBy="users", cascade={"persist", "remove"}) |
128
|
|
|
* @Groups({"Detail"}) |
129
|
|
|
*/ |
130
|
|
|
private $events; |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @var ArrayCollection[FormRequest] |
134
|
|
|
* @ORM\OneToMany(targetEntity="FormRequest", mappedBy="user") |
135
|
|
|
* @Groups({"Detail"}) |
136
|
|
|
*/ |
137
|
|
|
private $formRequests; |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @var ArrayCollection[Survey] |
141
|
|
|
* @ORM\OneToMany(targetEntity="Survey", mappedBy="user") |
142
|
|
|
*/ |
143
|
|
|
private $surveys; |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @var ArrayCollection[SurveyAnswer] |
147
|
|
|
* @ORM\OneToMany(targetEntity="SurveyAnswer", mappedBy="user") |
148
|
|
|
*/ |
149
|
|
|
private $answers; |
150
|
|
|
|
151
|
|
|
public function __construct() |
152
|
|
|
{ |
153
|
|
|
$this->events = new ArrayCollection(); |
154
|
|
|
$this->formRequests = new ArrayCollection(); |
155
|
|
|
$this->surveys = new ArrayCollection(); |
156
|
|
|
$this->answers = new ArrayCollection(); |
157
|
|
|
$this->roles = array('ROLE_USER'); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Get id. |
162
|
|
|
* |
163
|
|
|
* @return int |
164
|
|
|
*/ |
165
|
|
|
public function getId() |
166
|
|
|
{ |
167
|
|
|
return $this->id; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Get name. |
172
|
|
|
* |
173
|
|
|
* @return string |
174
|
|
|
*/ |
175
|
|
|
public function getUsername() |
176
|
|
|
{ |
177
|
|
|
return $this->email; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Set firstname. |
182
|
|
|
* |
183
|
|
|
* @param string $name |
184
|
|
|
* |
185
|
|
|
* @return User |
186
|
|
|
*/ |
187
|
|
|
public function setFirstName($name) |
188
|
|
|
{ |
189
|
|
|
$this->firstName = $name; |
190
|
|
|
|
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Get first name. |
196
|
|
|
* |
197
|
|
|
* @return string |
198
|
|
|
*/ |
199
|
|
|
public function getFirstName() |
200
|
|
|
{ |
201
|
|
|
return $this->firstName; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Set lastName. |
206
|
|
|
* |
207
|
|
|
* @param string $lastName |
208
|
|
|
* |
209
|
|
|
* @return User |
210
|
|
|
*/ |
211
|
|
|
public function setLastName($lastName) |
212
|
|
|
{ |
213
|
|
|
$this->lastName = $lastName; |
214
|
|
|
|
215
|
|
|
return $this; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Get lastName. |
220
|
|
|
* |
221
|
|
|
* @return string |
222
|
|
|
*/ |
223
|
|
|
public function getLastName() |
224
|
|
|
{ |
225
|
|
|
return $this->lastName; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Set image. |
230
|
|
|
* |
231
|
|
|
* @param string $image |
232
|
|
|
* |
233
|
|
|
* @return User |
234
|
|
|
*/ |
235
|
|
|
public function setImage($image) |
236
|
|
|
{ |
237
|
|
|
$this->image = $image; |
238
|
|
|
|
239
|
|
|
return $this; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Get image. |
244
|
|
|
* |
245
|
|
|
* @return string |
246
|
|
|
*/ |
247
|
|
|
public function getImage() |
248
|
|
|
{ |
249
|
|
|
return $this->image; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Set email. |
254
|
|
|
* |
255
|
|
|
* @param string $email |
256
|
|
|
* |
257
|
|
|
* @return User |
258
|
|
|
*/ |
259
|
|
|
public function setEmail($email) |
260
|
|
|
{ |
261
|
|
|
$this->email = $email; |
262
|
|
|
|
263
|
|
|
return $this; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Get email. |
268
|
|
|
* |
269
|
|
|
* @return string |
270
|
|
|
*/ |
271
|
|
|
public function getEmail() |
272
|
|
|
{ |
273
|
|
|
return $this->email; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Set password. |
278
|
|
|
* |
279
|
|
|
* @param string $password |
280
|
|
|
* |
281
|
|
|
* @return User |
282
|
|
|
*/ |
283
|
|
|
public function setPassword($password) |
284
|
|
|
{ |
285
|
|
|
$this->password = $password; |
286
|
|
|
|
287
|
|
|
return $this; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Get password. |
292
|
|
|
* |
293
|
|
|
* @return string |
294
|
|
|
*/ |
295
|
|
|
public function getPassword() |
296
|
|
|
{ |
297
|
|
|
return $this->password; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* @return string |
302
|
|
|
*/ |
303
|
|
|
public function getPlainPassword() |
304
|
|
|
{ |
305
|
|
|
return $this->plainPassword; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* @param string $plainPassword |
310
|
|
|
*/ |
311
|
|
|
public function setPlainPassword($plainPassword) |
312
|
|
|
{ |
313
|
|
|
$this->plainPassword = $plainPassword; |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* @param mixed $roles |
318
|
|
|
*/ |
319
|
|
|
public function setRoles($roles) |
320
|
|
|
{ |
321
|
|
|
$this->roles = $roles; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* @return mixed |
326
|
|
|
*/ |
327
|
|
|
public function getRoles() |
328
|
|
|
{ |
329
|
|
|
return $this->roles; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* Set api token. |
334
|
|
|
* |
335
|
|
|
* @param string $apiToken |
336
|
|
|
* |
337
|
|
|
* @return User |
338
|
|
|
*/ |
339
|
|
|
public function setApiToken($apiToken) |
340
|
|
|
{ |
341
|
|
|
$this->apiToken = $apiToken; |
342
|
|
|
|
343
|
|
|
return $this; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* @return string |
348
|
|
|
*/ |
349
|
|
|
public function getApiToken() |
350
|
|
|
{ |
351
|
|
|
return $this->apiToken; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* @param Event $event |
356
|
|
|
* |
357
|
|
|
* @return User |
358
|
|
|
*/ |
359
|
|
|
public function setEvent($event) |
360
|
|
|
{ |
361
|
|
|
if (!$this->events->contains($event)) { |
362
|
|
|
$this->events->add($event); |
363
|
|
|
$event->addUser($this); |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
return $this; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* @return ArrayCollection |
371
|
|
|
*/ |
372
|
|
|
public function getEvents() |
373
|
|
|
{ |
374
|
|
|
return $this->events; |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* @return ArrayCollection |
379
|
|
|
*/ |
380
|
|
|
public function getFormRequests() |
381
|
|
|
{ |
382
|
|
|
return $this->formRequests; |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
/** |
386
|
|
|
* @return ArrayCollection |
387
|
|
|
*/ |
388
|
|
|
public function getSurveys() |
389
|
|
|
{ |
390
|
|
|
return $this->surveys; |
391
|
|
|
} |
392
|
|
|
/** |
393
|
|
|
* @return ArrayCollection |
394
|
|
|
*/ |
395
|
|
|
public function getAnswers() |
396
|
|
|
{ |
397
|
|
|
return $this->answers; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* Set enabled |
402
|
|
|
* |
403
|
|
|
* @param boolean $enabled |
404
|
|
|
* |
405
|
|
|
* @return User |
406
|
|
|
*/ |
407
|
|
|
public function setEnabled(bool $enabled) |
408
|
|
|
{ |
409
|
|
|
$this->enabled = $enabled; |
410
|
|
|
|
411
|
|
|
return $this; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/** |
415
|
|
|
* Get enabled |
416
|
|
|
* |
417
|
|
|
* @return boolean |
418
|
|
|
*/ |
419
|
|
|
public function isEnabled() |
420
|
|
|
{ |
421
|
|
|
return $this->enabled; |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
public function getSalt() |
425
|
|
|
{ |
426
|
|
|
// TODO: Implement getSalt() method. |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
public function eraseCredentials() |
430
|
|
|
{ |
431
|
|
|
$this->setPlainPassword(null); |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** @see \Serializable::serialize() */ |
435
|
|
|
public function serialize() |
436
|
|
|
{ |
437
|
|
|
return serialize(array( |
438
|
|
|
$this->id, |
439
|
|
|
$this->firstName, |
440
|
|
|
$this->lastName, |
441
|
|
|
$this->email, |
442
|
|
|
$this->enabled, |
443
|
|
|
)); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
/** @see \Serializable::unserialize() */ |
447
|
|
|
public function unserialize($serialized) |
448
|
|
|
{ |
449
|
|
|
list( |
450
|
|
|
$this->id, |
451
|
|
|
$this->firstName, |
452
|
|
|
$this->lastName, |
453
|
|
|
$this->email, |
454
|
|
|
$this->enabled) = unserialize($serialized); |
455
|
|
|
} |
456
|
|
|
} |
457
|
|
|
|