Passed
Pull Request — master (#5718)
by
unknown
16:51
created

User::getCreatorId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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