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