Passed
Push — master ( b61354...af9f4d )
by Julito
19:31
created

User::getCurrentUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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