Passed
Push — master ( d3d7f5...b09054 )
by Julito
08:20
created

User::setDateOfBirth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nop 1
dl 0
loc 5
rs 10
nc 1
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Entity;
8
9
use ApiPlatform\Core\Annotation\ApiFilter;
10
use ApiPlatform\Core\Annotation\ApiProperty;
11
use ApiPlatform\Core\Annotation\ApiResource;
12
use ApiPlatform\Core\Annotation\ApiSubresource;
13
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
14
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
15
use Chamilo\CourseBundle\Entity\CGroupRelTutor;
16
use Chamilo\CourseBundle\Entity\CGroupRelUser;
17
use DateTime;
18
use Doctrine\Common\Collections\ArrayCollection;
19
use Doctrine\Common\Collections\Collection;
20
use Doctrine\Common\Collections\Criteria;
21
use Doctrine\ORM\Mapping as ORM;
22
use Gedmo\Timestampable\Traits\TimestampableEntity;
23
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
24
use Symfony\Component\Security\Core\User\EquatableInterface;
25
use Symfony\Component\Security\Core\User\UserInterface;
26
use Symfony\Component\Serializer\Annotation\Groups;
27
use Symfony\Component\Uid\NilUuid;
28
use Symfony\Component\Uid\Uuid;
29
use Symfony\Component\Uid\UuidV4;
30
use Symfony\Component\Validator\Constraints as Assert;
31
use Symfony\Component\Validator\Mapping\ClassMetadata;
32
use UserManager;
33
34
/**
35
 * @ApiResource(
36
 *     attributes={"security"="is_granted('ROLE_ADMIN')"},
37
 *     iri="http://schema.org/Person",
38
 *     normalizationContext={"groups"={"user:read"}},
39
 *     denormalizationContext={"groups"={"user:write"}},
40
 *     collectionOperations={
41
 *         "get"={"security"="is_granted('ROLE_ADMIN')"},
42
 *         "post"={}
43
 *     },
44
 *     itemOperations={
45
 *         "get"={"security"="is_granted('ROLE_ADMIN')"},
46
 *         "put"={},
47
 *     },
48
 * )
49
 *
50
 * @ApiFilter(SearchFilter::class, properties={"username":"partial", "firstname":"partial", "lastname":"partial"})
51
 * @ApiFilter(BooleanFilter::class, properties={"isActive"})
52
 *
53
 * @ORM\Table(
54
 *     name="user",
55
 *     indexes={
56
 *         @ORM\Index(name="status", columns={"status"})
57
 *     }
58
 * )
59
 * @UniqueEntity("username")
60
 * @ORM\Entity
61
 * @ORM\EntityListeners({"Chamilo\CoreBundle\Entity\Listener\UserListener"})
62
 */
