Passed
Push — master ( b95980...a81919 )
by Julito
08:46
created

User::getSessionsRelUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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