Passed
Push — master ( bcea47...3c36a2 )
by Julito
11:00
created

User::setFullName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
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, ExtraFieldItemInterface
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
    #[Groups(['user:read', 'user_json:read'])]
794
    protected string $fullName;
795
796
    public function __construct()
797
    {
798
        $this->skipResourceNode = false;
799
        $this->uuid = Uuid::v4();
800
        $this->apiToken = null;
801
        $this->biography = '';
802
        $this->website = '';
803
        $this->locale = 'en';
804
        $this->timezone = 'Europe\Paris';
805
        $this->authSource = 'platform';
806
807
        $this->status = CourseRelUser::STUDENT;
808
        $this->salt = sha1(uniqid('', true));
809
        $this->active = true;
810
        $this->enabled = true;
811
        $this->locked = false;
812
        $this->expired = false;
813
814
        $this->courses = new ArrayCollection();
815
        $this->classes = new ArrayCollection();
816
        $this->curriculumItems = new ArrayCollection();
817
        $this->portals = new ArrayCollection();
818
        $this->dropBoxSentFiles = new ArrayCollection();
819
        $this->dropBoxReceivedFiles = new ArrayCollection();
820
        $this->groups = new ArrayCollection();
821
        $this->gradeBookCertificates = new ArrayCollection();
822
        $this->courseGroupsAsMember = new ArrayCollection();
823
        $this->courseGroupsAsTutor = new ArrayCollection();
824
        $this->resourceNodes = new ArrayCollection();
825
        $this->sessionRelCourseRelUsers = new ArrayCollection();
826
        $this->achievedSkills = new ArrayCollection();
827
        $this->commentedUserSkills = new ArrayCollection();
828
        $this->gradeBookCategories = new ArrayCollection();
829
        $this->gradeBookComments = new ArrayCollection();
830
        $this->gradeBookEvaluations = new ArrayCollection();
831
        $this->gradeBookLinks = new ArrayCollection();
832
        $this->gradeBookResults = new ArrayCollection();
833
        $this->gradeBookResultLogs = new ArrayCollection();
834
        $this->gradeBookScoreLogs = new ArrayCollection();
835
        $this->friends = new ArrayCollection();
836
        $this->friendsWithMe = new ArrayCollection();
837
        $this->gradeBookLinkEvalLogs = new ArrayCollection();
838
        $this->sequenceValues = new ArrayCollection();
839
        $this->trackEExerciseConfirmations = new ArrayCollection();
840
        $this->trackEAccessCompleteList = new ArrayCollection();
841
        $this->templates = new ArrayCollection();
842
        $this->trackEAttempts = new ArrayCollection();
843
        $this->trackECourseAccess = new ArrayCollection();
844
        $this->userCourseCategories = new ArrayCollection();
845
        $this->userRelCourseVotes = new ArrayCollection();
846
        $this->userRelTags = new ArrayCollection();
847
        $this->personalAgendas = new ArrayCollection();
848
        $this->sessionsRelUser = new ArrayCollection();
849
        $this->sentMessages = new ArrayCollection();
850
        $this->receivedMessages = new ArrayCollection();
851
        $this->surveyInvitations = new ArrayCollection();
852
        $this->logins = new ArrayCollection();
853
854
        //$this->extraFields = new ArrayCollection();
855
        $this->createdAt = new DateTime();
856
        $this->updatedAt = new DateTime();
857
        $this->registrationDate = new DateTime();
858
859
        $this->roles = [];
860
        $this->credentialsExpired = false;
861
        $this->credentialsExpireAt = new DateTime();
862
        $this->dateOfBirth = new DateTime();
863
        $this->expiresAt = new DateTime();
864
        $this->passwordRequestedAt = new DateTime();
865
    }
866
867
    public function __toString(): string
868
    {
869
        return $this->username;
870
    }
871
872
    public static function getPasswordConstraints(): array
873
    {
874
        return [
875
            new Assert\Length([
876
                'min' => 5,
877
            ]),
878
            // Alpha numeric + "_" or "-"
879
            new Assert\Regex(
880
                [
881
                    'pattern' => '/^[a-z\-_0-9]+$/i',
882
                    'htmlPattern' => '/^[a-z\-_0-9]+$/i',
883
                ]
884
            ),
885
            // Min 3 letters - not needed
886
            /*new Assert\Regex(array(
887
                    'pattern' => '/[a-z]{3}/i',
888
                    'htmlPattern' => '/[a-z]{3}/i')
889
                ),*/
890
            // Min 2 numbers
891
            new Assert\Regex(
892
                [
893
                    'pattern' => '/[0-9]{2}/',
894
                    'htmlPattern' => '/[0-9]{2}/',
895
                ]
896
            ),
897
        ];
898
    }
899
900
    public static function loadValidatorMetadata(ClassMetadata $metadata): void
901
    {
902
        //$metadata->addPropertyConstraint('firstname', new Assert\NotBlank());
903
        //$metadata->addPropertyConstraint('lastname', new Assert\NotBlank());
904
        //$metadata->addPropertyConstraint('email', new Assert\Email());
905
        /*
906
        $metadata->addPropertyConstraint('password',
907
            new Assert\Collection(self::getPasswordConstraints())
908
        );*/
909
910
        /*$metadata->addConstraint(new UniqueEntity(array(
911
            'fields'  => 'username',
912
            'message' => 'This value is already used.',
913
        )));*/
914
915
        /*$metadata->addPropertyConstraint(
916
            'username',
917
            new Assert\Length(array(
918
                'min'        => 2,
919
                'max'        => 50,
920
                '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.',
921
                '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.',
922
            ))
923
        );*/
924
    }
925
926
    public function getUuid(): UuidV4
927
    {
928
        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...
929
    }
930
931
    public function setUuid(UuidV4 $uuid): self
932
    {
933
        $this->uuid = $uuid;
934
935
        return $this;
936
    }
937
938
    public function getResourceNode(): ?ResourceNode