63
class User implements UserInterface, EquatableInterface, ResourceInterface, ResourceIllustrationInterface
64
{
65
    use TimestampableEntity;
66
67
    public const ROLE_DEFAULT = 'ROLE_USER';
68
    public const ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN';
69
    public const COURSE_MANAGER = 1;
70
    public const TEACHER = 1;
71
    public const SESSION_ADMIN = 3;
72
    public const DRH = 4;
73
    public const STUDENT = 5;
74
    public const ANONYMOUS = 6;
75
76
    /**
77
     * @Groups({"user:read", "resource_node:read", "user_json:read"})
78
     * @ORM\Column(name="id", type="integer")
79
     * @ORM\Id
80
     * @ORM\GeneratedValue()
81
     */
82
    protected int $id;
83
84
    /**
85
     * @ORM\Column(name="api_token", type="string", unique=true, nullable=true)
86
     */
87
    protected ?string $apiToken = null;
88
89
    /**
90
     * @Assert\NotBlank()
91
     * @ApiProperty(iri="http://schema.org/name")
92
     * @Groups({"user:read", "user:write", "resource_node:read", "user_json:read"})
93
     * @ORM\Column(name="firstname", type="string", length=64, nullable=true)
94
     */
95
    protected ?string $firstname = null;
96
97
    /**
98
     * @Groups({"user:read", "user:write", "resource_node:read", "user_json:read"})
99
     * @ORM\Column(name="lastname", type="string", length=64, nullable=true)
100
     */
101
    protected ?string $lastname = null;
102
103
    /**
104
     * @Groups({"user:read", "user:write"})
105
     * @ORM\Column(name="website", type="string", length=255, nullable=true)
106
     */
107
    protected ?string $website;
108
109
    /**
110
     * @Groups({"user:read", "user:write"})
111
     * @ORM\Column(name="biography", type="text", nullable=true)
112
     */
113
    protected ?string $biography;
114
115
    /**
116
     * @Groups({"user:read", "user:write", "user_json:read"})
117
     * @ORM\Column(name="locale", type="string", length=8)
118
     */
119
    protected string $locale;
120
121
    /**
122
     * @Groups({"user:read", "user:write", "course:read", "resource_node:read", "user_json:read"})
123
     * @Assert\NotBlank()
124
     * @ORM\Column(name="username", type="string", length=100, unique=true)
125
     */
126
    protected string $username;
127
128
    /**
129
     * @Groups({"user:write"})
130
     */
131
    protected ?string $plainPassword = null;
132
133
    /**
134
     * @ORM\Column(name="password", type="string", length=255)
135
     */
136
    protected string $password;
137
138
    /**
139
     * @ORM\Column(name="username_canonical", type="string", length=180)
140
     */
141
    protected string $usernameCanonical;
142
143
    /**
144
     * @Groups({"user:read", "user:write", "user_json:read"})
145
     * @ORM\Column(name="timezone", type="string", length=64)
146
     */
147
    protected string $timezone;
148
149
    /**
150
     * @ORM\Column(name="email_canonical", type="string", length=100)
151
     */
152
    protected string $emailCanonical;
153
154
    /**
155
     * @Groups({"user:read", "user:write", "user_json:read"})
156
     * @Assert\NotBlank()
157
     * @Assert\Email()
158
     *
159
     * @ORM\Column(name="email", type="string", length=100)
160
     */
161
    protected string $email;
162
163
    /**
164
     * @ORM\Column(name="locked", type="boolean")
165
     */
166
    protected bool $locked;
167
168
    /**
169
     * @Assert\NotBlank()
170
     * @Groups({"user:read", "user:write"})
171
     * @ORM\Column(name="enabled", type="boolean")
172
     */
173
    protected bool $enabled;
174
175
    /**
176
     * @Groups({"user:read", "user:write"})
177
     * @ORM\Column(name="expired", type="boolean")
178
     */
179
    protected bool $expired;
180
181
    /**
182
     * @ORM\Column(name="credentials_expired", type="boolean")
183
     */
184
    protected bool $credentialsExpired;
185
186
    /**
187
     * @ORM\Column(name="credentials_expire_at", type="datetime", nullable=true)
188
     */
189
    protected ?DateTime $credentialsExpireAt;
190
191
    /**
192
     * @ORM\Column(name="date_of_birth", type="datetime", nullable=true)
193
     */
194
    protected ?DateTime $dateOfBirth;
195
196
    /**
197
     * @Groups({"user:read", "user:write"})
198
     * @ORM\Column(name="expires_at", type="datetime", nullable=true)
199
     */
200
    protected ?DateTime $expiresAt;
201
202
    /**
203
     * @Groups({"user:read", "user:write"})
204
     * @ORM\Column(name="phone", type="string", length=64, nullable=true)
205
     */
206
    protected ?string $phone = null;
207
208
    /**
209
     * @Groups({"user:read", "user:write"})
210
     * @ORM\Column(name="address", type="string", length=250, nullable=true)
211
     */
212
    protected ?string $address = null;
213
214
    protected AccessUrl $currentUrl;
215
216
    /**
217
     * @ORM\Column(type="string", length=255)
218
     */
219
    protected string $salt;
220
221
    /**
222
     * @ORM\Column(name="gender", type="string", length=1, nullable=true)
223
     */
224
    protected ?string $gender = null;
225
226
    /**
227
     * @Groups({"user:read"})
228
     * @ORM\Column(name="last_login", type="datetime", nullable=true)
229
     */
230
    protected ?DateTime $lastLogin;
231
232
    /**
233
     * Random string sent to the user email address in order to verify it.
234
     *
235
     * @ORM\Column(name="confirmation_token", type="string", length=255, nullable=true)
236
     */
237
    protected ?string $confirmationToken = null;
238
239
    /**
240
     * @ORM\Column(name="password_requested_at", type="datetime", nullable=true)
241
     */
242
    protected ?DateTime $passwordRequestedAt;
243
244
    /**
245
     * @ApiSubresource
246
     *
247
     * @var Collection<int, CourseRelUser>|CourseRelUser[]
248
     *
249
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CourseRelUser", mappedBy="user", orphanRemoval=true)
250
     */
251
    protected Collection $courses;
252
253
    /**
254
     * @var Collection<int, UsergroupRelUser>|UsergroupRelUser[]
255
     *
256
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\UsergroupRelUser", mappedBy="user")
257
     */
258
    protected Collection $classes;
259
260
    /**
261
     * ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CDropboxPost", mappedBy="user").
262
     */
263
    protected Collection $dropBoxReceivedFiles;
264
265
    /**
266
     * ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CDropboxFile", mappedBy="userSent").
267
     */
268
    protected Collection $dropBoxSentFiles;
269
270
    /**
271
     * An array of roles. Example: ROLE_USER, ROLE_TEACHER, ROLE_ADMIN.
272
     *
273
     * @Groups({"user:read", "user:write", "user_json:read"})
274
     * @ORM\Column(type="array")
275
     *
276
     * @var mixed[]|string[]
277
     */
278
    protected array $roles = [];
279
280
    /**
281
     * @ORM\Column(name="profile_completed", type="boolean", nullable=true)
282
     */
283
    protected ?bool $profileCompleted = null;
284
285
    /**
286
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\JuryMembers", mappedBy="user")
287
     */
288
    //protected $jurySubscriptions;
289
290
    /**
291
     * @var Collection|Group[]
292
     * @ORM\ManyToMany(targetEntity="Chamilo\CoreBundle\Entity\Group", inversedBy="users")
293
     * @ORM\JoinTable(
294
     *     name="fos_user_user_group",
295
     *     joinColumns={
296
     *         @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="cascade")
297
     *     },
298
     *     inverseJoinColumns={
299
     *         @ORM\JoinColumn(name="group_id", referencedColumnName="id")
300
     *     }
301
     * )
302
     */
303
    protected Collection $groups;
304
305
    /**
306
     * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CurriculumItemRelUser", mappedBy="user").
307
     *
308
     * @var Collection|mixed[]
309
     */
310
    protected Collection $curriculumItems;
311
312
    /**
313
     * @var AccessUrlRelUser[]|Collection<int, AccessUrlRelUser>
314
     *
315
     * @ORM\OneToMany(
316
     *     targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelUser",
317
     *     mappedBy="user",
318
     *     cascade={"persist", "remove"},
319
     *     orphanRemoval=true
320
     * )
321
     */
322
    protected Collection $portals;
323
324
    /**
325
     * @var Collection<int, Session>|Session[]
326
     *
327
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Session", mappedBy="generalCoach")
328
     */
329
    protected Collection $sessionsAsGeneralCoach;
330
331
    /**
332
     * @Groups({"user_json:read"})
333
     *
334
     * @ORM\OneToOne(
335
     *     targetEntity="Chamilo\CoreBundle\Entity\ResourceNode", cascade={"remove"}, orphanRemoval=true
336
     * )
337
     * @ORM\JoinColumn(name="resource_node_id", onDelete="CASCADE")
338
     */
339
    protected ?ResourceNode $resourceNode = null;
340
341
    /**
342
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\ResourceNode", mappedBy="creator")
343
     *
344
     * @var Collection<int, ResourceNode>|ResourceNode[]
345
     */
346
    protected Collection $resourceNodes;
347
348
    /**
349
     * @var Collection<int, SessionRelCourseRelUser>|SessionRelCourseRelUser[]
350
     *
351
     * @ORM\OneToMany(
352
     *     targetEntity="Chamilo\CoreBundle\Entity\SessionRelCourseRelUser",
353
     *     mappedBy="user",
354
     *     cascade={"persist"},
355
     *     orphanRemoval=true
356
     * )
357
     */
358
    protected Collection $sessionCourseSubscriptions;
359
360
    /**
361
     * @ApiSubresource()
362
     *
363
     * @var Collection<int, SessionRelUser>|SessionRelUser[]
364
     *
365
     * @ORM\OneToMany(
366
     *     targetEntity="Chamilo\CoreBundle\Entity\SessionRelUser",
367
     *     mappedBy="user",
368
     *     cascade={"persist", "remove"},
369
     *     orphanRemoval=true
370
     * )
371
     */
372
    protected Collection $sessionsRelUser;
373
374
    /**
375
     * @var Collection<int, SkillRelUser>|SkillRelUser[]
376
     *
377
     * @ORM\OneToMany(
378
     *     targetEntity="Chamilo\CoreBundle\Entity\SkillRelUser",
379
     *     mappedBy="user",
380
     *     cascade={"persist", "remove"},
381
     *     orphanRemoval=true
382
     * )
383
     */
384
    protected Collection $achievedSkills;
385
386
    /**
387
     * @ORM\OneToMany(
388
     *     targetEntity="Chamilo\CoreBundle\Entity\SkillRelUserComment",
389
     *     mappedBy="feedbackGiver",
390
     *     cascade={"persist", "remove"},
391
     *     orphanRemoval=true
392
     * )
393
     *
394
     * @var Collection<int, SkillRelUserComment>|SkillRelUserComment[]
395
     */
396
    protected Collection $commentedUserSkills;
397
398
    /**
399
     * @var Collection<int, GradebookCategory>|GradebookCategory[]
400
     *
401
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\GradebookCategory", mappedBy="user")
402
     */
403
    protected Collection $gradeBookCategories;
404
405
    /**
406
     * @var Collection<int, GradebookCertificate>|GradebookCertificate[]
407
     *
408
     * @ORM\OneToMany(
409
     *     targetEntity="GradebookCertificate", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true
410
     * )
411
     */
412
    protected Collection $gradeBookCertificates;
413
414
    /**
415
     * @var Collection<int, GradebookComment>|GradebookComment[]
416
     *
417
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\GradebookComment", mappedBy="user")
418
     */
419
    protected Collection $gradeBookComments;
420
421
    /**
422
     * @ORM\OneToMany(
423
     *     targetEntity="GradebookEvaluation", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true
424
     * )
425
     *
426
     * @var Collection<int, GradebookEvaluation>|GradebookEvaluation[]
427
     */
428
    protected Collection $gradeBookEvaluations;
429
430
    /**
431
     * @ORM\OneToMany(targetEntity="GradebookLink", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
432
     *
433
     * @var Collection<int, GradebookLink>|GradebookLink[]
434
     */
435
    protected Collection $gradeBookLinks;
436
437
    /**
438
     * @ORM\OneToMany(targetEntity="GradebookResult", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
439
     *
440
     * @var Collection<int, GradebookResult>|GradebookResult[]
441
     */
442
    protected Collection $gradeBookResults;
443
444
    /**
445
     * @ORM\OneToMany(
446
     *     targetEntity="GradebookResultLog", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true
447
     * )
448
     *
449
     * @var Collection<int, GradebookResultLog>|GradebookResultLog[]
450
     */
451
    protected Collection $gradeBookResultLogs;
452
453
    /**
454
     * @ORM\OneToMany(
455
     *     targetEntity="GradebookScoreLog", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true
456
     * )
457
     *
458
     * @var Collection<int, GradebookScoreLog>|GradebookScoreLog[]
459
     */
460
    protected Collection $gradeBookScoreLogs;
461
462
    /**
463
     * @var Collection<int, UserRelUser>|UserRelUser[]
464
     * @ORM\OneToMany(targetEntity="UserRelUser", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
465
     */
466
    protected Collection $userRelUsers;
467
468
    /**
469
     * @var Collection<int, GradebookLinkevalLog>|GradebookLinkevalLog[]
470
     * @ORM\OneToMany(
471
     *     targetEntity="GradebookLinkevalLog",
472
     *     mappedBy="user",
473
     *     cascade={"persist", "remove"},
474
     *     orphanRemoval=true
475
     * )
476
     */
477
    protected Collection $gradeBookLinkEvalLogs;
478
479
    /**
480
     * @var Collection<int, SequenceValue>|SequenceValue[]
481
     * @ORM\OneToMany(targetEntity="SequenceValue", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
482
     */
483
    protected Collection $sequenceValues;
484
485
    /**
486
     * @var Collection<int, TrackEExerciseConfirmation>|TrackEExerciseConfirmation[]
487
     * @ORM\OneToMany(
488
     *     targetEntity="Chamilo\CoreBundle\Entity\TrackEExerciseConfirmation",
489
     *     mappedBy="user",
490
     *     cascade={"persist", "remove"},
491
     *     orphanRemoval=true
492
     * )
493
     */
494
    protected Collection $trackEExerciseConfirmations;
495
496
    /**
497
     * @var Collection<int, TrackEAttempt>|TrackEAttempt[]
498
     * @ORM\OneToMany(
499
     *     targetEntity="TrackEAccessComplete", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true
500
     * )
501
     */
502
    protected Collection $trackEAccessCompleteList;
503
504
    /**
505
     * @var Collection<int, Templates>|Templates[]
506
     * @ORM\OneToMany(targetEntity="Templates", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
507
     */
508
    protected Collection $templates;
509
510
    /**
511
     * @var Collection<int, TrackEAttempt>|TrackEAttempt[]
512
     * @ORM\OneToMany(targetEntity="TrackEAttempt", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
513
     */
514
    protected Collection $trackEAttempts;
515
516
    /**
517
     * @ORM\OneToMany(
518
     *     targetEntity="Chamilo\CoreBundle\Entity\TrackECourseAccess",
519
     *     mappedBy="user",
520
     *     cascade={"persist", "remove"},
521
     *     orphanRemoval=true
522
     * )
523
     *
524
     * @var Collection<int, TrackECourseAccess>|TrackECourseAccess[]
525
     */
526
    protected Collection $trackECourseAccess;
527
528
    /**
529
     * @var Collection<int, UserCourseCategory>|UserCourseCategory[]
530
     *
531
     * @ORM\OneToMany(
532
     *     targetEntity="UserCourseCategory",
533
     *     mappedBy="user",
534
     *     cascade={"persist", "remove"},
535
     *     orphanRemoval=true
536
     * )
537
     */
538
    protected Collection $userCourseCategories;
539
540
    /**
541
     * @var Collection<int, UserRelCourseVote>|UserRelCourseVote[]
542
     * @ORM\OneToMany(targetEntity="UserRelCourseVote", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
543
     */
544
    protected Collection $userRelCourseVotes;
545
546
    /**
547
     * @var Collection<int, UserRelTag>|UserRelTag[]
548
     * @ORM\OneToMany(targetEntity="UserRelTag", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
549
     */
550
    protected Collection $userRelTags;
551
552
    /**
553
     * @var Collection<int, PersonalAgenda>|PersonalAgenda[]
554
     * @ORM\OneToMany(targetEntity="PersonalAgenda", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
555
     */
556
    protected Collection $personalAgendas;
557
558
    /**
559
     * @var CGroupRelUser[]|Collection<int, CGroupRelUser>
560
     *
561
     * @ORM\OneToMany(
562
     *     targetEntity="Chamilo\CourseBundle\Entity\CGroupRelUser",
563
     *     mappedBy="user",
564
     *     cascade={"persist", "remove"},
565
     *     orphanRemoval=true
566
     * )
567
     */
568
    protected Collection $courseGroupsAsMember;
569
570
    /**
571
     * @var CGroupRelTutor[]|Collection<int, CGroupRelTutor>
572
     *
573
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CGroupRelTutor", mappedBy="user", orphanRemoval=true)
574
     */
575
    protected Collection $courseGroupsAsTutor;
576
577
    /**
578
     * @ORM\Column(name="auth_source", type="string", length=50, nullable=true)
579
     */
580
    protected ?string $authSource;
581
582
    /**
583
     * @ORM\Column(name="status", type="integer")
584
     */
585
    protected int $status;
586
587
    /**
588
     * @ORM\Column(name="official_code", type="string", length=40, nullable=true)
589
     */
590
    protected ?string $officialCode = null;
591
592
    /**
593
     * @ORM\Column(name="picture_uri", type="string", length=250, nullable=true)
594
     */
595
    protected ?string $pictureUri = null;
596
597
    /**
598
     * @ORM\Column(name="creator_id", type="integer", nullable=true, unique=false)
599
     */
600
    protected ?int $creatorId = null;
601
602
    /**
603
     * @ORM\Column(name="competences", type="text", nullable=true, unique=false)
604
     */
605
    protected ?string $competences = null;
606
607
    /**
608
     * @ORM\Column(name="diplomas", type="text", nullable=true, unique=false)
609
     */
610
    protected ?string $diplomas = null;
611
612
    /**
613
     * @ORM\Column(name="openarea", type="text", nullable=true, unique=false)
614
     */
615
    protected ?string $openarea = null;
616
617
    /**
618
     * @ORM\Column(name="teach", type="text", nullable=true, unique=false)
619
     */
620
    protected ?string $teach = null;
621
622
    /**
623
     * @ORM\Column(name="productions", type="string", length=250, nullable=true, unique=false)
624
     */
625
    protected ?string $productions = null;
626
627
    /**
628
     * @ORM\Column(name="registration_date", type="datetime")
629
     */
630
    protected DateTime $registrationDate;
631
632
    /**
633
     * @ORM\Column(name="expiration_date", type="datetime", nullable=true, unique=false)
634
     */
635
    protected ?DateTime $expirationDate;
636
637
    /**
638
     * @ORM\Column(name="active", type="boolean")
639
     */
640
    protected bool $active;
641
642
    /**
643
     * @ORM\Column(name="openid", type="string", length=255, nullable=true, unique=false)
644
     */
645
    protected ?string $openid = null;
646
647
    /**
648
     * @ORM\Column(name="theme", type="string", length=255, nullable=true, unique=false)
649
     */
650
    protected ?string $theme = null;
651
652
    /**
653
     * @ORM\Column(name="hr_dept_id", type="smallint", nullable=true, unique=false)
654
     */
655
    protected ?int $hrDeptId = null;
656
657
    /**
658
     * @var Collection<int, Message>|Message[]
659
     *
660
     * @ORM\OneToMany(
661
     *     targetEntity="Chamilo\CoreBundle\Entity\Message",
662
     *     mappedBy="userSender",
663
     *     cascade={"persist", "remove"},
664
     *     orphanRemoval=true
665
     * )
666
     */
667
    protected Collection $sentMessages;
668
669
    /**
670
     * @var Collection<int, Message>|Message[]
671
     *
672
     * @ORM\OneToMany(
673
     *     targetEntity="Chamilo\CoreBundle\Entity\Message",
674
     *     mappedBy="userReceiver",
675
     *     cascade={"persist", "remove"},
676
     *     orphanRemoval=true
677
     * )
678
     */
679
    protected Collection $receivedMessages;
680
681
    /**
682
     * @ORM\OneToOne(targetEntity="Admin", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
683
     */
684
    protected Admin $admin;
685
686
    /**
687
     * @var null|NilUuid|UuidV4
688
     *
689
     * @ORM\Column(type="uuid", unique=true)
690
     */
691
    protected $uuid;
692
693
    // Property used only during installation.
694
    protected bool $skipResourceNode;
695
696
    public function __construct()
697
    {
698
        $this->uuid = Uuid::v4();
699
        $this->apiToken = null;
700
        $this->biography = '';
701
        $this->website = '';
702
        $this->locale = 'en';
703
        $this->status = self::STUDENT;
704
        $this->salt = sha1(uniqid('', true));
705
        $this->active = true;
706
        $this->registrationDate = new DateTime();
707
        $this->authSource = 'platform';
708
        $this->skipResourceNode = false;
709
        $this->courses = new ArrayCollection();
710
        //$this->items = new ArrayCollection();
711
        $this->classes = new ArrayCollection();
712
        $this->curriculumItems = new ArrayCollection();
713
        $this->portals = new ArrayCollection();
714
        $this->dropBoxSentFiles = new ArrayCollection();
715
        $this->dropBoxReceivedFiles = new ArrayCollection();
716
        $this->groups = new ArrayCollection();
717
        $this->gradeBookCertificates = new ArrayCollection();
718
        $this->courseGroupsAsMember = new ArrayCollection();
719
        $this->courseGroupsAsTutor = new ArrayCollection();
720
        $this->sessionsAsGeneralCoach = new ArrayCollection();
721
        $this->resourceNodes = new ArrayCollection();
722
        $this->sessionCourseSubscriptions = new ArrayCollection();
723
        $this->achievedSkills = new ArrayCollection();
724
        $this->commentedUserSkills = new ArrayCollection();
725
        $this->gradeBookCategories = new ArrayCollection();
726
        $this->gradeBookComments = new ArrayCollection();
727
        $this->gradeBookEvaluations = new ArrayCollection();
728
        $this->gradeBookLinks = new ArrayCollection();
729
        $this->gradeBookResults = new ArrayCollection();
730
        $this->gradeBookResultLogs = new ArrayCollection();
731
        $this->gradeBookScoreLogs = new ArrayCollection();
732
        $this->userRelUsers = new ArrayCollection();
733
        $this->gradeBookLinkEvalLogs = new ArrayCollection();
734
        $this->sequenceValues = new ArrayCollection();
735
        $this->trackEExerciseConfirmations = new ArrayCollection();
736
        $this->trackEAccessCompleteList = new ArrayCollection();
737
        $this->templates = new ArrayCollection();
738
        $this->trackEAttempts = new ArrayCollection();
739
        $this->trackECourseAccess = new ArrayCollection();
740
        $this->userCourseCategories = new ArrayCollection();
741
        $this->userRelCourseVotes = new ArrayCollection();
742
        $this->userRelTags = new ArrayCollection();
743
        $this->personalAgendas = new ArrayCollection();
744
        $this->sessionsRelUser = new ArrayCollection();
745
        $this->sentMessages = new ArrayCollection();
746
        $this->receivedMessages = new ArrayCollection();
747
748
        //$this->extraFields = new ArrayCollection();
749
        $this->createdAt = new DateTime();
750
        $this->updatedAt = new DateTime();
751
752
        $this->enabled = false;
753
        $this->locked = false;
754
        $this->expired = false;
755
        $this->roles = [];
756
        $this->credentialsExpired = false;
757
        $this->credentialsExpireAt = new DateTime();
758
        $this->dateOfBirth = new DateTime();
759
        $this->expiresAt = new DateTime();
760
        $this->lastLogin = new DateTime();
761
        $this->passwordRequestedAt = new DateTime();
762
        $this->expirationDate = new DateTime();
763
    }
764
765
    public function __toString(): string
766
    {
767
        return $this->username;
768
    }
769
770
    public static function getPasswordConstraints(): array
771
    {
772
        return [
773
            new Assert\Length([
774
                'min' => 5,
775
            ]),
776
            // Alpha numeric + "_" or "-"
777
            new Assert\Regex(
778
                [
779
                    'pattern' => '/^[a-z\-_0-9]+$/i',
780
                    'htmlPattern' => '/^[a-z\-_0-9]+$/i',
781
                ]
782
            ),
783
            // Min 3 letters - not needed
784
            /*new Assert\Regex(array(
785
                    'pattern' => '/[a-z]{3}/i',
786
                    'htmlPattern' => '/[a-z]{3}/i')
787
                ),*/
788
            // Min 2 numbers
789
            new Assert\Regex(
790
                [
791
                    'pattern' => '/[0-9]{2}/',
792
                    'htmlPattern' => '/[0-9]{2}/',
793
                ]
794
            ),
795
        ];
796
    }
797
798
    public static function loadValidatorMetadata(ClassMetadata $metadata): void
799
    {
800
        //$metadata->addPropertyConstraint('firstname', new Assert\NotBlank());
801
        //$metadata->addPropertyConstraint('lastname', new Assert\NotBlank());
802
        //$metadata->addPropertyConstraint('email', new Assert\Email());
803
        /*
804
        $metadata->addPropertyConstraint('password',
805
            new Assert\Collection(self::getPasswordConstraints())
806
        );*/
807
808
        /*$metadata->addConstraint(new UniqueEntity(array(
809
            'fields'  => 'username',
810
            'message' => 'This value is already used.',
811
        )));*/
812
813
        /*$metadata->addPropertyConstraint(
814
            'username',
815
            new Assert\Length(array(
816
                'min'        => 2,
817
                'max'        => 50,
818
                'minMessage' => 'This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.',
819
                'maxMessage' => 'This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.',
820
            ))
821
        );*/
822
    }
823
824
    public function getUuid(): UuidV4
825
    {
826
        return $this->uuid;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->uuid could return the type null which is incompatible with the type-hinted return Symfony\Component\Uid\UuidV4. Consider adding an additional type-check to rule them out.
Loading history...
827
    }
828
829
    public function setUuid(UuidV4 $uuid): self
830
    {
831
        $this->uuid = $uuid;
832
833
        return $this;
834
    }
835
836
    public function getResourceNode(): ?ResourceNode
837
    {
838
        return $this->resourceNode;
839
    }
840
841
    public function setResourceNode(ResourceNode $resourceNode): self
842
    {
843
        $this->resourceNode = $resourceNode;
844
845
        return $this;
846
    }
847
848
    public function hasResourceNode(): bool
849
    {
850
        return $this->resourceNode instanceof ResourceNode;
851
    }
852
853
    public function getResourceNodes(): Collection
854
    {
855
        return $this->resourceNodes;
856
    }
857
858
    /**
859
     * @param Collection<int, ResourceNode>|ResourceNode[] $resourceNodes
860
     */
861
    public function setResourceNodes(Collection $resourceNodes): self
862
    {
863
        $this->resourceNodes = $resourceNodes;
864
865
        return $this;
866
    }
867
868
    public function getDropBoxSentFiles(): Collection
869
    {
870
        return $this->dropBoxSentFiles;
871
    }
872
873
    public function setDropBoxSentFiles(Collection $value): self
874
    {
875
        $this->dropBoxSentFiles = $value;
876
877
        return $this;
878
    }
879
880
    /*public function getDropBoxReceivedFiles()
881
    {
882
        return $this->dropBoxReceivedFiles;
883
    }
884
885
    public function setDropBoxReceivedFiles($value): void
886
    {
887
        $this->dropBoxReceivedFiles = $value;
888
    }*/
889
890
    public function getCourses(): Collection
891
    {
892
        return $this->courses;
893
    }
894
895
    /**
896
     * @param Collection<int, CourseRelUser>|CourseRelUser[] $courses
897
     */
898
    public function setCourses(Collection $courses): self
899
    {
900
        $this->courses = $courses;
901
902
        return $this;
903
    }
904
905
    public function setPortal(AccessUrlRelUser $portal): self
906
    {
907
        $this->portals->add($portal);
908
909
        return $this;
910
    }
911
912
    /*public function getCurriculumItems(): Collection
913
    {
914
        return $this->curriculumItems;
915
    }
916
917
    public function setCurriculumItems(array $items): self
918
    {
919
        $this->curriculumItems = $items;
920
921
        return $this;
922
    }*/
923
924
    public function getIsActive(): bool
925
    {
926
        return $this->active;
927
    }
928
929
    public function isEnabled(): bool
930
    {
931
        return $this->isActive();
932
    }
933
934
    public function setEnabled(bool $boolean): self
935
    {
936
        $this->enabled = $boolean;
937
938
        return $this;
939
    }
940
941
    public function getSalt(): string
942
    {
943
        return $this->salt;
944
    }
945
946
    public function setSalt(string $salt): self
947
    {
948
        $this->salt = $salt;
949
950
        return $this;
951
    }
952
953
    public function getLps(): void
954
    {
955
        //return $this->lps;
956
        /*$criteria = Criteria::create()
957
            ->where(Criteria::expr()->eq("id", "666"))
958
            //->orderBy(array("username" => "ASC"))
959
            //->setFirstResult(0)
960
            //->setMaxResults(20)
961
        ;
962
        $lps = $this->lps->matching($criteria);*/
963
        /*return $this->lps->filter(
964
            function($entry) use ($idsToFilter) {
965
                return $entry->getId() == 1;
966
        });*/
967
    }
968
969
    /**
970
     * Returns the list of classes for the user.
971
     */
972
    public function getCompleteNameWithClasses(): string
973
    {
974
        $classSubscription = $this->getClasses();
975
        $classList = [];
976
        /** @var UsergroupRelUser $subscription */
977
        foreach ($classSubscription as $subscription) {
978
            $class = $subscription->getUsergroup();
979
            $classList[] = $class->getName();
980
        }
981
        $classString = empty($classList) ? null : ' ['.implode(', ', $classList).']';
982
983
        return UserManager::formatUserFullName($this).$classString;
984
    }
985
986
    public function getClasses(): Collection
987
    {
988
        return $this->classes;
989
    }
990
991
    /**
992
     * @param Collection<int, UsergroupRelUser>|UsergroupRelUser[] $classes
993
     */
994
    public function setClasses(Collection $classes): self
995
    {
996
        $this->classes = $classes;
997
998
        return $this;
999
    }
1000
1001
    public function getPassword()
1002
    {
1003
        return $this->password;
1004
    }
1005
1006
    public function setPassword(string $password): self
1007
    {
1008
        $this->password = $password;
1009
1010
        return $this;
1011
    }
1012
1013
    public function getAuthSource(): ?string
1014
    {
1015
        return $this->authSource;
1016
    }
1017
1018
    public function setAuthSource(string $authSource): self
1019
    {
1020
        $this->authSource = $authSource;
1021
1022
        return $this;
1023
    }
1024
1025
    public function getEmail(): string
1026
    {
1027
        return $this->email;
1028
    }
1029
1030
    public function setEmail(string $email): self
1031
    {
1032
        $this->email = $email;
1033
1034
        return $this;
1035
    }
1036
1037
    public function getOfficialCode(): ?string
1038
    {
1039
        return $this->officialCode;
1040
    }
1041
1042
    public function setOfficialCode(?string $officialCode): self
1043
    {
1044
        $this->officialCode = $officialCode;
1045
1046
        return $this;
1047
    }
1048
1049
    public function getPhone(): ?string
1050
    {
1051
        return $this->phone;
1052
    }
1053
1054
    public function setPhone(?string $phone): self
1055
    {
1056
        $this->phone = $phone;
1057
1058
        return $this;
1059
    }
1060
1061
    public function getAddress(): ?string
1062
    {
1063
        return $this->address;
1064
    }
1065
1066
    public function setAddress(?string $address): self
1067
    {
1068
        $this->address = $address;
1069
1070
        return $this;
1071
    }
1072
1073
    public function getCreatorId(): ?int
1074
    {
1075
        return $this->creatorId;
1076
    }
1077
1078
    public function setCreatorId(int $creatorId): self
1079
    {
1080
        $this->creatorId = $creatorId;
1081
1082
        return $this;
1083
    }
1084
1085
    public function getCompetences(): ?string
1086
    {
1087
        return $this->competences;
1088
    }
1089
1090
    public function setCompetences(?string $competences): self
1091
    {
1092
        $this->competences = $competences;
1093
1094
        return $this;
1095
    }
1096
1097
    public function getDiplomas(): ?string
1098
    {
1099
        return $this->diplomas;
1100
    }
1101
1102
    public function setDiplomas(?string $diplomas): self
1103
    {
1104
        $this->diplomas = $diplomas;
1105
1106
        return $this;
1107
    }
1108
1109
    public function getOpenarea(): ?string
1110
    {
1111
        return $this->openarea;
1112
    }
1113
1114
    public function setOpenarea(?string $openarea): self
1115
    {
1116
        $this->openarea = $openarea;
1117
1118
        return $this;
1119
    }
1120
1121
    public function getTeach(): ?string
1122
    {
1123
        return $this->teach;
1124
    }
1125
1126
    public function setTeach(?string $teach): self
1127
    {
1128
        $this->teach = $teach;
1129
1130
        return $this;
1131
    }
1132
1133
    public function getProductions(): ?string
1134
    {
1135
        return $this->productions;
1136
    }
1137
1138
    public function setProductions(?string $productions): self
1139
    {
1140
        $this->productions = $productions;
1141
1142
        return $this;
1143
    }
1144
1145
    public function getRegistrationDate(): DateTime
1146
    {
1147
        return $this->registrationDate;
1148
    }
1149
1150
    public function setRegistrationDate(DateTime $registrationDate): self
1151
    {
1152
        $this->registrationDate = $registrationDate;
1153
1154
        return $this;
1155
    }
1156
1157
    public function getExpirationDate(): ?DateTime
1158
    {
1159
        return $this->expirationDate;
1160
    }
1161
1162
    public function setExpirationDate(DateTime $expirationDate): self
1163
    {
1164
        $this->expirationDate = $expirationDate;
1165
1166
        return $this;
1167
    }
1168
1169
    public function getActive(): bool
1170
    {
1171
        return $this->active;
1172
    }
1173
1174
    public function isActive(): bool
1175
    {
1176
        return $this->getIsActive();
1177
    }
1178
1179
    public function setActive(bool $active): self
1180
    {
1181
        $this->active = $active;
1182
1183
        return $this;
1184
    }
1185
1186
    public function getOpenid(): ?string
1187
    {
1188
        return $this->openid;
1189
    }
1190
1191
    public function setOpenid(string $openid): self
1192
    {
1193
        $this->openid = $openid;
1194
1195
        return $this;
1196
    }
1197
1198
    public function getTheme(): ?string
1199
    {
1200
        return $this->theme;
1201
    }
1202
1203
    public function setTheme(string $theme): self
1204
    {
1205
        $this->theme = $theme;
1206
1207
        return $this;
1208
    }
1209
1210
    public function getHrDeptId(): ?int
1211
    {
1212
        return $this->hrDeptId;
1213
    }
1214
1215
    public function setHrDeptId(int $hrDeptId): self
1216
    {
1217
        $this->hrDeptId = $hrDeptId;
1218
1219
        return $this;
1220
    }
1221
1222
    public function getMemberSince(): DateTime
1223
    {
1224
        return $this->registrationDate;
1225
    }
1226
1227
    public function isOnline(): bool
1228
    {
1229
        return false;
1230
    }
1231
1232
    public function getIdentifier(): int
1233
    {
1234
        return $this->getId();
1235
    }
1236
1237
    public function getId(): int
1238
    {
1239
        return $this->id;
1240
    }
1241
1242
    public function getSlug(): string
1243
    {
1244
        return $this->getUsername();
1245
    }
1246
1247
    public function getUsername(): string
1248
    {
1249
        return $this->username;
1250
    }
1251
1252
    public function setUsername(string $username): self
1253
    {
1254
        $this->username = $username;
1255
1256
        return $this;
1257
    }
1258
1259
    public function setSlug(string $slug): self
1260
    {
1261
        return $this->setUsername($slug);
1262
    }
1263
1264
    public function getLastLogin(): ?DateTime
1265
    {
1266
        return $this->lastLogin;
1267
    }
1268
1269
    public function setLastLogin(DateTime $lastLogin = null): self
1270
    {
1271
        $this->lastLogin = $lastLogin;
1272
1273
        return $this;
1274
    }
1275
1276
    public function getSessionCourseSubscriptions(): Collection
1277
    {
1278
        return $this->sessionCourseSubscriptions;
1279
    }
1280
1281
    /**
1282
     * @param Collection<int, SessionRelCourseRelUser>|SessionRelCourseRelUser[] $value
1283
     */
1284
    public function setSessionCourseSubscriptions(Collection $value): self
1285
    {
1286
        $this->sessionCourseSubscriptions = $value;
1287
1288
        return $this;
1289
    }
1290
1291
    public function getConfirmationToken(): ?string
1292
    {
1293
        return $this->confirmationToken;
1294
    }
1295
1296
    public function setConfirmationToken(string $confirmationToken): self
1297
    {
1298
        $this->confirmationToken = $confirmationToken;
1299
1300
        return $this;
1301
    }
1302
1303
    public function isPasswordRequestNonExpired(int $ttl): bool
1304
    {
1305
        return $this->getPasswordRequestedAt() instanceof DateTime &&
1306
            $this->getPasswordRequestedAt()->getTimestamp() + $ttl > time();
1307
    }
1308
1309
    public function getPasswordRequestedAt(): ?DateTime
1310
    {
1311
        return $this->passwordRequestedAt;
1312
    }
1313
1314
    public function setPasswordRequestedAt(DateTime $date = null): self
1315
    {
1316
        $this->passwordRequestedAt = $date;
1317
1318
        return $this;
1319
    }
1320
1321
    public function getPlainPassword(): ?string
1322
    {
1323
        return $this->plainPassword;
1324
    }
1325
1326
    public function setPlainPassword(string $password): self
1327
    {
1328
        $this->plainPassword = $password;
1329
1330
        // forces the object to look "dirty" to Doctrine. Avoids
1331
        // Doctrine *not* saving this entity, if only plainPassword changes
1332
        $this->password = '';
1333
1334
        return $this;
1335
    }
1336
1337
    /**
1338
     * Returns the expiration date.
1339
     */
1340
    public function getExpiresAt(): ?DateTime
1341
    {
1342
        return $this->expiresAt;
1343
    }
1344
1345
    public function setExpiresAt(DateTime $date): self
1346
    {
1347
        $this->expiresAt = $date;
1348
1349
        return $this;
1350
    }
1351
1352
    /**
1353
     * Returns the credentials expiration date.
1354
     */
1355
    public function getCredentialsExpireAt(): ?DateTime
1356
    {
1357
        return $this->credentialsExpireAt;
1358
    }
1359
1360
    /**
1361
     * Sets the credentials expiration date.
1362
     */
1363
    public function setCredentialsExpireAt(DateTime $date = null): self
1364
    {
1365
        $this->credentialsExpireAt = $date;
1366
1367
        return $this;
1368
    }
1369
1370
    public function getFullname(): string
1371
    {
1372
        return sprintf('%s %s', $this->getFirstname(), $this->getLastname());
1373
    }
1374
1375
    public function getFirstname(): ?string
1376
    {
1377
        return $this->firstname;
1378
    }
1379
1380
    public function setFirstname(string $firstname): self
1381
    {
1382
        $this->firstname = $firstname;
1383
1384
        return $this;
1385
    }
1386
1387
    public function getLastname(): ?string
1388
    {
1389
        return $this->lastname;
1390
    }
1391
1392
    public function setLastname(string $lastname): self
1393
    {
1394
        $this->lastname = $lastname;
1395
1396
        return $this;
1397
    }
1398
1399
    public function hasGroup(string $name): bool
1400
    {
1401
        return \in_array($name, $this->getGroupNames(), true);
1402
    }
1403
1404
    public function getGroupNames(): array
1405
    {
1406
        $names = [];
1407
        foreach ($this->getGroups() as $group) {
1408
            $names[] = $group->getName();
1409
        }
1410
1411
        return $names;
1412
    }
1413
1414
    public function getGroups(): Collection
1415
    {
1416
        return $this->groups;
1417
    }
1418
1419
    /**
1420
     * Sets the user groups.
1421
     */
1422
    public function setGroups(Collection $groups): self
1423
    {
1424
        foreach ($groups as $group) {
1425
            $this->addGroup($group);
1426
        }
1427
1428
        return $this;
1429
    }
1430
1431
    public function addGroup(Group $group): self
1432
    {
1433
        if (!$this->getGroups()->contains($group)) {
1434
            $this->getGroups()->add($group);
1435
        }
1436
1437
        return $this;
1438
    }
1439
1440
    public function removeGroup(Group $group): self
1441
    {
1442
        if ($this->getGroups()->contains($group)) {
1443
            $this->getGroups()->removeElement($group);
1444
        }
1445
1446
        return $this;
1447
    }
1448
1449
    public function isAccountNonExpired(): bool
1450
    {
1451
        /*if (true === $this->expired) {
1452
            return false;
1453
        }
1454
1455
        if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
1456
            return false;
1457
        }*/
1458
1459
        return true;
1460
    }
1461
1462
    public function isAccountNonLocked(): bool
1463
    {
1464
        return true;
1465
        //return !$this->locked;
1466
    }
1467
1468
    public function isCredentialsNonExpired(): bool
1469
    {
1470
        /*if (true === $this->credentialsExpired) {
1471
            return false;
1472
        }
1473
1474
        if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
1475
            return false;
1476
        }*/
1477
1478
        return true;
1479
    }
1480
1481
    public function getCredentialsExpired(): bool
1482
    {
1483
        return $this->credentialsExpired;
1484
    }
1485
1486
    public function setCredentialsExpired(bool $boolean): self
1487
    {
1488
        $this->credentialsExpired = $boolean;
1489
1490
        return $this;
1491
    }
1492
1493
    public function getExpired(): bool
1494
    {
1495
        return $this->expired;
1496
    }
1497
1498
    /**
1499
     * Sets this user to expired.
1500
     */
1501
    public function setExpired(bool $boolean): self
1502
    {
1503
        $this->expired = $boolean;
1504
1505
        return $this;
1506
    }
1507
1508
    public function getLocked(): bool
1509
    {
1510
        return $this->locked;
1511
    }
1512
1513
    public function setLocked(bool $boolean): self
1514
    {
1515
        $this->locked = $boolean;
1516
1517
        return $this;
1518
    }
1519
1520
    /**
1521
     * Check if the user has the skill.
1522
     *
1523
     * @param Skill $skill The skill
1524
     */
1525
    public function hasSkill(Skill $skill): bool
1526
    {
1527
        $achievedSkills = $this->getAchievedSkills();
1528
1529
        foreach ($achievedSkills as $userSkill) {
1530
            if ($userSkill->getSkill()->getId() !== $skill->getId()) {
1531
                continue;
1532
            }
1533
1534
            return true;
1535
        }
1536
1537
        return false;
1538
    }
1539
1540
    public function getAchievedSkills(): Collection
1541
    {
1542
        return $this->achievedSkills;
1543
    }
1544
1545
    /**
1546
     * @param Collection<int, SkillRelUser>|SkillRelUser[] $value
1547
     */
1548
    public function setAchievedSkills(Collection $value): self
1549
    {
1550
        $this->achievedSkills = $value;
1551
1552
        return $this;
1553
    }
1554
1555
    public function isProfileCompleted(): ?bool
1556
    {
1557
        return $this->profileCompleted;
1558
    }
1559
1560
    public function setProfileCompleted(?bool $profileCompleted): self
1561
    {
1562
        $this->profileCompleted = $profileCompleted;
1563
1564
        return $this;
1565
    }
1566
1567
    public function getCurrentUrl(): AccessUrl
1568
    {
1569
        return $this->currentUrl;
1570
    }
1571
1572
    /**
1573
     * Sets the AccessUrl for the current user in memory.
1574
     */
1575
    public function setCurrentUrl(AccessUrl $url): self
1576
    {
1577
        $urlList = $this->getPortals();
1578
        /** @var AccessUrlRelUser $item */
1579
        foreach ($urlList as $item) {
1580
            if ($item->getUrl()->getId() === $url->getId()) {
1581
                $this->currentUrl = $url;
1582
1583
                break;
1584
            }
1585
        }
1586
1587
        return $this;
1588
    }
1589
1590
    public function getPortals(): Collection
1591
    {
1592
        return $this->portals;
1593
    }
1594
1595
    /**
1596
     * @param AccessUrlRelUser[]|Collection<int, AccessUrlRelUser> $value
1597
     */
1598
    public function setPortals(Collection $value): void
1599
    {
1600
        $this->portals = $value;
1601
    }
1602
1603
    public function getSessionsAsGeneralCoach(): Collection
1604
    {
1605
        return $this->sessionsAsGeneralCoach;
1606
    }
1607
1608
    /**
1609
     * @param Collection<int, Session>|Session[] $value
1610
     */
1611
    public function setSessionsAsGeneralCoach(Collection $value): self
1612
    {
1613
        $this->sessionsAsGeneralCoach = $value;
1614
1615
        return $this;
1616
    }
1617
1618
    public function getCommentedUserSkills(): Collection
1619
    {
1620
        return $this->commentedUserSkills;
1621
    }
1622
1623
    /**
1624
     * @param Collection<int, SkillRelUserComment>|SkillRelUserComment[] $commentedUserSkills
1625
     */
1626
    public function setCommentedUserSkills(Collection $commentedUserSkills): self
1627
    {
1628
        $this->commentedUserSkills = $commentedUserSkills;
1629
1630
        return $this;
1631
    }
1632
1633
    public function isEqualTo(UserInterface $user): bool
1634
    {
1635
        if ($this->password !== $user->getPassword()) {
1636
            return false;
1637
        }
1638
1639
        if ($this->salt !== $user->getSalt()) {
1640
            return false;
1641
        }
1642
1643
        if ($this->username !== $user->getUsername()) {
1644
            return false;
1645
        }
1646
1647
        return true;
1648
    }
1649
1650
    public function getSentMessages(): Collection
1651
    {
1652
        return $this->sentMessages;
1653
    }
1654
1655
    public function getReceivedMessages(): Collection
1656
    {
1657
        return $this->receivedMessages;
1658
    }
1659
1660
    /**
1661
     * @param int $lastId Optional. The ID of the last received message
1662
     */
1663
    public function getUnreadReceivedMessages(int $lastId = 0): Collection
1664
    {
1665
        $criteria = Criteria::create();
1666
        $criteria->where(
1667
            Criteria::expr()->eq('msgStatus', MESSAGE_STATUS_UNREAD)
1668
        );
1669
1670
        if ($lastId > 0) {
1671
            $criteria->andWhere(
1672
                Criteria::expr()->gt('id', $lastId)
1673
            );
1674
        }
1675
1676
        $criteria->orderBy([
1677
            'sendDate' => Criteria::DESC,
1678
        ]);
1679
1680
        return $this->receivedMessages->matching($criteria);
1681
    }
1682
1683
    public function getCourseGroupsAsMember(): Collection
1684
    {
1685
        return $this->courseGroupsAsMember;
1686
    }
1687
1688
    public function getCourseGroupsAsTutor(): Collection
1689
    {
1690
        return $this->courseGroupsAsTutor;
1691
    }
1692
1693
    public function getCourseGroupsAsMemberFromCourse(Course $course): Collection
1694
    {
1695
        $criteria = Criteria::create();
1696
        $criteria->where(
1697
            Criteria::expr()->eq('cId', $course)
1698
        );
1699
1700
        return $this->courseGroupsAsMember->matching($criteria);
1701
    }
1702
1703
    public function eraseCredentials(): void
1704
    {
1705
        $this->plainPassword = null;
1706
    }
1707
1708
    public function isSuperAdmin(): bool
1709
    {
1710
        return $this->hasRole('ROLE_SUPER_ADMIN');
1711
    }
1712
1713
    public function hasRole(string $role): bool
1714
    {
1715
        return \in_array(strtoupper($role), $this->getRoles(), true);
1716
    }
1717
1718
    /**
1719
     * Returns the user roles.
1720
     *
1721
     * @return array The roles
1722
     */
1723
    public function getRoles(): array
1724
    {
1725
        $roles = $this->roles;
1726
1727
        foreach ($this->getGroups() as $group) {
1728
            $roles = array_merge($roles, $group->getRoles());
1729
        }
1730
1731
        // we need to make sure to have at least one role
1732
        $roles[] = 'ROLE_USER';
1733
1734
        return array_unique($roles);
1735
    }
1736
1737
    public function setRoles(array $roles): self
1738
    {
1739
        $this->roles = [];
1740
1741
        foreach ($roles as $role) {
1742
            $this->addRole($role);
1743
        }
1744
1745
        return $this;
1746
    }
1747
1748
    public function addRole(string $role): self
1749
    {
1750
        $role = strtoupper($role);
1751
        if ($role === static::ROLE_DEFAULT) {
1752
            return $this;
1753
        }
1754
1755
        if (!\in_array($role, $this->roles, true)) {
1756
            $this->roles[] = $role;
1757
        }
1758
1759
        return $this;
1760
    }
1761
1762
    public function isUser(self $user = null): bool
1763
    {
1764
        return null !== $user && $this->getId() === $user->getId();
1765
    }
1766
1767
    public function removeRole(string $role): self
1768
    {
1769
        if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
1770
            unset($this->roles[$key]);
1771
            $this->roles = array_values($this->roles);
1772
        }
1773
1774
        return $this;
1775
    }
