Passed
Push — master ( 0ade09...5f933d )
by Julito
10:26
created

User::setLocked()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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