939
    {
940
        return $this->resourceNode;
941
    }
942
943
    public function setResourceNode(ResourceNode $resourceNode): self
944
    {
945
        $this->resourceNode = $resourceNode;
946
947
        return $this;
948
    }
949
950
    public function hasResourceNode(): bool
951
    {
952
        return $this->resourceNode instanceof ResourceNode;
953
    }
954
955
    public function getResourceNodes(): Collection
956
    {
957
        return $this->resourceNodes;
958
    }
959
960
    /**
961
     * @param Collection<int, ResourceNode>|ResourceNode[] $resourceNodes
962
     */
963
    public function setResourceNodes(Collection $resourceNodes): self
964
    {
965
        $this->resourceNodes = $resourceNodes;
966
967
        return $this;
968
    }
969
970
    public function getDropBoxSentFiles(): Collection
971
    {
972
        return $this->dropBoxSentFiles;
973
    }
974
975
    public function setDropBoxSentFiles(Collection $value): self
976
    {
977
        $this->dropBoxSentFiles = $value;
978
979
        return $this;
980
    }
981
982
    /*public function getDropBoxReceivedFiles()
983
    {
984
        return $this->dropBoxReceivedFiles;
985
    }
986
987
    public function setDropBoxReceivedFiles($value): void
988
    {
989
        $this->dropBoxReceivedFiles = $value;
990
    }*/
991
992
    public function getCourses(): Collection
993
    {
994
        return $this->courses;
995
    }
996
997
    /**
998
     * @param Collection<int, CourseRelUser>|CourseRelUser[] $courses
999
     */
1000
    public function setCourses(Collection $courses): self
1001
    {
1002
        $this->courses = $courses;
1003
1004
        return $this;
1005
    }
1006
1007
    public function setPortal(AccessUrlRelUser $portal): self
1008
    {
1009
        $this->portals->add($portal);
1010
1011
        return $this;
1012
    }
1013
1014
    /*public function getCurriculumItems(): Collection
1015
    {
1016
        return $this->curriculumItems;
1017
    }
1018
1019
    public function setCurriculumItems(array $items): self
1020
    {
1021
        $this->curriculumItems = $items;
1022
1023
        return $this;
1024
    }*/
1025
1026
    public function getIsActive(): bool
1027
    {
1028
        return $this->active;
1029
    }
1030
1031
    public function isEnabled(): bool
1032
    {
1033
        return $this->isActive();
1034
    }
1035
1036
    public function setEnabled(bool $boolean): self
1037
    {
1038
        $this->enabled = $boolean;
1039
1040
        return $this;
1041
    }
1042
1043
    public function getSalt(): ?string
1044
    {
1045
        return $this->salt;
1046
    }
1047
1048
    public function setSalt(string $salt): self
1049
    {
1050
        $this->salt = $salt;
1051
1052
        return $this;
1053
    }
1054
1055
    /**
1056
     * Returns the list of classes for the user.
1057
     */
1058
    public function getCompleteNameWithClasses(): string
1059
    {
1060
        $classSubscription = $this->getClasses();
1061
        $classList = [];
1062
        /** @var UsergroupRelUser $subscription */
1063
        foreach ($classSubscription as $subscription) {
1064
            $class = $subscription->getUsergroup();
1065
            $classList[] = $class->getName();
1066
        }
1067
        $classString = empty($classList) ? null : ' ['.implode(', ', $classList).']';
1068
1069
        return UserManager::formatUserFullName($this).$classString;
1070
    }
1071
1072
    public function getClasses(): Collection
1073
    {
1074
        return $this->classes;
1075
    }
1076
1077
    /**
1078
     * @param Collection<int, UsergroupRelUser>|UsergroupRelUser[] $classes
1079
     */
1080
    public function setClasses(Collection $classes): self
1081
    {
1082
        $this->classes = $classes;
1083
1084
        return $this;
1085
    }
1086
1087
    public function getPassword(): ?string
1088
    {
1089
        return $this->password;
1090
    }
1091
1092
    public function setPassword(string $password): self
1093
    {
1094
        $this->password = $password;
1095
1096
        return $this;
1097
    }
1098
1099
    public function getAuthSource(): ?string
1100
    {
1101
        return $this->authSource;
1102
    }
1103
1104
    public function setAuthSource(string $authSource): self
1105
    {
1106
        $this->authSource = $authSource;
1107
1108
        return $this;
1109
    }
1110
1111
    public function getEmail(): string
1112
    {
1113
        return $this->email;
1114
    }
1115
1116
    public function setEmail(string $email): self
1117
    {
1118
        $this->email = $email;
1119
1120
        return $this;
1121
    }
1122
1123
    public function getOfficialCode(): ?string
1124
    {
1125
        return $this->officialCode;
1126
    }
1127
1128
    public function setOfficialCode(?string $officialCode): self
1129
    {
1130
        $this->officialCode = $officialCode;
1131
1132
        return $this;
1133
    }
1134
1135
    public function getPhone(): ?string
1136
    {
1137
        return $this->phone;
1138
    }
1139
1140
    public function setPhone(?string $phone): self
1141
    {
1142
        $this->phone = $phone;
1143
1144
        return $this;
1145
    }
1146
1147
    public function getAddress(): ?string
1148
    {
1149
        return $this->address;
1150
    }
1151
1152
    public function setAddress(?string $address): self
1153
    {
1154
        $this->address = $address;
1155
1156
        return $this;
1157
    }
1158
1159
    public function getCreatorId(): ?int
1160
    {
1161
        return $this->creatorId;
1162
    }
1163
1164
    public function setCreatorId(int $creatorId): self
1165
    {
1166
        $this->creatorId = $creatorId;
1167
1168
        return $this;
1169
    }
1170
1171
    public function getCompetences(): ?string
1172
    {
1173
        return $this->competences;
1174
    }
1175
1176
    public function setCompetences(?string $competences): self
1177
    {
1178
        $this->competences = $competences;
1179
1180
        return $this;
1181
    }