1776
1777
    public function getUsernameCanonical(): string
1778
    {
1779
        return $this->usernameCanonical;
1780
    }
1781
1782
    public function setUsernameCanonical(string $usernameCanonical): self
1783
    {
1784
        $this->usernameCanonical = $usernameCanonical;
1785
1786
        return $this;
1787
    }
1788
1789
    public function getEmailCanonical(): string
1790
    {
1791
        return $this->emailCanonical;
1792
    }
1793
1794
    public function setEmailCanonical(string $emailCanonical): self
1795
    {
1796
        $this->emailCanonical = $emailCanonical;
1797
1798
        return $this;
1799
    }
1800
1801
    public function getTimezone(): string
1802
    {
1803
        return $this->timezone;
1804
    }
1805
1806
    public function setTimezone(string $timezone): self
1807
    {
1808
        $this->timezone = $timezone;
1809
1810
        return $this;
1811
    }
1812
1813
    public function getLocale(): string
1814
    {
1815
        return $this->locale;
1816
    }
1817
1818
    public function setLocale(string $locale): self
1819
    {
1820
        $this->locale = $locale;
1821
1822
        return $this;
1823
    }
1824
1825
    public function getApiToken(): ?string
1826
    {
1827
        return $this->apiToken;
1828
    }
1829
1830
    public function setApiToken(string $apiToken): self
