Passed
Pull Request — master (#5836)
by
unknown
07:43
created

User::setMfaSecret()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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