1182
1183
    public function getDiplomas(): ?string
1184
    {
1185
        return $this->diplomas;
1186
    }
1187
1188
    public function setDiplomas(?string $diplomas): self
1189
    {
1190
        $this->diplomas = $diplomas;
1191
1192
        return $this;
1193
    }
1194
1195
    public function getOpenarea(): ?string
1196
    {
1197
        return $this->openarea;
1198
    }
1199
1200
    public function setOpenarea(?string $openarea): self
1201
    {
1202
        $this->openarea = $openarea;
1203
1204
        return $this;
1205
    }
1206
1207
    public function getTeach(): ?string
1208
    {
1209
        return $this->teach;
1210
    }
1211
1212
    public function setTeach(?string $teach): self
1213
    {
1214
        $this->teach = $teach;
1215
1216
        return $this;
1217
    }
1218
1219
    public function getProductions(): ?string
1220
    {
1221
        return $this->productions;
1222
    }
1223
1224
    public function setProductions(?string $productions): self
1225
    {
1226
        $this->productions = $productions;
1227
1228
        return $this;
1229
    }
1230
1231
    public function getRegistrationDate(): DateTime
1232
    {
1233
        return $this->registrationDate;
1234
    }
1235
1236
    public function setRegistrationDate(DateTime $registrationDate): self
1237
    {
1238
        $this->registrationDate = $registrationDate;
1239
1240
        return $this;
1241
    }
1242
1243
    public function getExpirationDate(): ?DateTime
1244
    {
1245
        return $this->expirationDate;
1246
    }
1247
1248
    public function setExpirationDate(?DateTime $expirationDate): self
1249
    {
1250
        $this->expirationDate = $expirationDate;
1251
1252
        return $this;
1253
    }
1254
1255
    public function getActive(): bool
1256
    {
1257
        return $this->active;
1258
    }
1259
1260
    public function isActive(): bool
1261
    {
1262
        return $this->getIsActive();
1263
    }
1264
1265
    public function setActive(bool $active): self
1266
    {
1267
        $this->active = $active;
1268
1269
        return $this;
1270
    }
1271
1272
    public function getOpenid(): ?string
1273
    {
1274
        return $this->openid;
1275
    }
1276
1277
    public function setOpenid(string $openid): self
1278
    {
1279
        $this->openid = $openid;
1280
1281
        return $this;
1282
    }
1283
1284
    public function getTheme(): ?string
1285
    {
1286
        return $this->theme;
1287
    }
1288
1289
    public function setTheme(string $theme): self
1290
    {
1291
        $this->theme = $theme;
1292
1293
        return $this;
1294
    }
1295
1296
    public function getHrDeptId(): ?int
1297
    {
1298
        return $this->hrDeptId;
1299
    }
1300
1301
    public function setHrDeptId(int $hrDeptId): self
1302
    {
1303
        $this->hrDeptId = $hrDeptId;
1304
1305
        return $this;
1306
    }
1307
1308
    public function getMemberSince(): DateTime
1309
    {
1310
        return $this->registrationDate;
1311
    }
1312
1313
    public function isOnline(): bool
1314
    {
1315
        return false;
1316
    }
1317
1318
    public function getIdentifier(): int
1319
    {
1320
        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...
1321
    }
1322
1323
    public function getId(): ?int
1324
    {
1325
        return $this->id;
1326
    }
1327
1328
    public function getIri(): ?string
1329
    {
1330
        if (null === $this->id) {
1331
            return null;
1332
        }
1333
1334
        return '/api/users/'.$this->getId();
1335
    }
1336
1337
    public function getSlug(): string
1338
    {
1339
        return $this->getUsername();
1340
    }
1341
1342
    public function getUsername(): string
1343
    {
1344
        return $this->username;
1345
    }
1346
1347
    public function getUserIdentifier(): string
1348
    {
1349
        return $this->username;
1350
    }
1351
1352
    public function setUsername(string $username): self
1353
    {
1354
        $this->username = $username;
1355
1356
        return $this;
1357
    }
1358
1359
    public function setSlug(string $slug): self
1360
    {
1361
        return $this->setUsername($slug);
1362
    }
1363
1364
    public function getLastLogin(): ?DateTime
1365
    {
1366
        return $this->lastLogin;
1367
    }
1368
1369
    public function setLastLogin(DateTime $lastLogin = null): self
1370
    {
1371
        $this->lastLogin = $lastLogin;
1372
1373
        return $this;
1374
    }
1375
1376
    public function getConfirmationToken(): ?string
1377
    {
1378
        return $this->confirmationToken;
1379
    }
1380
1381
    public function setConfirmationToken(string $confirmationToken): self
1382
    {
1383
        $this->confirmationToken = $confirmationToken;
1384
1385
        return $this;
1386
    }
1387
1388
    public function isPasswordRequestNonExpired(int $ttl): bool
1389
    {
1390
        return $this->getPasswordRequestedAt() instanceof DateTime
1391
            && $this->getPasswordRequestedAt()->getTimestamp() + $ttl > time();
1392
    }
1393
1394
    public function getPasswordRequestedAt(): ?DateTime
1395
    {
1396
        return $this->passwordRequestedAt;
1397
    }
1398
1399
    public function setPasswordRequestedAt(DateTime $date = null): self
1400
    {
1401
        $this->passwordRequestedAt = $date;
1402
1403
        return $this;
1404
    }
1405
1406
    public function getPlainPassword(): ?string
1407
    {
1408
        return $this->plainPassword;
1409
    }
1410
1411
    public function setPlainPassword(string $password): self
1412
    {
1413
        $this->plainPassword = $password;
1414
1415
        // forces the object to look "dirty" to Doctrine. Avoids
1416
        // Doctrine *not* saving this entity, if only plainPassword changes
1417
        $this->password = '';
1418
1419
        return $this;
1420
    }
1421
1422
    /**
1423
     * Returns the expiration date.
1424
     */