1831
    {
1832
        $this->apiToken = $apiToken;
1833
1834
        return $this;
1835
    }
1836
1837
    public function getWebsite(): ?string
1838
    {
1839
        return $this->website;
1840
    }
1841
1842
    public function setWebsite(string $website): self
1843
    {
1844
        $this->website = $website;
1845
1846
        return $this;
1847
    }
1848
1849
    public function getBiography(): ?string
1850
    {
1851
        return $this->biography;
1852
    }
1853
1854
    public function setBiography(string $biography): self
1855
    {
1856
        $this->biography = $biography;
1857
1858
        return $this;
1859
    }
1860
1861
    public function getDateOfBirth(): ?DateTime
1862
    {
1863
        return $this->dateOfBirth;
1864
    }
1865
1866
    public function setDateOfBirth(DateTime $dateOfBirth = null): self
1867
    {
1868
        $this->dateOfBirth = $dateOfBirth;
1869
1870
        return $this;
1871
    }
1872
1873
    public function getProfileUrl(): string
1874
    {
1875
        return '/main/social/profile.php?u='.$this->id;
1876
    }
1877
1878
    public function getIconStatus(): string
1879
    {
1880
        $status = $this->getStatus();
1881
        $hasCertificates = $this->getGradeBookCertificates()->count() > 0;
1882
        $urlImg = '/img/';
1883
        $iconStatus = '';
1884
        switch ($status) {
1885
            case self::STUDENT:
1886
                if ($hasCertificates) {
1887
                    $iconStatus = $urlImg.'icons/svg/identifier_graduated.svg';
1888
                } else {
1889
                    $iconStatus = $urlImg.'icons/svg/identifier_student.svg';
1890
                }
1891
1892
                break;
1893
            case self::COURSE_MANAGER:
1894
                if ($this->isAdmin()) {
1895
                    $iconStatus = $urlImg.'icons/svg/identifier_admin.svg';
1896
                } else {
1897
                    $iconStatus = $urlImg.'icons/svg/identifier_teacher.svg';
1898
                }
1899
1900
                break;
1901
            case STUDENT_BOSS:
1902
                $iconStatus = $urlImg.'icons/svg/identifier_teacher.svg';
1903
1904
                break;
1905
        }
1906
1907
        return $iconStatus;
1908
    }
