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