1425
    public function getExpiresAt(): ?DateTime
1426
    {
1427
        return $this->expiresAt;
1428
    }
1429
1430
    public function setExpiresAt(DateTime $date): self
1431
    {
1432
        $this->expiresAt = $date;
1433
1434
        return $this;
1435
    }
1436
1437
    /**
1438
     * Returns the credentials expiration date.
1439
     */
1440
    public function getCredentialsExpireAt(): ?DateTime
1441
    {
1442
        return $this->credentialsExpireAt;
1443
    }
1444
1445
    /**
1446
     * Sets the credentials expiration date.
1447
     */
1448
    public function setCredentialsExpireAt(DateTime $date = null): self
1449
    {
1450
        $this->credentialsExpireAt = $date;
1451
1452
        return $this;
1453
    }
1454
1455
    public function getFullname(): string
1456
    {
1457
        if (empty($this->fullName)) {
1458
            return sprintf('%s %s', $this->getFirstname(), $this->getLastname());
1459
        }
1460
1461
        return $this->fullName;
1462
    }
1463
1464
    public function getFirstname(): ?string
1465
    {
1466
        return $this->firstname;
1467
    }
1468
1469
    public function setFirstname(string $firstname): self
1470
    {
1471
        $this->firstname = $firstname;
1472
1473
        return $this;
1474
    }
1475
1476
    public function getLastname(): ?string
1477
    {
1478
        return $this->lastname;
1479
    }
1480
1481
    public function setLastname(string $lastname): self
1482
    {
1483
        $this->lastname = $lastname;
1484
1485
        return $this;
1486
    }
1487
1488
    public function hasGroup(string $name): bool
1489
    {
1490
        return \in_array($name, $this->getGroupNames(), true);
1491
    }
1492
1493
    public function getGroupNames(): array
1494
    {
1495
        $names = [];
1496
        foreach ($this->getGroups() as $group) {
1497
            $names[] = $group->getName();
1498
        }
1499
1500
        return $names;
1501
    }
1502
1503
    public function getGroups(): Collection
1504
    {
1505
        return $this->groups;
1506
    }
1507
1508
    /**
1509
     * Sets the user groups.
1510
     */
1511
    public function setGroups(Collection $groups): self
1512
    {
1513
        foreach ($groups as $group) {
1514
            $this->addGroup($group);
1515
        }
1516
1517
        return $this;
1518
    }
1519
1520
    public function addGroup(Group $group): self
1521
    {
1522
        if (!$this->getGroups()->contains($group)) {
1523
            $this->getGroups()->add($group);
1524
        }
1525
1526
        return $this;
1527
    }
1528
1529
    public function removeGroup(Group $group): self
1530
    {
1531
        if ($this->getGroups()->contains($group)) {
1532
            $this->getGroups()->removeElement($group);
1533
        }
1534
1535
        return $this;
1536
    }
1537
1538
    public function isAccountNonExpired(): bool
1539
    {
1540
        /*if (true === $this->expired) {
1541
            return false;
1542
        }
1543
1544
        if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
1545
            return false;
1546
        }*/
1547
1548
        return true;
1549
    }
1550
1551
    public function isAccountNonLocked(): bool
1552
    {
1553
        return true;
1554
        //return !$this->locked;
1555
    }
1556
1557
    public function isCredentialsNonExpired(): bool
1558
    {
1559
        /*if (true === $this->credentialsExpired) {
1560
            return false;
1561
        }
1562
1563
        if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
1564
            return false;
1565
        }*/
1566
1567
        return true;
1568
    }
1569
1570
    public function getCredentialsExpired(): bool
1571
    {
1572
        return $this->credentialsExpired;
1573
    }
1574
1575
    public function setCredentialsExpired(bool $boolean): self
1576
    {
1577
        $this->credentialsExpired = $boolean;
1578
1579
        return $this;
1580
    }
1581
1582
    public function getExpired(): bool
1583
    {
1584
        return $this->expired;
1585
    }
1586
1587
    /**
1588
     * Sets this user to expired.
1589
     */
1590
    public function setExpired(bool $boolean): self
1591
    {
1592
        $this->expired = $boolean;
1593
1594
        return $this;
1595
    }
1596
1597
    public function getLocked(): bool
1598
    {
1599
        return $this->locked;
1600
    }
1601
1602
    public function setLocked(bool $boolean): self
1603
    {
1604
        $this->locked = $boolean;
1605
1606
        return $this;
1607
    }
1608
1609
    /**
1610
     * Check if the user has the skill.
1611
     *
1612
     * @param Skill $skill The skill
1613
     */
1614
    public function hasSkill(Skill $skill): bool
1615
    {
1616
        $achievedSkills = $this->getAchievedSkills();
1617
1618
        foreach ($achievedSkills as $userSkill) {
1619
            if ($userSkill->getSkill()->getId() !== $skill->getId()) {
1620
                continue;
1621
            }
1622
1623
            return true;
1624
        }
1625
1626
        return false;
1627
    }
1628
1629
    public function getAchievedSkills(): Collection
1630
    {
1631
        return $this->achievedSkills;
1632
    }
1633
1634
    /**
1635
     * @param Collection<int, SkillRelUser>|SkillRelUser[] $value
1636
     */
1637
    public function setAchievedSkills(Collection $value): self
1638
    {
1639
        $this->achievedSkills = $value;
1640
1641
        return $this;
1642
    }
1643
1644
    public function isProfileCompleted(): ?bool
1645
    {
1646
        return $this->profileCompleted;
1647
    }
1648
1649
    public function setProfileCompleted(?bool $profileCompleted): self
1650
    {
1651
        $this->profileCompleted = $profileCompleted;
1652
1653
        return $this;
1654
    }
1655
1656
    public function getCurrentUrl(): ?AccessUrl
1657
    {
1658
        return $this->currentUrl;
1659
    }
1660
1661
    public function setCurrentUrl(AccessUrl $url): self