1909
1910
    public function getStatus(): int
1911
    {
1912
        return $this->status;
1913
    }
1914
1915
    public function setStatus(int $status): self
1916
    {
1917
        $this->status = $status;
1918
1919
        return $this;
1920
    }
1921
1922
    public function getPictureUri(): ?string
1923
    {
1924
        return $this->pictureUri;
1925
    }
1926
1927
    public function getGradeBookCertificates(): Collection
1928
    {
1929
        return $this->gradeBookCertificates;
1930
    }
1931
1932
    /**
1933
     * @param Collection<int, GradebookCertificate>|GradebookCertificate[] $gradeBookCertificates
1934
     */
1935
    public function setGradeBookCertificates(Collection $gradeBookCertificates): self
1936
    {
1937
        $this->gradeBookCertificates = $gradeBookCertificates;
1938
1939
        return $this;
1940
    }
1941
1942
    public function isAdmin(): bool
1943
    {
1944
        return $this->hasRole('ROLE_ADMIN');
1945
    }
1946
1947
    /**
1948
     * @return GradebookCategory[]|Collection
1949
     */
1950
    public function getGradeBookCategories()
1951
    {
1952
        return $this->gradeBookCategories;
1953
    }
1954
1955
    /**
1956
     * @return GradebookComment[]|Collection
1957
     */
