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