1662
    {
1663
        $accessUrlRelUser = (new AccessUrlRelUser())
1664
            ->setUrl($url)
1665
            ->setUser($this)
1666
        ;
1667
        $this->getPortals()->add($accessUrlRelUser);
1668
1669
        return $this;
1670
    }
1671
1672
    public function getPortals(): Collection
1673
    {
1674
        return $this->portals;
1675
    }
1676
1677
    /**
1678
     * @param AccessUrlRelUser[]|Collection<int, AccessUrlRelUser> $value
1679
     */
1680
    public function setPortals(Collection $value): void
1681
    {
1682
        $this->portals = $value;
1683
    }
1684
1685
    public function getSessionsAsGeneralCoach(): array
1686
    {
1687
        return $this->getSessions(Session::GENERAL_COACH);
1688
    }
1689
1690
    public function getSessionsAsAdmin(): array
1691
    {
1692
        return $this->getSessions(Session::SESSION_ADMIN);
1693
    }
1694
1695
    public function getCommentedUserSkills(): Collection
1696
    {
1697
        return $this->commentedUserSkills;
1698
    }
1699
1700
    /**
1701
     * @param Collection<int, SkillRelUserComment>|SkillRelUserComment[] $commentedUserSkills
1702
     */
1703
    public function setCommentedUserSkills(Collection $commentedUserSkills): self
1704
    {
1705
        $this->commentedUserSkills = $commentedUserSkills;
1706
1707
        return $this;
1708
    }
1709
1710
    public function isEqualTo(UserInterface $user): bool
1711
    {
1712
        if ($this->password !== $user->getPassword()) {
1713
            return false;
1714
        }
1715
1716
        if ($this->salt !== $user->getSalt()) {
1717
            return false;
1718
        }
1719
1720
        if ($this->username !== $user->getUserIdentifier()) {
1721
            return false;
1722
        }
1723
1724
        return true;
1725
    }
1726
1727
    public function getSentMessages(): Collection
1728
    {
1729
        return $this->sentMessages;
1730
    }
1731
1732
    public function getReceivedMessages(): Collection
1733
    {
1734
        return $this->receivedMessages;
1735
    }
1736
1737
    public function getCourseGroupsAsMember(): Collection
1738
    {
1739
        return $this->courseGroupsAsMember;
1740
    }
1741
1742
    public function getCourseGroupsAsTutor(): Collection
1743
    {
1744
        return $this->courseGroupsAsTutor;
1745
    }
1746
1747
    public function getCourseGroupsAsMemberFromCourse(Course $course): Collection
1748
    {
1749
        $criteria = Criteria::create();
1750
        $criteria->where(
1751
            Criteria::expr()->eq('cId', $course)
1752
        );
1753
1754
        return $this->courseGroupsAsMember->matching($criteria);
1755
    }
1756
1757
    public function eraseCredentials(): void
1758
    {
1759
        $this->plainPassword = null;
1760
    }
1761
1762
    public function isSuperAdmin(): bool
1763
    {
1764
        return $this->hasRole('ROLE_SUPER_ADMIN');
1765
    }
1766
1767
    public static function getRoleFromStatus(int $status): string
1768
    {
1769
        return match ($status) {
1770
            COURSEMANAGER => 'ROLE_TEACHER',
1771
            STUDENT => 'ROLE_STUDENT',
1772
            DRH => 'ROLE_RRHH',
1773
            SESSIONADMIN => 'ROLE_SESSION_MANAGER',
1774
            STUDENT_BOSS => 'ROLE_STUDENT_BOSS',
1775
            INVITEE => 'ROLE_INVITEE',
1776
            default => 'ROLE_USER',
1777
        };
1778
    }
1779
1780
    public function setRoleFromStatus(int $status): void
1781
    {
1782
        $role = self::getRoleFromStatus($status);
1783
1784
        $this->addRole($role);
1785
    }
1786
1787
    public function hasRole(string $role): bool
1788
    {
1789
        return \in_array(strtoupper($role), $this->getRoles(), true);
1790
    }
1791
1792
    /**
1793
     * Returns the user roles.
1794
     */
1795
    public function getRoles(): array
1796
    {
1797
        $roles = $this->roles;
1798
1799
        foreach ($this->getGroups() as $group) {
1800
            $roles = array_merge($roles, $group->getRoles());
1801
        }
1802
1803
        // we need to make sure to have at least one role
1804
        $roles[] = 'ROLE_USER';
1805
1806
        return array_unique($roles);
1807
    }
1808
1809
    public function setRoles(array $roles): self
1810
    {
1811
        $this->roles = [];
1812
1813
        foreach ($roles as $role) {
1814
            $this->addRole($role);
1815
        }
1816
1817
        return $this;
1818
    }
1819
1820
    public function addRole(string $role): self
1821
    {
1822
        $role = strtoupper($role);
1823
        if ($role === static::ROLE_DEFAULT || empty($role)) {
1824
            return $this;
1825
        }
1826
1827
        if (!\in_array($role, $this->roles, true)) {
1828
            $this->roles[] = $role;
1829
        }
1830
1831
        return $this;
1832
    }
1833
1834
    public function removeRole(string $role): self
1835
    {
1836
        if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
1837
            unset($this->roles[$key]);
1838
            $this->roles = array_values($this->roles);
1839
        }
1840
1841
        return $this;
1842
    }
1843
1844
    public function getUsernameCanonical(): string
1845
    {
1846
        return $this->usernameCanonical;
1847
    }
1848
1849
    public function setUsernameCanonical(string $usernameCanonical): self
1850
    {
1851
        $this->usernameCanonical = $usernameCanonical;
1852
1853
        return $this;
1854
    }
1855
1856
    public function getEmailCanonical(): string
1857
    {
1858
        return $this->emailCanonical;
1859
    }
1860
1861
    public function setEmailCanonical(string $emailCanonical): self
1862
    {
1863
        $this->emailCanonical = $emailCanonical;
1864
1865
        return $this;
1866
    }