1958
    public function getGradeBookComments()
1959
    {
1960
        return $this->gradeBookComments;
1961
    }
1962
1963
    /**
1964
     * @return GradebookEvaluation[]|Collection
1965
     */
1966
    public function getGradeBookEvaluations()
1967
    {
1968
        return $this->gradeBookEvaluations;
1969
    }
1970
1971
    /**
1972
     * @return GradebookLink[]|Collection
1973
     */
1974
    public function getGradeBookLinks()
1975
    {
1976
        return $this->gradeBookLinks;
1977
    }
1978
1979
    /**
1980
     * @return GradebookResult[]|Collection
1981
     */
1982
    public function getGradeBookResults()
1983
    {
1984
        return $this->gradeBookResults;
1985
    }
1986
1987
    /**
1988
     * @return GradebookResultLog[]|Collection
1989
     */
1990
    public function getGradeBookResultLogs()
1991
    {
1992
        return $this->gradeBookResultLogs;
1993
    }
1994
1995
    /**
1996
     * @return GradebookScoreLog[]|Collection
1997
     */
1998
    public function getGradeBookScoreLogs()
1999
    {
2000
        return $this->gradeBookScoreLogs;
2001
    }
2002
2003
    /**
2004
     * @return GradebookLinkevalLog[]|Collection
2005
     */
