Passed
Push — master ( 3ac343...373e44 )
by Angel Fernando Quiroz
08:23 queued 15s
created

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