Passed
Push — master ( b28532...61a578 )
by Julito
11:48 queued 36s
created

User::getLps()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

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