2006
    public function getGradeBookLinkEvalLogs()
2007
    {
2008
        return $this->gradeBookLinkEvalLogs;
2009
    }
2010
2011
    /**
2012
     * @return UserRelCourseVote[]|Collection
2013
     */
2014
    public function getUserRelCourseVotes()
2015
    {
2016
        return $this->userRelCourseVotes;
2017
    }
2018
2019
    /**
2020
     * @return UserRelTag[]|Collection
2021
     */
2022
    public function getUserRelTags()
2023
    {
2024
        return $this->userRelTags;
2025
    }
2026
2027
    /**
2028
     * @return PersonalAgenda[]|Collection
2029
     */
2030
    public function getPersonalAgendas()
2031
    {
2032
        return $this->personalAgendas;
2033
    }
2034
2035
    /**
2036
     * @return Collection|mixed[]
2037
     */
2038
    public function getCurriculumItems()
2039
    {
2040
        return $this->curriculumItems;
2041
    }
2042
2043
    /**
2044
     * @return UserRelUser[]|Collection
2045
     */
2046
    public function getUserRelUsers()
2047
    {
2048
        return $this->userRelUsers;
2049
    }
2050
2051
    /**
2052
     * @return Templates[]|Collection
2053
     */
2054
    public function getTemplates()
