Passed
Push — master ( 4ed902...760dff )
by Julito
11:06 queued 11s
created

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