1867
1868
    public function getTimezone(): string
1869
    {
1870
        return $this->timezone;
1871
    }
1872
1873
    public function setTimezone(string $timezone): self
1874
    {
1875
        $this->timezone = $timezone;
1876
1877
        return $this;
1878
    }
1879
1880
    public function getLocale(): string
1881
    {
1882
        return $this->locale;
1883
    }
1884
1885
    public function setLocale(string $locale): self
1886
    {
1887
        $this->locale = $locale;
1888
1889
        return $this;
1890
    }
1891
1892
    public function getApiToken(): ?string
1893
    {
1894
        return $this->apiToken;
1895
    }
1896
1897
    public function setApiToken(string $apiToken): self
1898
    {
1899
        $this->apiToken = $apiToken;
1900
1901
        return $this;
1902
    }
1903
1904
    public function getWebsite(): ?string
1905
    {
1906
        return $this->website;
1907
    }
1908
1909
    public function setWebsite(string $website): self
1910
    {
1911
        $this->website = $website;
1912
1913
        return $this;
1914
    }
1915
1916
    public function getBiography(): ?string
1917
    {
1918
        return $this->biography;
1919
    }
1920
1921
    public function setBiography(string $biography): self
1922
    {
1923
        $this->biography = $biography;
1924
1925
        return $this;
1926
    }
1927
1928
    public function getDateOfBirth(): ?DateTime
1929
    {
1930
        return $this->dateOfBirth;
1931
    }
1932
1933
    public function setDateOfBirth(DateTime $dateOfBirth = null): self
1934
    {
1935
        $this->dateOfBirth = $dateOfBirth;
1936
1937
        return $this;
1938
    }
1939
1940
    public function getProfileUrl(): string
1941
    {
1942
        return '/main/social/profile.php?u='.$this->id;
1943
    }
1944
1945
    public function getIconStatus(): string
1946
    {
1947
        $hasCertificates = $this->getGradeBookCertificates()->count() > 0;
1948
        $urlImg = '/img/';
1949
1950
        if ($this->isStudent()) {
1951
            $iconStatus = $urlImg.'icons/svg/identifier_student.svg';
1952
            if ($hasCertificates) {
1953
                $iconStatus = $urlImg.'icons/svg/identifier_graduated.svg';
1954
            }
1955
1956
            return $iconStatus;
1957
        }
1958
1959
        if ($this->isTeacher()) {
1960
            $iconStatus = $urlImg.'icons/svg/identifier_teacher.svg';
1961
            if ($this->isAdmin()) {
1962
                $iconStatus = $urlImg.'icons/svg/identifier_admin.svg';
1963
            }
1964
1965
            return $iconStatus;
1966
        }
1967
1968
        if ($this->isStudentBoss()) {
1969
            return $urlImg.'icons/svg/identifier_teacher.svg';
1970
        }
1971
1972
        return '';
1973
    }
1974
1975
    public function getStatus(): int
1976
    {
1977
        return $this->status;
1978
    }
1979
1980
    public function setStatus(int $status): self
1981
    {
1982
        $this->status = $status;
1983
1984
        return $this;
1985
    }
1986
1987
    public function getPictureUri(): ?string
1988
    {
1989
        return $this->pictureUri;
1990
    }
1991
1992
    public function getGradeBookCertificates(): Collection
1993
    {
1994
        return $this->gradeBookCertificates;
1995
    }
1996
1997
    /**
1998
     * @param Collection<int, GradebookCertificate>|GradebookCertificate[] $gradeBookCertificates
1999
     */
2000
    public function setGradeBookCertificates(Collection $gradeBookCertificates): self
2001
    {
2002
        $this->gradeBookCertificates = $gradeBookCertificates;
2003
2004
        return $this;
2005
    }
2006
2007
    public function isStudent(): bool
2008
    {
2009
        return $this->hasRole('ROLE_STUDENT');
2010
    }
2011
2012
    public function isStudentBoss(): bool
2013
    {
2014
        return $this->hasRole('ROLE_STUDENT_BOSS');
2015
    }
2016
2017
    public function isTeacher(): bool
2018
    {
2019
        return $this->hasRole('ROLE_TEACHER');
2020
    }
2021
2022
    public function isAdmin(): bool
2023
    {
2024
        return $this->hasRole('ROLE_ADMIN');
2025
    }
2026
2027
    /**
2028
     * @return GradebookCategory[]|Collection
2029
     */
2030
    public function getGradeBookCategories()
2031
    {
2032
        return $this->gradeBookCategories;
2033
    }
2034
2035
    /**
2036
     * @return GradebookComment[]|Collection
2037
     */
2038
    public function getGradeBookComments()
2039
    {
2040
        return $this->gradeBookComments;
2041
    }
2042
2043
    /**
2044
     * @return GradebookEvaluation[]|Collection
2045
     */
2046
    public function getGradeBookEvaluations()
2047
    {
2048
        return $this->gradeBookEvaluations;
2049
    }
2050
2051
    /**
2052
     * @return GradebookLink[]|Collection
2053
     */
2054
    public function getGradeBookLinks()
2055
    {
2056
        return $this->gradeBookLinks;
2057
    }
2058
2059
    /**
2060
     * @return GradebookResult[]|Collection
2061
     */
2062
    public function getGradeBookResults()
2063
    {
2064
        return $this->gradeBookResults;
2065
    }
2066
2067
    /**
2068
     * @return GradebookResultLog[]|Collection
2069
     */
2070
    public function getGradeBookResultLogs()
2071
    {
2072
        return $this->gradeBookResultLogs;
2073
    }
2074
2075
    /**
2076
     * @return GradebookScoreLog[]|Collection
2077
     */
2078
    public function getGradeBookScoreLogs()
2079
    {
2080
        return $this->gradeBookScoreLogs;
2081
    }
2082
2083
    /**
2084
     * @return GradebookLinkevalLog[]|Collection
2085
     */
