Passed
Push — master ( a30985...75a2b1 )
by Julito
10:34
created

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