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({"Short"}) |
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({"Short"}) |
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({"Short"}) |
64
|
|
|
*/ |
65
|
|
|
private $lastName; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var string |
69
|
|
|
* @Assert\Image() |
70
|
|
|
* @ORM\Column(type="string", nullable=true) |
71
|
|
|
*/ |
72
|
|
|
private $image; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var string |
76
|
|
|
* @Assert\NotBlank() |
77
|
|
|
* @Assert\Email( |
78
|
|
|
* checkMX = true |
79
|
|
|
* ) |
80
|
|
|
* @Assert\Type("string") |
81
|
|
|
* @Assert\Length( |
82
|
|
|
* max = 250 |
83
|
|
|
* ) |
84
|
|
|
* @ORM\Column(type="string", length=250, unique=true) |
85
|
|
|
* @Groups({"Short"}) |
86
|
|
|
*/ |
87
|
|
|
private $email; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @var string |
91
|
|
|
* @ORM\Column(type="string", length=255) |
92
|
|
|
*/ |
93
|
|
|
private $password; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @var string |
97
|
|
|
* @Assert\Type("string") |
98
|
|
|
* @Assert\Length( |
99
|
|
|
* max = 255 |
100
|
|
|
* ) |
101
|
|
|
* @Assert\NotBlank(groups={"registration"}) |
102
|
|
|
*/ |
103
|
|
|
private $plainPassword; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @var bool |
107
|
|
|
* @ORM\Column(type="boolean") |
108
|
|
|
* @Groups({"Short"}) |
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
|
|
|
*/ |
129
|
|
|
private $events; |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @var ArrayCollection[FormRequest] |
133
|
|
|
* @ORM\OneToMany(targetEntity="FormRequest", mappedBy="user") |
134
|
|
|
*/ |
135
|
|
|
private $formRequests; |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @var ArrayCollection[Survey] |
139
|
|
|
* @ORM\OneToMany(targetEntity="Survey", mappedBy="user") |
140
|
|
|
*/ |
141
|
|
|
private $surveys; |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @var ArrayCollection[SurveyAnswer] |
145
|
|
|
* @ORM\OneToMany(targetEntity="SurveyAnswer", mappedBy="user") |
146
|
|
|
*/ |
147
|
|
|
private $answers; |
148
|
|
|
|
149
|
1 |
|
public function __construct() |
150
|
|
|
{ |
151
|
1 |
|
$this->events = new ArrayCollection(); |
152
|
1 |
|
$this->formRequests = new ArrayCollection(); |
153
|
1 |
|
$this->surveys = new ArrayCollection(); |
154
|
1 |
|
$this->answers = new ArrayCollection(); |
155
|
1 |
|
$this->roles = array('ROLE_USER'); |
156
|
1 |
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Get id. |
160
|
|
|
* |
161
|
|
|
* @return int |
162
|
|
|
*/ |
163
|
4 |
|
public function getId() |
164
|
|
|
{ |
165
|
4 |
|
return $this->id; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Get name. |
170
|
|
|
* |
171
|
|
|
* @return string |
172
|
|
|
*/ |
173
|
1 |
|
public function getUsername() |
174
|
|
|
{ |
175
|
1 |
|
return $this->email; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Set firstname. |
180
|
|
|
* |
181
|
|
|
* @param string $name |
182
|
|
|
* |
183
|
|
|
* @return User |
184
|
|
|
*/ |
185
|
2 |
|
public function setFirstName($name) |
186
|
|
|
{ |
187
|
2 |
|
$this->firstName = $name; |
188
|
|
|
|
189
|
2 |
|
return $this; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Get first name. |
194
|
|
|
* |
195
|
|
|
* @return string |
196
|
|
|
*/ |
197
|
5 |
|
public function getFirstName() |
198
|
|
|
{ |
199
|
5 |
|
return $this->firstName; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Set lastName. |
204
|
|
|
* |
205
|
|
|
* @param string $lastName |
206
|
|
|
* |
207
|
|
|
* @return User |
208
|
|
|
*/ |
209
|
2 |
|
public function setLastName($lastName) |
210
|
|
|
{ |
211
|
2 |
|
$this->lastName = $lastName; |
212
|
|
|
|
213
|
2 |
|
return $this; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Get lastName. |
218
|
|
|
* |
219
|
|
|
* @return string |
220
|
|
|
*/ |
221
|
5 |
|
public function getLastName() |
222
|
|
|
{ |
223
|
5 |
|
return $this->lastName; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Set image. |
228
|
|
|
* |
229
|
|
|
* @param string $image |
230
|
|
|
* |
231
|
|
|
* @return User |
232
|
|
|
*/ |
233
|
|
|
public function setImage($image) |
234
|
|
|
{ |
235
|
|
|
$this->image = $image; |
236
|
|
|
|
237
|
|
|
return $this; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Get image. |
242
|
|
|
* |
243
|
|
|
* @return string |
244
|
|
|
*/ |
245
|
1 |
|
public function getImage() |
246
|
|
|
{ |
247
|
1 |
|
return $this->image; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Set email. |
252
|
|
|
* |
253
|
|
|
* @param string $email |
254
|
|
|
* |
255
|
|
|
* @return User |
256
|
|
|
*/ |
257
|
2 |
|
public function setEmail($email) |
258
|
|
|
{ |
259
|
2 |
|
$this->email = $email; |
260
|
|
|
|
261
|
2 |
|
return $this; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Get email. |
266
|
|
|
* |
267
|
|
|
* @return string |
268
|
|
|
*/ |
269
|
5 |
|
public function getEmail() |
270
|
|
|
{ |
271
|
5 |
|
return $this->email; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* Set password. |
276
|
|
|
* |
277
|
|
|
* @param string $password |
278
|
|
|
* |
279
|
|
|
* @return User |
280
|
|
|
*/ |
281
|
2 |
|
public function setPassword($password) |
282
|
|
|
{ |
283
|
2 |
|
$this->password = $password; |
284
|
|
|
|
285
|
2 |
|
return $this; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* Get password. |
290
|
|
|
* |
291
|
|
|
* @return string |
292
|
|
|
*/ |
293
|
1 |
|
public function getPassword() |
294
|
|
|
{ |
295
|
1 |
|
return $this->password; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @return string |
300
|
|
|
*/ |
301
|
4 |
|
public function getPlainPassword() |
302
|
|
|
{ |
303
|
4 |
|
return $this->plainPassword; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* @param string $plainPassword |
308
|
|
|
*/ |
309
|
3 |
|
public function setPlainPassword($plainPassword) |
310
|
|
|
{ |
311
|
3 |
|
$this->plainPassword = $plainPassword; |
312
|
3 |
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* @param mixed $roles |
316
|
|
|
*/ |
317
|
|
|
public function setRoles($roles) |
318
|
|
|
{ |
319
|
|
|
$this->roles = $roles; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* @return mixed |
324
|
|
|
*/ |
325
|
1 |
|
public function getRoles() |
326
|
|
|
{ |
327
|
1 |
|
return $this->roles; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* Set api token. |
332
|
|
|
* |
333
|
|
|
* @param string $apiToken |
334
|
|
|
* |
335
|
|
|
* @return User |
336
|
|
|
*/ |
337
|
1 |
|
public function setApiToken($apiToken) |
338
|
|
|
{ |
339
|
1 |
|
$this->apiToken = $apiToken; |
340
|
|
|
|
341
|
1 |
|
return $this; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* @return string |
346
|
|
|
*/ |
347
|
|
|
public function getApiToken() |
348
|
|
|
{ |
349
|
|
|
return $this->apiToken; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* @param Event $event |
354
|
|
|
* |
355
|
|
|
* @return User |
356
|
|
|
*/ |
357
|
|
|
public function setEvent($event) |
358
|
|
|
{ |
359
|
|
|
if (!$this->events->contains($event)) { |
360
|
|
|
$this->events->add($event); |
361
|
|
|
$event->addUser($this); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
return $this; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* @return ArrayCollection |
369
|
|
|
*/ |
370
|
|
|
public function getEvents() |
371
|
|
|
{ |
372
|
|
|
return $this->events; |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
/** |
376
|
|
|
* @return ArrayCollection |
377
|
|
|
*/ |
378
|
|
|
public function getFormRequests() |
379
|
|
|
{ |
380
|
|
|
return $this->formRequests; |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* @return ArrayCollection |
385
|
|
|
*/ |
386
|
|
|
public function getSurveys() |
387
|
|
|
{ |
388
|
|
|
return $this->surveys; |
389
|
|
|
} |
390
|
|
|
/** |
391
|
|
|
* @return ArrayCollection |
392
|
|
|
*/ |
393
|
|
|
public function getAnswers() |
394
|
|
|
{ |
395
|
|
|
return $this->answers; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* Set enabled |
400
|
|
|
* |
401
|
|
|
* @param boolean $enabled |
402
|
|
|
* |
403
|
|
|
* @return User |
404
|
|
|
*/ |
405
|
1 |
|
public function setEnabled(bool $enabled) |
406
|
|
|
{ |
407
|
1 |
|
$this->enabled = $enabled; |
408
|
|
|
|
409
|
1 |
|
return $this; |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* Get enabled |
414
|
|
|
* |
415
|
|
|
* @return boolean |
416
|
|
|
*/ |
417
|
4 |
|
public function isEnabled() |
418
|
|
|
{ |
419
|
4 |
|
return $this->enabled; |
420
|
|
|
} |
421
|
|
|
|
422
|
2 |
|
public function getSalt() |
423
|
|
|
{ |
424
|
|
|
// TODO: Implement getSalt() method. |
425
|
2 |
|
} |
426
|
|
|
|
427
|
1 |
|
public function eraseCredentials() |
428
|
|
|
{ |
429
|
1 |
|
$this->setPlainPassword(null); |
430
|
1 |
|
} |
431
|
|
|
|
432
|
|
|
/** @see \Serializable::serialize() */ |
433
|
|
|
public function serialize() |
434
|
|
|
{ |
435
|
|
|
return serialize(array( |
436
|
|
|
$this->id, |
437
|
|
|
$this->firstName, |
438
|
|
|
$this->lastName, |
439
|
|
|
$this->email, |
440
|
|
|
$this->enabled, |
441
|
|
|
)); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** @see \Serializable::unserialize() */ |
445
|
|
|
public function unserialize($serialized) |
446
|
|
|
{ |
447
|
|
|
list( |
448
|
|
|
$this->id, |
449
|
|
|
$this->firstName, |
450
|
|
|
$this->lastName, |
451
|
|
|
$this->email, |
452
|
|
|
$this->enabled) = unserialize($serialized); |
453
|
|
|
} |
454
|
|
|
} |
455
|
|
|
|