2086
    public function getGradeBookLinkEvalLogs()
2087
    {
2088
        return $this->gradeBookLinkEvalLogs;
2089
    }
2090
2091
    /**
2092
     * @return UserRelCourseVote[]|Collection
2093
     */
2094
    public function getUserRelCourseVotes()
2095
    {
2096
        return $this->userRelCourseVotes;
2097
    }
2098
2099
    /**
2100
     * @return UserRelTag[]|Collection
2101
     */
2102
    public function getUserRelTags()
2103
    {
2104
        return $this->userRelTags;
2105
    }
2106
2107
    /**
2108
     * @return PersonalAgenda[]|Collection
2109
     */
2110
    public function getPersonalAgendas()
2111
    {
2112
        return $this->personalAgendas;
2113
    }
2114
2115
    /**
2116
     * @return Collection|mixed[]
2117
     */
2118
    public function getCurriculumItems()
2119
    {
2120
        return $this->curriculumItems;
2121
    }
2122
2123
    /**
2124
     * @return UserRelUser[]|Collection
2125
     */
2126
    public function getFriends()
2127
    {
2128
        return $this->friends;
2129
    }
2130
2131
    /**
2132
     * @param int $relationType Example: UserRelUser::USER_RELATION_TYPE_BOSS
2133
     *
2134
     * @return UserRelUser[]|Collection
2135
     */
2136
    public function getFriendsByRelationType(int $relationType)
2137
    {
2138
        return $this->friends->filter(function (UserRelUser $userRelUser) use ($relationType) {
2139
            return $relationType === $userRelUser->getRelationType();
2140
        });
2141
    }
2142
2143
    /**
2144
     * @return UserRelUser[]|Collection
2145
     */
2146
    public function getFriendsWithMe()
2147
    {
2148
        return $this->friendsWithMe;
2149
    }
2150
2151
    public function addFriend(self $friend): self
2152
    {
2153
        return $this->addUserRelUser($friend, UserRelUser::USER_RELATION_TYPE_FRIEND);
2154
    }
2155
2156
    public function addUserRelUser(self $friend, int $relationType): self
2157
    {
2158
        $userRelUser = (new UserRelUser())
2159
            ->setUser($this)
2160
            ->setFriend($friend)
2161
            ->setRelationType($relationType)
2162
        ;
2163
        $this->friends->add($userRelUser);
2164
2165
        return $this;
2166
    }
2167
2168
    /**
2169
     * @return Templates[]|Collection
2170
     */
2171
    public function getTemplates()
2172
    {
2173
        return $this->templates;
2174
    }
2175
2176
    /**
2177
     * @return ArrayCollection|Collection
2178
     */
2179
    public function getDropBoxReceivedFiles()
2180
    {
2181
        return $this->dropBoxReceivedFiles;
2182
    }
2183
2184
    /**
2185
     * @return SequenceValue[]|Collection
2186
     */
2187
    public function getSequenceValues()
2188
    {
2189
        return $this->sequenceValues;
2190
    }
2191
2192
    /**
2193
     * @return TrackEExerciseConfirmation[]|Collection
2194
     */
2195
    public function getTrackEExerciseConfirmations()
2196
    {
2197
        return $this->trackEExerciseConfirmations;
2198
    }
2199
2200
    /**
2201
     * @return TrackEAttempt[]|Collection
2202
     */
2203
    public function getTrackEAccessCompleteList()
2204
    {
2205
        return $this->trackEAccessCompleteList;
2206
    }
2207
2208
    /**
2209
     * @return TrackEAttempt[]|Collection
2210
     */
2211
    public function getTrackEAttempts()
2212
    {
2213
        return $this->trackEAttempts;
2214
    }
2215
2216
    /**
2217
     * @return TrackECourseAccess[]|Collection
2218
     */
2219
    public function getTrackECourseAccess()
2220
    {
2221
        return $this->trackECourseAccess;
2222
    }
2223
2224
    /**
2225
     * @return UserCourseCategory[]|Collection
2226
     */
2227
    public function getUserCourseCategories()
2228
    {
2229
        return $this->userCourseCategories;
2230
    }
2231
2232
    public function getCourseGroupsAsTutorFromCourse(Course $course): Collection
2233
    {
2234
        $criteria = Criteria::create();
2235
        $criteria->where(
2236
            Criteria::expr()->eq('cId', $course->getId())
2237
        );
2238
2239
        return $this->courseGroupsAsTutor->matching($criteria);
2240
    }
2241
2242
    /**
2243
     * Retrieves this user's related student sessions.
2244
     *
2245
     * @return Session[]
2246
     */
2247
    public function getStudentSessions(): array
2248
    {
2249
        return $this->getSessions(Session::STUDENT);
2250
    }
2251
2252
    /**
2253
     * @return SessionRelUser[]|Collection
2254
     */
2255
    public function getSessionsRelUser()
2256
    {
2257
        return $this->sessionsRelUser;
2258
    }
2259
2260
    public function isSkipResourceNode(): bool
2261
    {
2262
        return $this->skipResourceNode;
2263
    }
2264
2265
    public function setSkipResourceNode(bool $skipResourceNode): self
2266
    {
2267
        $this->skipResourceNode = $skipResourceNode;
2268
2269
        return $this;
2270
    }
2271
2272
    /**
2273
     * Retrieves this user's related sessions.
2274
     *
2275
     * @return Session[]
2276
     */
2277
    public function getSessions(int $relationType): array
2278
    {
2279
        $sessions = [];
2280
        foreach ($this->getSessionsRelUser() as $sessionRelUser) {
2281
            if ($sessionRelUser->getRelationType() === $relationType) {
2282
                $sessions[] = $sessionRelUser->getSession();
2283
            }
2284
        }
2285
2286
        return $sessions;
2287
    }
2288
2289
    /**
2290
     * Retrieves this user's related DRH sessions.
2291
     *
2292
     * @return Session[]
2293
     */
