Passed
Push — master ( a4ad40...93e8b6 )
by Julito
08:20
created

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