2055
    {
2056
        return $this->templates;
2057
    }
2058
2059
    /**
2060
     * @return ArrayCollection|Collection
2061
     */
2062
    public function getDropBoxReceivedFiles()
2063
    {
2064
        return $this->dropBoxReceivedFiles;
2065
    }
2066
2067
    /**
2068
     * @return SequenceValue[]|Collection
2069
     */
2070
    public function getSequenceValues()
2071
    {
2072
        return $this->sequenceValues;
2073
    }
2074
2075
    /**
2076
     * @return TrackEExerciseConfirmation[]|Collection
2077
     */
2078
    public function getTrackEExerciseConfirmations()
2079
    {
2080
        return $this->trackEExerciseConfirmations;
2081
    }
2082
2083
    /**
2084
     * @return TrackEAttempt[]|Collection
2085
     */
2086
    public function getTrackEAccessCompleteList()
2087
    {
2088
        return $this->trackEAccessCompleteList;
2089
    }
2090
2091
    /**
2092
     * @return TrackEAttempt[]|Collection
2093
     */
2094
    public function getTrackEAttempts()
2095
    {
2096
        return $this->trackEAttempts;
2097
    }
2098
2099
    /**
2100
     * @return TrackECourseAccess[]|Collection
2101
     */
2102
    public function getTrackECourseAccess()
2103
    {
2104
        return $this->trackECourseAccess;
2105
    }
2106
2107
    /**
2108
     * @return UserCourseCategory[]|Collection
2109
     */
2110
    public function getUserCourseCategories()
2111
    {
2112
        return $this->userCourseCategories;
2113
    }
2114
2115
    public function getCourseGroupsAsTutorFromCourse(Course $course): Collection
2116
    {
2117
        $criteria = Criteria::create();
2118
        $criteria->where(
2119
            Criteria::expr()->eq('cId', $course->getId())
2120
        );
2121
2122
        return $this->courseGroupsAsTutor->matching($criteria);
2123
    }
2124
2125
    /**
2126
     * Retrieves this user's related student sessions.
2127
     *
2128
     * @return Session[]
2129
     */
2130
    public function getStudentSessions(): array
2131
    {
2132
        return $this->getSessions(0);
2133
    }
2134
2135
    /**
2136
     * @return SessionRelUser[]|Collection
2137
     */
2138
    public function getSessionsRelUser()
2139
    {
2140
        return $this->sessionsRelUser;
2141
    }
2142
2143
    public function isSkipResourceNode(): bool
2144
    {
2145
        return $this->skipResourceNode;
2146
    }
2147
2148
    public function setSkipResourceNode(bool $skipResourceNode): self
2149
    {
2150
        $this->skipResourceNode = $skipResourceNode;
2151
2152
        return $this;
2153
    }
2154
2155
    /**
2156
     * Retreives this user's related sessions.
2157
     *
2158
     * @param int $relationType \Chamilo\CoreBundle\Entity\SessionRelUser::relationTypeList key
2159
     *
2160
     * @return Session[]
2161
     */
2162
    public function getSessions(int $relationType): array
2163
    {
2164
        $sessions = [];
2165
        foreach ($this->getSessionsRelUser() as $sessionRelUser) {
2166
            if ($sessionRelUser->getRelationType() === $relationType) {
2167
                $sessions[] = $sessionRelUser->getSession();
2168
            }
2169
        }
2170
2171
        return $sessions;
2172
    }
2173
2174
    /**
2175
     * Retrieves this user's related DRH sessions.
2176
     *
2177
     * @return Session[]
2178
     */
2179
    public function getDRHSessions(): array
2180
    {
2181
        return $this->getSessions(1);
2182
    }
2183
2184
    /**
2185
     * Get this user's related accessible sessions of a type, student by default.
2186
     *
2187
     * @param int $relationType \Chamilo\CoreBundle\Entity\SessionRelUser::relationTypeList key
2188
     *
2189
     * @return Session[]
2190
     */
2191
    public function getCurrentlyAccessibleSessions(int $relationType = 0): array
2192
    {
2193
        $sessions = [];
2194
        foreach ($this->getSessions($relationType) as $session) {
2195
            if ($session->isCurrentlyAccessible()) {
2196
                $sessions[] = $session;
2197
            }
2198
        }
2199
2200
        return $sessions;
2201
    }
2202
2203
    public function getResourceIdentifier(): int
2204
    {
2205
        return $this->id;
2206
    }
2207
2208
    public function getResourceName(): string
2209
    {
2210
        return $this->getUsername();
2211
    }
2212
2213
    public function setResourceName(string $name): void
2214
    {
2215
        $this->setUsername($name);
2216
    }
2217
2218
    public function setParent(AbstractResource $parent): void
2219
    {
2220
    }
2221
2222
    public function getDefaultIllustration(int $size): string
2223
    {
2224
        $size = empty($size) ? 32 : $size;
2225
2226
        return sprintf('/img/icons/%s/unknown.png', $size);
2227
    }
2228
2229
    /**
2230
     * Find the largest sort value in a given UserCourseCategory
2231
     * This method is used when we are moving a course to a different category
2232
     * and also when a user subscribes to courses (the new course is added at the end of the main category).
2233
     *
2234
     * Used to be implemented in global function \api_max_sort_value.
2235
     * Reimplemented using the ORM cache.
2236
     *
2237
     * @param null|UserCourseCategory $userCourseCategory the user_course_category
2238
     *
2239
     * @return int|mixed
2240
     */
2241
    public function getMaxSortValue(?UserCourseCategory $userCourseCategory = null)
2242
    {
2243
        $categoryCourses = $this->courses->matching(
2244
            Criteria::create()
2245
                ->where(Criteria::expr()->neq('relationType', COURSE_RELATION_TYPE_RRHH))
2246
                ->andWhere(Criteria::expr()->eq('userCourseCat', $userCourseCategory))
2247
        );
2248
2249
        return $categoryCourses->isEmpty()
2250
            ? 0
2251
            : max(
2252
                $categoryCourses->map(
2253
                    /** @var CourseRelUser $courseRelUser */
2254
                    function ($courseRelUser) {
2255
                        return $courseRelUser->getSort();
2256
                    }
2257
                )->toArray()
2258
            );
2259
    }
2260
}
2261