2294
    public function getDRHSessions(): array
2295
    {
2296
        return $this->getSessions(Session::DRH);
2297
    }
2298
2299
    /**
2300
     * Get this user's related accessible sessions of a type, student by default.
2301
     *
2302
     * @return Session[]
2303
     */
2304
    public function getCurrentlyAccessibleSessions(int $relationType = Session::STUDENT): array
2305
    {
2306
        $sessions = [];
2307
        foreach ($this->getSessions($relationType) as $session) {
2308
            if ($session->isCurrentlyAccessible()) {
2309
                $sessions[] = $session;
2310
            }
2311
        }
2312
2313
        return $sessions;
2314
    }
2315
2316
    public function getResourceIdentifier(): int
2317
    {
2318
        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...
2319
    }
2320
2321
    public function getResourceName(): string
2322
    {
2323
        return $this->getUsername();
2324
    }
2325
2326
    public function setResourceName(string $name): void
2327
    {
2328
        $this->setUsername($name);
2329
    }
2330
2331
    public function setParent(AbstractResource $parent): void
2332
    {
2333
    }
2334
2335
    public function getDefaultIllustration(int $size): string
2336
    {
2337
        $size = empty($size) ? 32 : $size;
2338
2339
        return sprintf('/img/icons/%s/unknown.png', $size);
2340
    }
2341
2342
    public function getAdmin(): ?Admin
2343
    {
2344
        return $this->admin;
2345
    }
2346
2347
    public function setAdmin(?Admin $admin): self
2348
    {
2349
        $this->admin = $admin;
2350
2351
        return $this;
2352
    }
2353
2354
    public function addUserAsAdmin(): self
2355
    {
2356
        if (null === $this->admin) {
2357
            $admin = new Admin();
2358
            $admin->setUser($this);
2359
            $this->setAdmin($admin);
2360
            $this->addRole('ROLE_ADMIN');
2361
        }
2362
2363
        return $this;
2364
    }
2365
2366
    public function getSessionsByStatusInCourseSubscription(int $status): Collection
2367
    {
2368
        $criteria = Criteria::create()->where(
2369
            Criteria::expr()->eq('status', $status)
2370
        );
2371
2372
        return $this
2373
            ->getSessionRelCourseRelUsers()
2374
            ->matching($criteria)
2375
            ->map(fn (SessionRelCourseRelUser $sessionRelCourseRelUser) => $sessionRelCourseRelUser->getSession())
2376
        ;
2377
    }
2378
2379
    /**
2380
     * @return SessionRelCourseRelUser[]|Collection
2381
     */
2382
    public function getSessionRelCourseRelUsers()
2383
    {
2384
        return $this->sessionRelCourseRelUsers;
2385
    }
2386
2387
    /**
2388
     * @param SessionRelCourseRelUser[]|Collection $sessionRelCourseRelUsers
2389
     */
2390
    public function setSessionRelCourseRelUsers($sessionRelCourseRelUsers): self
2391
    {
2392
        $this->sessionRelCourseRelUsers = $sessionRelCourseRelUsers;
2393
2394
        return $this;
2395
    }
2396
2397
    public function getGender(): ?string
2398
    {
2399
        return $this->gender;
2400
    }
2401
2402
    public function setGender(?string $gender): self
2403
    {
2404
        $this->gender = $gender;
2405
2406
        return $this;
2407
    }
2408
2409
    /**
2410
     * @return CSurveyInvitation[]|Collection
2411
     */
2412
    public function getSurveyInvitations()
2413
    {
2414
        return $this->surveyInvitations;
2415
    }
2416
2417
    public function setSurveyInvitations(Collection $surveyInvitations): self
2418
    {
2419
        $this->surveyInvitations = $surveyInvitations;
2420
2421
        return $this;
2422
    }
2423
2424
    /**
2425
     * @return TrackELogin[]|Collection
2426
     */
2427
    public function getLogins()
2428
    {
2429
        return $this->logins;
2430
    }
2431
2432
    public function setLogins(Collection $logins): self
2433
    {
2434
        $this->logins = $logins;
2435
2436
        return $this;
2437
    }
2438
2439
    /**
2440
     * @return MessageTag[]|Collection
2441
     */
2442
    public function getMessageTags()
2443
    {
2444
        return $this->messageTags;
2445
    }
2446
2447
    /**
2448
     * @param MessageTag[]|Collection $messageTags
2449
     */
2450
    public function setMessageTags($messageTags): self
2451
    {
2452
        $this->messageTags = $messageTags;
2453
2454
        return $this;
2455
    }
2456
2457
    /**
2458
     * @todo move in a repo
2459
     * Find the largest sort value in a given UserCourseCategory
2460
     * This method is used when we are moving a course to a different category
2461
     * and also when a user subscribes to courses (the new course is added at the end of the main category).
2462
     *
2463
     * Used to be implemented in global function \api_max_sort_value.
2464
     * Reimplemented using the ORM cache.
2465
     *
2466
     * @param null|UserCourseCategory $userCourseCategory the user_course_category
2467
     */
2468
    public function getMaxSortValue(?UserCourseCategory $userCourseCategory = null): int
2469
    {
2470
        $categoryCourses = $this->courses->matching(
2471
            Criteria::create()
2472
                ->where(Criteria::expr()->neq('relationType', COURSE_RELATION_TYPE_RRHH))
2473
                ->andWhere(Criteria::expr()->eq('userCourseCat', $userCourseCategory))
2474
        );
2475
2476
        return $categoryCourses->isEmpty()
2477
            ? 0
2478
            : max(
2479
                $categoryCourses->map(
2480
                    function ($courseRelUser) {
2481
                        return $courseRelUser->getSort();
2482
                    }
2483
                )->toArray()
2484
            );
2485
    }
2486
2487
    public function setFullName(string $fullName): self
2488
    {
2489
        $this->fullName = $fullName;
2490
2491
        return $this;
2492
    }
2493
}
2494