1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Application\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use Symfony\Component\Security\Core\User\AdvancedUserInterface; |
8
|
|
|
use Symfony\Component\Security\Core\Encoder\EncoderFactory; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* User Entity. |
12
|
|
|
* |
13
|
|
|
* @ORM\Table(name="users") |
14
|
|
|
* @ORM\Entity(repositoryClass="Application\Repository\UserRepository") |
15
|
|
|
* @ORM\HasLifecycleCallbacks() |
16
|
|
|
* |
17
|
|
|
* @author Borut Balažek <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class UserEntity implements AdvancedUserInterface, \Serializable |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var int |
23
|
|
|
* |
24
|
|
|
* @ORM\Column(name="id", type="integer") |
25
|
|
|
* @ORM\Id |
26
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY") |
27
|
|
|
*/ |
28
|
|
|
protected $id; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* What is the locale for this user? |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
* |
35
|
|
|
* @ORM\Column(name="locale", type="string", length=8, nullable=true) |
36
|
|
|
*/ |
37
|
|
|
protected $locale = 'en_US'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
* |
42
|
|
|
* @ORM\Column(name="username", type="string", length=64, unique=true) |
43
|
|
|
*/ |
44
|
|
|
protected $username; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
* |
49
|
|
|
* @ORM\Column(name="email", type="string", length=64, unique=true) |
50
|
|
|
*/ |
51
|
|
|
protected $email; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var array |
55
|
|
|
* |
56
|
|
|
* @ORM\Column(name="roles", type="json_array", nullable=true) |
57
|
|
|
*/ |
58
|
|
|
protected $roles; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var string |
62
|
|
|
* |
63
|
|
|
* @ORM\Column(name="password", type="string", length=255) |
64
|
|
|
*/ |
65
|
|
|
protected $password; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Used only when saving the user. |
69
|
|
|
* |
70
|
|
|
* @var string |
71
|
|
|
*/ |
72
|
|
|
protected $plainPassword; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Used only when saving a new password. |
76
|
|
|
* |
77
|
|
|
* @var string |
78
|
|
|
*/ |
79
|
|
|
protected $oldPassword; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var string |
83
|
|
|
* |
84
|
|
|
* @ORM\Column(name="salt", type="string", length=255, nullable=true) |
85
|
|
|
*/ |
86
|
|
|
protected $salt; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Used for emails & co. |
90
|
|
|
* |
91
|
|
|
* @var string |
92
|
|
|
* |
93
|
|
|
* @ORM\Column(name="token", type="string", length=255, nullable=true) |
94
|
|
|
*/ |
95
|
|
|
protected $token; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Used for authentification & co. |
99
|
|
|
* |
100
|
|
|
* @var string |
101
|
|
|
* |
102
|
|
|
* @ORM\Column(name="access_token", type="string", length=255, nullable=true) |
103
|
|
|
*/ |
104
|
|
|
protected $accessToken; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @var bool |
108
|
|
|
* |
109
|
|
|
* @ORM\Column(name="enabled", type="boolean") |
110
|
|
|
*/ |
111
|
|
|
protected $enabled = true; |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @var bool |
115
|
|
|
* |
116
|
|
|
* @ORM\Column(name="locked", type="boolean") |
117
|
|
|
*/ |
118
|
|
|
protected $locked = false; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @var string |
122
|
|
|
* |
123
|
|
|
* @ORM\Column(name="reset_password_code", type="string", length=255, nullable=true, unique=true) |
124
|
|
|
*/ |
125
|
|
|
protected $resetPasswordCode; |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @var string |
129
|
|
|
* |
130
|
|
|
* @ORM\Column(name="activation_code", type="string", length=255, nullable=true, unique=true) |
131
|
|
|
*/ |
132
|
|
|
protected $activationCode; |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @var \DateTime |
136
|
|
|
* |
137
|
|
|
* @ORM\Column(name="time_last_active", type="datetime", nullable=true) |
138
|
|
|
*/ |
139
|
|
|
protected $timeLastActive; |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @var \DateTime |
143
|
|
|
* |
144
|
|
|
* @ORM\Column(name="time_created", type="datetime") |
145
|
|
|
*/ |
146
|
|
|
protected $timeCreated; |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @var \DateTime |
150
|
|
|
* |
151
|
|
|
* @ORM\Column(name="time_updated", type="datetime") |
152
|
|
|
*/ |
153
|
|
|
protected $timeUpdated; |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @ORM\OneToOne(targetEntity="Application\Entity\ProfileEntity", mappedBy="user", cascade={"all"}) |
157
|
|
|
**/ |
158
|
|
|
protected $profile; |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @var ArrayCollection |
162
|
|
|
* |
163
|
|
|
* @ORM\OneToMany(targetEntity="Application\Entity\PostEntity", mappedBy="user", cascade={"all"}) |
164
|
|
|
*/ |
165
|
|
|
protected $posts; |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @var ArrayCollection |
169
|
|
|
* |
170
|
|
|
* @ORM\OneToMany(targetEntity="Application\Entity\UserActionEntity", mappedBy="user", cascade={"all"}) |
171
|
|
|
*/ |
172
|
|
|
protected $userActions; |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Otherwise known as: userExpired / accountExpired. |
176
|
|
|
* |
177
|
|
|
* @var bool |
178
|
|
|
*/ |
179
|
|
|
protected $expired = false; |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @var bool |
183
|
|
|
*/ |
184
|
|
|
protected $credentialsExpired = false; |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* The constructor. |
188
|
|
|
*/ |
189
|
|
|
public function __construct() |
190
|
|
|
{ |
191
|
|
|
$this->setSalt( |
192
|
|
|
md5(uniqid(null, true)) |
193
|
|
|
); |
194
|
|
|
|
195
|
|
|
$this->setToken( |
196
|
|
|
md5(uniqid(null, true)) |
197
|
|
|
); |
198
|
|
|
|
199
|
|
|
$this->setAccessToken( |
200
|
|
|
md5(uniqid(null, true)) |
201
|
|
|
); |
202
|
|
|
|
203
|
|
|
$this->setActivationCode( |
204
|
|
|
md5(uniqid(null, true)) |
205
|
|
|
); |
206
|
|
|
|
207
|
|
|
$this->setResetPasswordCode( |
208
|
|
|
md5(uniqid(null, true)) |
209
|
|
|
); |
210
|
|
|
|
211
|
|
|
$this->posts = new ArrayCollection(); |
212
|
|
|
$this->userActions = new ArrayCollection(); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/*** Id ***/ |
216
|
|
|
/** |
217
|
|
|
* @return int |
218
|
|
|
*/ |
219
|
|
|
public function getId() |
220
|
|
|
{ |
221
|
|
|
return $this->id; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @param int $id |
226
|
|
|
* |
227
|
|
|
* @return UserEntity |
228
|
|
|
*/ |
229
|
|
|
public function setId($id) |
230
|
|
|
{ |
231
|
|
|
$this->id = $id; |
232
|
|
|
|
233
|
|
|
return $this; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/*** Locale ***/ |
237
|
|
|
/** |
238
|
|
|
* @return string |
239
|
|
|
*/ |
240
|
|
|
public function getLocale() |
241
|
|
|
{ |
242
|
|
|
return $this->locale; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @param string $locale |
247
|
|
|
* |
248
|
|
|
* @return UserEntity |
249
|
|
|
*/ |
250
|
|
|
public function setLocale($locale) |
251
|
|
|
{ |
252
|
|
|
$this->locale = $locale; |
253
|
|
|
|
254
|
|
|
return $this; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/*** Username ***/ |
258
|
|
|
/** |
259
|
|
|
* @return string |
260
|
|
|
*/ |
261
|
|
|
public function getUsername() |
262
|
|
|
{ |
263
|
|
|
return $this->username; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @param string $username |
268
|
|
|
* |
269
|
|
|
* @return UserEntity |
270
|
|
|
*/ |
271
|
|
|
public function setUsername($username) |
272
|
|
|
{ |
273
|
|
|
$this->username = $username; |
274
|
|
|
|
275
|
|
|
return $this; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/*** Email ***/ |
279
|
|
|
/** |
280
|
|
|
* @return string |
281
|
|
|
*/ |
282
|
|
|
public function getEmail() |
283
|
|
|
{ |
284
|
|
|
return $this->email; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @param string $email |
289
|
|
|
* |
290
|
|
|
* @return UserEntity |
291
|
|
|
*/ |
292
|
|
|
public function setEmail($email) |
293
|
|
|
{ |
294
|
|
|
$this->email = $email; |
295
|
|
|
|
296
|
|
|
return $this; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/*** Password ***/ |
300
|
|
|
/** |
301
|
|
|
* @return string |
302
|
|
|
*/ |
303
|
|
|
public function getPassword() |
304
|
|
|
{ |
305
|
|
|
return $this->password; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* @param string $password |
310
|
|
|
* |
311
|
|
|
* @return UserEntity |
312
|
|
|
*/ |
313
|
|
|
public function setPassword($password) |
314
|
|
|
{ |
315
|
|
|
if ($password) { |
316
|
|
|
$this->password = $password; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
return $this; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/*** Plain password ***/ |
323
|
|
|
/** |
324
|
|
|
* @return string |
325
|
|
|
*/ |
326
|
|
|
public function getPlainPassword() |
327
|
|
|
{ |
328
|
|
|
return $this->plainPassword; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* @param string $plainPassword |
333
|
|
|
* @param EncoderFactory $encoderFactory |
334
|
|
|
* |
335
|
|
|
* @return UserEntity |
336
|
|
|
*/ |
337
|
|
|
public function setPlainPassword($plainPassword, EncoderFactory $encoderFactory = null) |
338
|
|
|
{ |
339
|
|
|
$this->plainPassword = $plainPassword; |
340
|
|
|
|
341
|
|
|
if ($encoderFactory) { |
342
|
|
|
$encoder = $encoderFactory->getEncoder($this); |
343
|
|
|
|
344
|
|
|
$password = $encoder->encodePassword( |
345
|
|
|
$this->getPlainPassword(), |
346
|
|
|
$this->getSalt() |
347
|
|
|
); |
348
|
|
|
|
349
|
|
|
$this->setPassword($password); |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
return $this; |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/*** Old password ***/ |
356
|
|
|
/** |
357
|
|
|
* @return string |
358
|
|
|
*/ |
359
|
|
|
public function getOldPassword() |
360
|
|
|
{ |
361
|
|
|
return $this->oldPassword; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* @param string $oldPassword |
366
|
|
|
* |
367
|
|
|
* @return UserEntity |
368
|
|
|
*/ |
369
|
|
|
public function setOldPassword($oldPassword) |
370
|
|
|
{ |
371
|
|
|
$this->oldPassword = $oldPassword; |
372
|
|
|
|
373
|
|
|
return $this; |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
/*** Salt ***/ |
377
|
|
|
/** |
378
|
|
|
* @return string |
379
|
|
|
*/ |
380
|
|
|
public function getSalt() |
381
|
|
|
{ |
382
|
|
|
return $this->salt; |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
/** |
386
|
|
|
* @param string $salt |
387
|
|
|
* |
388
|
|
|
* @return UserEntity |
389
|
|
|
*/ |
390
|
|
|
public function setSalt($salt) |
391
|
|
|
{ |
392
|
|
|
$this->salt = $salt; |
393
|
|
|
|
394
|
|
|
return $this; |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/*** Token ***/ |
398
|
|
|
/** |
399
|
|
|
* @return string |
400
|
|
|
*/ |
401
|
|
|
public function getToken() |
402
|
|
|
{ |
403
|
|
|
return $this->token; |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
/** |
407
|
|
|
* @param string $token |
408
|
|
|
* |
409
|
|
|
* @return UserEntity |
410
|
|
|
*/ |
411
|
|
|
public function setToken($token) |
412
|
|
|
{ |
413
|
|
|
$this->token = $token; |
414
|
|
|
|
415
|
|
|
return $this; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/*** Access Token ***/ |
419
|
|
|
/** |
420
|
|
|
* @return string |
421
|
|
|
*/ |
422
|
|
|
public function getAccessToken() |
423
|
|
|
{ |
424
|
|
|
return $this->accessToken; |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
/** |
428
|
|
|
* @param string $accessToken |
429
|
|
|
* |
430
|
|
|
* @return UserEntity |
431
|
|
|
*/ |
432
|
|
|
public function setAccessToken($accessToken) |
433
|
|
|
{ |
434
|
|
|
$this->accessToken = $accessToken; |
435
|
|
|
|
436
|
|
|
return $this; |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
/*** Enabled ***/ |
440
|
|
|
/** |
441
|
|
|
* @return bool |
442
|
|
|
*/ |
443
|
|
|
public function getEnabled() |
444
|
|
|
{ |
445
|
|
|
return $this->enabled; |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
/** |
449
|
|
|
* @return bool |
450
|
|
|
*/ |
451
|
|
|
public function isEnabled() |
452
|
|
|
{ |
453
|
|
|
return $this->getEnabled(); |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
/** |
457
|
|
|
* @param bool $enabled |
458
|
|
|
*/ |
459
|
|
|
public function setEnabled($enabled) |
460
|
|
|
{ |
461
|
|
|
$this->enabled = $enabled; |
462
|
|
|
|
463
|
|
|
return $this; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* @return UserEntity |
468
|
|
|
*/ |
469
|
|
|
public function enable() |
470
|
|
|
{ |
471
|
|
|
$this->setEnabled(true); |
472
|
|
|
|
473
|
|
|
return $this; |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
/** |
477
|
|
|
* @return UserEntity |
478
|
|
|
*/ |
479
|
|
|
public function disable() |
480
|
|
|
{ |
481
|
|
|
$this->setEnabled(false); |
482
|
|
|
|
483
|
|
|
return $this; |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
/*** Locked ***/ |
487
|
|
|
/** |
488
|
|
|
* @return bool |
489
|
|
|
*/ |
490
|
|
|
public function getLocked() |
491
|
|
|
{ |
492
|
|
|
return $this->locked; |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
/** |
496
|
|
|
* @return bool |
497
|
|
|
*/ |
498
|
|
|
public function isLocked() |
499
|
|
|
{ |
500
|
|
|
return $this->getLocked(); |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
/** |
504
|
|
|
* @param bool $locked |
505
|
|
|
* |
506
|
|
|
* @return UserEntity |
507
|
|
|
*/ |
508
|
|
|
public function setLocked($locked) |
509
|
|
|
{ |
510
|
|
|
$this->locked = $locked; |
511
|
|
|
|
512
|
|
|
return $this; |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
/** |
516
|
|
|
* @return UserEntity |
517
|
|
|
*/ |
518
|
|
|
public function lock() |
519
|
|
|
{ |
520
|
|
|
$this->setLocked(true); |
521
|
|
|
|
522
|
|
|
return $this; |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
/** |
526
|
|
|
* @return bool |
527
|
|
|
*/ |
528
|
|
|
public function isAccountNonLocked() |
529
|
|
|
{ |
530
|
|
|
return !$this->isLocked(); |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
/*** Reset password code ***/ |
534
|
|
|
/** |
535
|
|
|
* @return string |
536
|
|
|
*/ |
537
|
|
|
public function getResetPasswordCode() |
538
|
|
|
{ |
539
|
|
|
return $this->resetPasswordCode; |
540
|
|
|
} |
541
|
|
|
|
542
|
|
|
/** |
543
|
|
|
* @param string $resetPasswordCode |
544
|
|
|
* |
545
|
|
|
* @return UserEntity |
546
|
|
|
*/ |
547
|
|
|
public function setResetPasswordCode($resetPasswordCode) |
548
|
|
|
{ |
549
|
|
|
$this->resetPasswordCode = $resetPasswordCode; |
550
|
|
|
|
551
|
|
|
return $this; |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
/*** Activation code ***/ |
555
|
|
|
/** |
556
|
|
|
* @return string |
557
|
|
|
*/ |
558
|
|
|
public function getActivationCode() |
559
|
|
|
{ |
560
|
|
|
return $this->activationCode; |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
/** |
564
|
|
|
* @param string $activationCode |
565
|
|
|
* |
566
|
|
|
* @return UserEntity |
567
|
|
|
*/ |
568
|
|
|
public function setActivationCode($activationCode) |
569
|
|
|
{ |
570
|
|
|
$this->activationCode = $activationCode; |
571
|
|
|
|
572
|
|
|
return $this; |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
/*** Time last active ***/ |
576
|
|
|
/** |
577
|
|
|
* @return \DateTime |
578
|
|
|
*/ |
579
|
|
|
public function getTimeLastActive() |
580
|
|
|
{ |
581
|
|
|
return $this->timeLastActive; |
582
|
|
|
} |
583
|
|
|
|
584
|
|
|
/** |
585
|
|
|
* @param $timeLastActive |
586
|
|
|
* |
587
|
|
|
* @return UserEntity |
588
|
|
|
*/ |
589
|
|
|
public function setTimeLastActive(\Datetime $timeLastActive = null) |
590
|
|
|
{ |
591
|
|
|
$this->timeLastActive = $timeLastActive; |
592
|
|
|
|
593
|
|
|
return $this; |
594
|
|
|
} |
595
|
|
|
|
596
|
|
|
/*** Time created ***/ |
597
|
|
|
/** |
598
|
|
|
* @return \DateTime |
599
|
|
|
*/ |
600
|
|
|
public function getTimeCreated() |
601
|
|
|
{ |
602
|
|
|
return $this->timeCreated; |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
/** |
606
|
|
|
* @param \DateTime $timeCreated |
607
|
|
|
* |
608
|
|
|
* @return UserEntity |
609
|
|
|
*/ |
610
|
|
|
public function setTimeCreated(\Datetime $timeCreated) |
611
|
|
|
{ |
612
|
|
|
$this->timeCreated = $timeCreated; |
613
|
|
|
|
614
|
|
|
return $this; |
615
|
|
|
} |
616
|
|
|
|
617
|
|
|
/*** Time updated ***/ |
618
|
|
|
/** |
619
|
|
|
* @return \DateTime |
620
|
|
|
*/ |
621
|
|
|
public function getTimeUpdated() |
622
|
|
|
{ |
623
|
|
|
return $this->timeUpdated; |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
/** |
627
|
|
|
* @param \DateTime $timeUpdated |
628
|
|
|
* |
629
|
|
|
* @return UserEntity |
630
|
|
|
*/ |
631
|
|
|
public function setTimeUpdated(\DateTime $timeUpdated) |
632
|
|
|
{ |
633
|
|
|
$this->timeUpdated = $timeUpdated; |
634
|
|
|
|
635
|
|
|
return $this; |
636
|
|
|
} |
637
|
|
|
|
638
|
|
|
/*** Expired ***/ |
639
|
|
|
/** |
640
|
|
|
* @return bool |
641
|
|
|
*/ |
642
|
|
|
public function getExpired() |
643
|
|
|
{ |
644
|
|
|
return $this->expired; |
645
|
|
|
} |
646
|
|
|
|
647
|
|
|
/** |
648
|
|
|
* @return bool |
649
|
|
|
*/ |
650
|
|
|
public function isExpired() |
651
|
|
|
{ |
652
|
|
|
return $this->getExpired(); |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
/** |
656
|
|
|
* @return bool |
657
|
|
|
*/ |
658
|
|
|
public function isAccountNonExpired() |
659
|
|
|
{ |
660
|
|
|
return !$this->getExpired(); |
661
|
|
|
} |
662
|
|
|
|
663
|
|
|
/*** Credentials expired ***/ |
664
|
|
|
/** |
665
|
|
|
* @return bool |
666
|
|
|
*/ |
667
|
|
|
public function getCredentialsExpired() |
668
|
|
|
{ |
669
|
|
|
return $this->credentialsExpired; |
670
|
|
|
} |
671
|
|
|
|
672
|
|
|
/** |
673
|
|
|
* @return bool |
674
|
|
|
*/ |
675
|
|
|
public function isCredentialsExpired() |
676
|
|
|
{ |
677
|
|
|
return $this->getCredentialsExpired(); |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
/** |
681
|
|
|
* @return bool |
682
|
|
|
*/ |
683
|
|
|
public function isCredentialsNonExpired() |
684
|
|
|
{ |
685
|
|
|
return !$this->getExpired(); |
686
|
|
|
} |
687
|
|
|
|
688
|
|
|
/*** Roles ***/ |
689
|
|
|
/** |
690
|
|
|
* @return array |
691
|
|
|
*/ |
692
|
|
|
public function getRoles() |
693
|
|
|
{ |
694
|
|
|
$roles = is_array($this->roles) |
695
|
|
|
? $this->roles |
696
|
|
|
: array() |
697
|
|
|
; |
698
|
|
|
$roles[] = 'ROLE_USER'; |
699
|
|
|
|
700
|
|
|
return (array) array_unique($roles, SORT_REGULAR); |
701
|
|
|
} |
702
|
|
|
|
703
|
|
|
/** |
704
|
|
|
* @param array $roles |
705
|
|
|
* |
706
|
|
|
* @return UserEntity |
707
|
|
|
*/ |
708
|
|
|
public function setRoles(array $roles) |
709
|
|
|
{ |
710
|
|
|
$this->roles = $roles; |
711
|
|
|
|
712
|
|
|
return $this; |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
/** |
716
|
|
|
* @param string $role |
717
|
|
|
* |
718
|
|
|
* @return bool |
719
|
|
|
*/ |
720
|
|
|
public function hasRole($role) |
721
|
|
|
{ |
722
|
|
|
return in_array( |
723
|
|
|
$role, |
724
|
|
|
$this->getRoles() |
725
|
|
|
); |
726
|
|
|
} |
727
|
|
|
|
728
|
|
|
/*** Profile ***/ |
729
|
|
|
/** |
730
|
|
|
* @return ProfileEntity |
731
|
|
|
*/ |
732
|
|
|
public function getProfile() |
733
|
|
|
{ |
734
|
|
|
return $this->profile; |
735
|
|
|
} |
736
|
|
|
|
737
|
|
|
/** |
738
|
|
|
* @param ProfileEntity $profile |
739
|
|
|
* |
740
|
|
|
* @return UserEntity |
741
|
|
|
*/ |
742
|
|
|
public function setProfile(ProfileEntity $profile) |
743
|
|
|
{ |
744
|
|
|
$this->profile = $profile; |
745
|
|
|
|
746
|
|
|
$this->getProfile()->setUser($this); |
747
|
|
|
|
748
|
|
|
return $this; |
749
|
|
|
} |
750
|
|
|
|
751
|
|
|
/*** Posts ***/ |
752
|
|
|
/** |
753
|
|
|
* @return array |
754
|
|
|
*/ |
755
|
|
|
public function getPosts() |
756
|
|
|
{ |
757
|
|
|
return $this->posts->toArray(); |
758
|
|
|
} |
759
|
|
|
|
760
|
|
|
/** |
761
|
|
|
* @param ArrayCollection $posts |
762
|
|
|
* |
763
|
|
|
* @return UserEntity |
764
|
|
|
*/ |
765
|
|
|
public function setPosts($posts) |
766
|
|
|
{ |
767
|
|
|
$this->posts = $posts; |
768
|
|
|
|
769
|
|
|
return $this; |
770
|
|
|
} |
771
|
|
|
|
772
|
|
|
/*** User actions ***/ |
773
|
|
|
/** |
774
|
|
|
* @return array |
775
|
|
|
*/ |
776
|
|
|
public function getUserActions() |
777
|
|
|
{ |
778
|
|
|
return $this->userActions->toArray(); |
779
|
|
|
} |
780
|
|
|
|
781
|
|
|
/** |
782
|
|
|
* @param $userActions |
783
|
|
|
* |
784
|
|
|
* @return UserEntity |
785
|
|
|
*/ |
786
|
|
|
public function setUserActions($userActions) |
787
|
|
|
{ |
788
|
|
|
$this->userActions = $userActions; |
789
|
|
|
|
790
|
|
|
return $this; |
791
|
|
|
} |
792
|
|
|
|
793
|
|
|
/** |
794
|
|
|
* @param AdvancedUserInterface $user |
795
|
|
|
* |
796
|
|
|
* @return bool |
797
|
|
|
*/ |
798
|
|
|
public function isEqualTo(AdvancedUserInterface $user) |
799
|
|
|
{ |
800
|
|
|
if (!($user instanceof AdvancedUserInterface)) { |
801
|
|
|
return false; |
802
|
|
|
} |
803
|
|
|
|
804
|
|
|
if ($this->getPassword() !== $user->getPassword()) { |
805
|
|
|
return false; |
806
|
|
|
} |
807
|
|
|
|
808
|
|
|
if ($this->getSalt() !== $user->getSalt()) { |
809
|
|
|
return false; |
810
|
|
|
} |
811
|
|
|
|
812
|
|
|
if ($this->getUsername() !== $user->getUsername()) { |
813
|
|
|
return false; |
814
|
|
|
} |
815
|
|
|
|
816
|
|
|
return true; |
817
|
|
|
} |
818
|
|
|
|
819
|
|
|
/** |
820
|
|
|
*/ |
821
|
|
|
public function eraseCredentials() |
822
|
|
|
{ |
823
|
|
|
$this->setPlainPassword(null); |
824
|
|
|
} |
825
|
|
|
|
826
|
|
|
/** |
827
|
|
|
* @return string |
828
|
|
|
*/ |
829
|
|
|
public function serialize() |
830
|
|
|
{ |
831
|
|
|
return serialize(array( |
832
|
|
|
$this->id, |
833
|
|
|
$this->username, |
834
|
|
|
$this->email, |
835
|
|
|
$this->password, |
836
|
|
|
$this->salt, |
837
|
|
|
)); |
838
|
|
|
} |
839
|
|
|
|
840
|
|
|
/** |
841
|
|
|
*/ |
842
|
|
|
public function unserialize($serialized) |
843
|
|
|
{ |
844
|
|
|
list( |
845
|
|
|
$this->id, |
846
|
|
|
$this->username, |
847
|
|
|
$this->email, |
848
|
|
|
$this->password, |
849
|
|
|
$this->salt) = unserialize($serialized); |
850
|
|
|
} |
851
|
|
|
|
852
|
|
|
/** |
853
|
|
|
* @return string |
854
|
|
|
*/ |
855
|
|
|
public function __toString() |
856
|
|
|
{ |
857
|
|
|
return $this->getUsername(); |
858
|
|
|
} |
859
|
|
|
|
860
|
|
|
/** |
861
|
|
|
* @param $allData Show all the data for this user. |
862
|
|
|
* |
863
|
|
|
* @return array |
864
|
|
|
*/ |
865
|
|
|
public function toArray($allData = true) |
866
|
|
|
{ |
867
|
|
|
$data = array( |
868
|
|
|
'username' => $this->getUsername(), |
869
|
|
|
'email' => $this->getEmail(), |
870
|
|
|
'title' => $this->getProfile()->getTitle(), |
871
|
|
|
'first_name' => $this->getProfile()->getFirstName(), |
872
|
|
|
'middle_name' => $this->getProfile()->getMiddleName(), |
873
|
|
|
'last_name' => $this->getProfile()->getLastName(), |
874
|
|
|
'full_name' => $this->getProfile()->getFullName(), |
875
|
|
|
'gender' => $this->getProfile()->getGender(), |
876
|
|
|
'birthdate' => $this->getProfile()->getBirthdate()->format('Y-m-d'), |
877
|
|
|
'image_url' => $this->getProfile()->getImageUrl(), |
878
|
|
|
); |
879
|
|
|
|
880
|
|
|
if ($allData) { |
881
|
|
|
$data = array_merge($data, array( |
882
|
|
|
'id' => $this->getId(), |
883
|
|
|
'time_created' => $this->getTimeCreated()->format(DATE_ATOM), |
884
|
|
|
)); |
885
|
|
|
} |
886
|
|
|
|
887
|
|
|
return $data; |
888
|
|
|
} |
889
|
|
|
|
890
|
|
|
/** |
891
|
|
|
* @ORM\PreUpdate |
892
|
|
|
*/ |
893
|
|
|
public function preUpdate() |
894
|
|
|
{ |
895
|
|
|
$this->setTimeUpdated(new \DateTime('now')); |
896
|
|
|
} |
897
|
|
|
|
898
|
|
|
/** |
899
|
|
|
* @ORM\PrePersist |
900
|
|
|
*/ |
901
|
|
|
public function prePersist() |
902
|
|
|
{ |
903
|
|
|
$this->setTimeUpdated(new \DateTime('now')); |
904
|
|
|
$this->setTimeCreated(new \DateTime('now')); |
905
|
|
|
} |
906
|
|
|
} |
907
|
|
|
|