Passed
Push — master ( e157d2...b7d807 )
by Julito
12:22
created

User::isEnabled()   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_ADMIN')"},
43
 *     iri="http://schema.org/Person",
44
 *     normalizationContext={"groups"={"user:read"}},
45
 *     denormalizationContext={"groups"={"user:write"}},
46
 *     collectionOperations={
47
 *         "get"={"security"="is_granted('ROLE_ADMIN')"},
48
 *         "post"={"security"="is_granted('ROLE_ADMIN')"}
49
 *     },
50
 *     itemOperations={
51
 *         "get"={"security"="is_granted('ROLE_ADMIN')"},
52
 *         "put"={"security"="is_granted('ROLE_ADMIN')"},
53
 *     },
54
 * )
55
 *
56
 * @ORM\Table(
57
 *     name="user",
58
 *     indexes={
59
 *         @ORM\Index(name="status", columns={"status"})
60
 *     }
61
 * )
62
 * @UniqueEntity("username")
63
 * @ORM\Entity
64
 * @ORM\EntityListeners({"Chamilo\CoreBundle\Entity\Listener\UserListener"})
65
 */
66
#[ApiFilter(SearchFilter::class, properties: [
67
    'username' => 'partial',
68
    'firstname' => 'partial',
69
    'lastname' => 'partial',
70
])]
71
#[ApiFilter(BooleanFilter::class, properties: ['isActive'])]
72
73
class User implements UserInterface, EquatableInterface, ResourceInterface, ResourceIllustrationInterface, PasswordAuthenticatedUserInterface, LegacyPasswordAuthenticatedUserInterface
74
{
75
    use TimestampableEntity;
76
    use UserCreatorTrait;
77
78
    public const USERNAME_MAX_LENGTH = 100;
79
    public const ROLE_DEFAULT = 'ROLE_USER';
80
    public const ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN';
81
    public const COURSE_MANAGER = 1;
82
    public const TEACHER = 1;
83
    public const SESSION_ADMIN = 3;
84
    public const DRH = 4;
85
    public const STUDENT = 5;
86
    public const ANONYMOUS = 6;
87
88
    /**
89
     * @Groups({"user_json:read"})
90
     *
91
     * @ORM\OneToOne(
92
     *     targetEntity="Chamilo\CoreBundle\Entity\ResourceNode", cascade={"remove"}, orphanRemoval=true
93
     * )
94
     * @ORM\JoinColumn(name="resource_node_id", onDelete="CASCADE")
95
     */
96
    public ?ResourceNode $resourceNode = null;
97
98
    /**
99
     * Resource illustration URL - Property set by ResourceNormalizer.php.
100
     *
101
     * @ApiProperty(iri="http://schema.org/contentUrl")
102
     */
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 getSlug(): string
1305
    {
1306
        return $this->getUsername();
1307
    }
1308
1309
    public function getUsername(): string
1310
    {
1311
        return $this->username;
1312
    }
1313
1314
    public function getUserIdentifier(): string
1315
    {
1316
        return $this->username;
1317
    }
1318
1319
    public function setUsername(string $username): self
1320
    {
1321
        $this->username = $username;
1322
1323
        return $this;
1324
    }
1325
1326
    public function setSlug(string $slug): self
1327
    {
1328
        return $this->setUsername($slug);
1329
    }
1330
1331
    public function getLastLogin(): ?DateTime
1332
    {
1333
        return $this->lastLogin;
1334
    }
1335
1336
    public function setLastLogin(DateTime $lastLogin = null): self
1337
    {
1338
        $this->lastLogin = $lastLogin;
1339
1340
        return $this;
1341
    }
1342
1343
    public function getConfirmationToken(): ?string
1344
    {
1345
        return $this->confirmationToken;
1346
    }
1347
1348
    public function setConfirmationToken(string $confirmationToken): self
1349
    {
1350
        $this->confirmationToken = $confirmationToken;
1351
1352
        return $this;
1353
    }
1354
1355
    public function isPasswordRequestNonExpired(int $ttl): bool
1356
    {
1357
        return $this->getPasswordRequestedAt() instanceof DateTime &&
1358
            $this->getPasswordRequestedAt()->getTimestamp() + $ttl > time();
1359
    }
1360
1361
    public function getPasswordRequestedAt(): ?DateTime
1362
    {
1363
        return $this->passwordRequestedAt;
1364
    }
1365
1366
    public function setPasswordRequestedAt(DateTime $date = null): self
1367
    {
1368
        $this->passwordRequestedAt = $date;
1369
1370
        return $this;
1371
    }
1372
1373
    public function getPlainPassword(): ?string
1374
    {
1375
        return $this->plainPassword;
1376
    }
1377
1378
    public function setPlainPassword(string $password): self
1379
    {
1380
        $this->plainPassword = $password;
1381
1382
        // forces the object to look "dirty" to Doctrine. Avoids
1383
        // Doctrine *not* saving this entity, if only plainPassword changes
1384
        $this->password = '';
1385
1386
        return $this;
1387
    }
1388
1389
    /**
1390
     * Returns the expiration date.
1391
     */
1392
    public function getExpiresAt(): ?DateTime
1393
    {
1394
        return $this->expiresAt;
1395
    }
1396
1397
    public function setExpiresAt(DateTime $date): self
1398
    {
1399
        $this->expiresAt = $date;
1400
1401
        return $this;
1402
    }
1403
1404
    /**
1405
     * Returns the credentials expiration date.
1406
     */
1407
    public function getCredentialsExpireAt(): ?DateTime
1408
    {
1409
        return $this->credentialsExpireAt;
1410
    }
1411
1412
    /**
1413
     * Sets the credentials expiration date.
1414
     */
1415
    public function setCredentialsExpireAt(DateTime $date = null): self
1416
    {
1417
        $this->credentialsExpireAt = $date;
1418
1419
        return $this;
1420
    }
1421
1422
    public function getFullname(): string
1423
    {
1424
        return sprintf('%s %s', $this->getFirstname(), $this->getLastname());
1425
    }
1426
1427
    public function getFirstname(): ?string
1428
    {
1429
        return $this->firstname;
1430
    }
1431
1432
    public function setFirstname(string $firstname): self
1433
    {
1434
        $this->firstname = $firstname;
1435
1436
        return $this;
1437
    }
1438
1439
    public function getLastname(): ?string
1440
    {
1441
        return $this->lastname;
1442
    }
1443
1444
    public function setLastname(string $lastname): self
1445
    {
1446
        $this->lastname = $lastname;
1447
1448
        return $this;
1449
    }
1450
1451
    public function hasGroup(string $name): bool
1452
    {
1453
        return \in_array($name, $this->getGroupNames(), true);
1454
    }
1455
1456
    public function getGroupNames(): array
1457
    {
1458
        $names = [];
1459
        foreach ($this->getGroups() as $group) {
1460
            $names[] = $group->getName();
1461
        }
1462
1463
        return $names;
1464
    }
1465
1466
    public function getGroups(): Collection
1467
    {
1468
        return $this->groups;
1469
    }
1470
1471
    /**
1472
     * Sets the user groups.
1473
     */
1474
    public function setGroups(Collection $groups): self
1475
    {
1476
        foreach ($groups as $group) {
1477
            $this->addGroup($group);
1478
        }
1479
1480
        return $this;
1481
    }
1482
1483
    public function addGroup(Group $group): self
1484
    {
1485
        if (!$this->getGroups()->contains($group)) {
1486
            $this->getGroups()->add($group);
1487
        }
1488
1489
        return $this;
1490
    }
1491
1492
    public function removeGroup(Group $group): self
1493
    {
1494
        if ($this->getGroups()->contains($group)) {
1495
            $this->getGroups()->removeElement($group);
1496
        }
1497
1498
        return $this;
1499
    }
1500
1501
    public function isAccountNonExpired(): bool
1502
    {
1503
        /*if (true === $this->expired) {
1504
            return false;
1505
        }
1506
1507
        if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
1508
            return false;
1509
        }*/
1510
1511
        return true;
1512
    }
1513
1514
    public function isAccountNonLocked(): bool
1515
    {
1516
        return true;
1517
        //return !$this->locked;
1518
    }
1519
1520
    public function isCredentialsNonExpired(): bool
1521
    {
1522
        /*if (true === $this->credentialsExpired) {
1523
            return false;
1524
        }
1525
1526
        if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
1527
            return false;
1528
        }*/
1529
1530
        return true;
1531
    }
1532
1533
    public function getCredentialsExpired(): bool
1534
    {
1535
        return $this->credentialsExpired;
1536
    }
1537
1538
    public function setCredentialsExpired(bool $boolean): self
1539
    {
1540
        $this->credentialsExpired = $boolean;
1541
1542
        return $this;
1543
    }
1544
1545
    public function getExpired(): bool
1546
    {
1547
        return $this->expired;
1548
    }
1549
1550
    /**
1551
     * Sets this user to expired.
1552
     */
1553
    public function setExpired(bool $boolean): self
1554
    {
1555
        $this->expired = $boolean;
1556
1557
        return $this;
1558
    }
1559
1560
    public function getLocked(): bool
1561
    {
1562
        return $this->locked;
1563
    }
1564
1565
    public function setLocked(bool $boolean): self
1566
    {
1567
        $this->locked = $boolean;
1568
1569
        return $this;
1570
    }
1571
1572
    /**
1573
     * Check if the user has the skill.
1574
     *
1575
     * @param Skill $skill The skill
1576
     */
1577
    public function hasSkill(Skill $skill): bool
1578
    {
1579
        $achievedSkills = $this->getAchievedSkills();
1580
1581
        foreach ($achievedSkills as $userSkill) {
1582
            if ($userSkill->getSkill()->getId() !== $skill->getId()) {
1583
                continue;
1584
            }
1585
1586
            return true;
1587
        }
1588
1589
        return false;
1590
    }
1591
1592
    public function getAchievedSkills(): Collection
1593
    {
1594
        return $this->achievedSkills;
1595
    }
1596
1597
    /**
1598
     * @param Collection<int, SkillRelUser>|SkillRelUser[] $value
1599
     */
1600
    public function setAchievedSkills(Collection $value): self
1601
    {
1602
        $this->achievedSkills = $value;
1603
1604
        return $this;
1605
    }
1606
1607
    public function isProfileCompleted(): ?bool
1608
    {
1609
        return $this->profileCompleted;
1610
    }
1611
1612
    public function setProfileCompleted(?bool $profileCompleted): self
1613
    {
1614
        $this->profileCompleted = $profileCompleted;
1615
1616
        return $this;
1617
    }
1618
1619
    public function getCurrentUrl(): AccessUrl
1620
    {
1621
        return $this->currentUrl;
1622
    }
1623
1624
    /**
1625
     * Sets the AccessUrl for the current user in memory.
1626
     */
1627
    public function setCurrentUrl(AccessUrl $url): self
1628
    {
1629
        $urlList = $this->getPortals();
1630
        /** @var AccessUrlRelUser $item */
1631
        foreach ($urlList as $item) {
1632
            if ($item->getUrl()->getId() === $url->getId()) {
1633
                $this->currentUrl = $url;
1634
1635
                break;
1636
            }
1637
        }
1638
1639
        return $this;
1640
    }
1641
1642
    public function getPortals(): Collection
1643
    {
1644
        return $this->portals;
1645
    }
1646
1647
    /**
1648
     * @param AccessUrlRelUser[]|Collection<int, AccessUrlRelUser> $value
1649
     */
1650
    public function setPortals(Collection $value): void
1651
    {
1652
        $this->portals = $value;
1653
    }
1654
1655
    public function getSessionsAsGeneralCoach(): Collection
1656
    {
1657
        return $this->sessionsAsGeneralCoach;
1658
    }
1659
1660
    /**
1661
     * @param Collection<int, Session>|Session[] $value
1662
     */
1663
    public function setSessionsAsGeneralCoach(Collection $value): self
1664
    {
1665
        $this->sessionsAsGeneralCoach = $value;
1666
1667
        return $this;
1668
    }
1669
1670
    public function getCommentedUserSkills(): Collection
1671
    {
1672
        return $this->commentedUserSkills;
1673
    }
1674
1675
    /**
1676
     * @param Collection<int, SkillRelUserComment>|SkillRelUserComment[] $commentedUserSkills
1677
     */
1678
    public function setCommentedUserSkills(Collection $commentedUserSkills): self
1679
    {
1680
        $this->commentedUserSkills = $commentedUserSkills;
1681
1682
        return $this;
1683
    }
1684
1685
    public function isEqualTo(UserInterface $user): bool
1686
    {
1687
        if ($this->password !== $user->getPassword()) {
1688
            return false;
1689
        }
1690
1691
        if ($this->salt !== $user->getSalt()) {
1692
            return false;
1693
        }
1694
1695
        if ($this->username !== $user->getUserIdentifier()) {
1696
            return false;
1697
        }
1698
1699
        return true;
1700
    }
1701
1702
    public function getSentMessages(): Collection
1703
    {
1704
        return $this->sentMessages;
1705
    }
1706
1707
    public function getReceivedMessages(): Collection
1708
    {
1709
        return $this->receivedMessages;
1710
    }
1711
1712
    public function getCourseGroupsAsMember(): Collection
1713
    {
1714
        return $this->courseGroupsAsMember;
1715
    }
1716
1717
    public function getCourseGroupsAsTutor(): Collection
1718
    {
1719
        return $this->courseGroupsAsTutor;
1720
    }
1721
1722
    public function getCourseGroupsAsMemberFromCourse(Course $course): Collection
1723
    {
1724
        $criteria = Criteria::create();
1725
        $criteria->where(
1726
            Criteria::expr()->eq('cId', $course)
1727
        );
1728
1729
        return $this->courseGroupsAsMember->matching($criteria);
1730
    }
1731
1732
    public function eraseCredentials(): void
1733
    {
1734
        $this->plainPassword = null;
1735
    }
1736
1737
    public function isSuperAdmin(): bool
1738
    {
1739
        return $this->hasRole('ROLE_SUPER_ADMIN');
1740
    }
1741
1742
    public function hasRole(string $role): bool
1743
    {
1744
        return \in_array(strtoupper($role), $this->getRoles(), true);
1745
    }
1746
1747
    /**
1748
     * Returns the user roles.
1749
     *
1750
     * @return array The roles
1751
     */
1752
    public function getRoles(): array
1753
    {
1754
        $roles = $this->roles;
1755
1756
        foreach ($this->getGroups() as $group) {
1757
            $roles = array_merge($roles, $group->getRoles());
1758
        }
1759
1760
        // we need to make sure to have at least one role
1761
        $roles[] = 'ROLE_USER';
1762
1763
        return array_unique($roles);
1764
    }
1765
1766
    public function setRoles(array $roles): self
1767
    {
1768
        $this->roles = [];
1769
1770
        foreach ($roles as $role) {
1771
            $this->addRole($role);
1772
        }
1773
1774
        return $this;
1775
    }
1776
1777
    public function addRole(string $role): self
1778
    {
1779
        $role = strtoupper($role);
1780
        if ($role === static::ROLE_DEFAULT) {
1781
            return $this;
1782
        }
1783
1784
        if (!\in_array($role, $this->roles, true)) {
1785
            $this->roles[] = $role;
1786
        }
1787
1788
        return $this;
1789
    }
1790
1791
    public function isUser(self $user = null): bool
1792
    {
1793
        return null !== $user && $this->getId() === $user->getId();
1794
    }
1795
1796
    public function removeRole(string $role): self
1797
    {
1798
        if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
1799
            unset($this->roles[$key]);
1800
            $this->roles = array_values($this->roles);
1801
        }
1802
1803
        return $this;
1804
    }
1805
1806
    public function getUsernameCanonical(): string
1807
    {
1808
        return $this->usernameCanonical;
1809
    }
1810
1811
    public function setUsernameCanonical(string $usernameCanonical): self
1812
    {
1813
        $this->usernameCanonical = $usernameCanonical;
1814
1815
        return $this;
1816
    }
1817
1818
    public function getEmailCanonical(): string
1819
    {
1820
        return $this->emailCanonical;
1821
    }
1822
1823
    public function setEmailCanonical(string $emailCanonical): self
1824
    {
1825
        $this->emailCanonical = $emailCanonical;
1826
1827
        return $this;
1828
    }
1829
1830
    public function getTimezone(): string
1831
    {
1832
        return $this->timezone;
1833
    }
1834
1835
    public function setTimezone(string $timezone): self
1836
    {
1837
        $this->timezone = $timezone;
1838
1839
        return $this;
1840
    }
1841
1842
    public function getLocale(): string
1843
    {
1844
        return $this->locale;
1845
    }
1846
1847
    public function setLocale(string $locale): self
1848
    {
1849
        $this->locale = $locale;
1850
1851
        return $this;
1852
    }
1853
1854
    public function getApiToken(): ?string
1855
    {
1856
        return $this->apiToken;
1857
    }
1858
1859
    public function setApiToken(string $apiToken): self
1860
    {
1861
        $this->apiToken = $apiToken;
1862
1863
        return $this;
1864
    }
1865
1866
    public function getWebsite(): ?string
1867
    {
1868
        return $this->website;
1869
    }
1870
1871
    public function setWebsite(string $website): self
1872
    {
1873
        $this->website = $website;
1874
1875
        return $this;
1876
    }
1877
1878
    public function getBiography(): ?string
1879
    {
1880
        return $this->biography;
1881
    }
1882
1883
    public function setBiography(string $biography): self
1884
    {
1885
        $this->biography = $biography;
1886
1887
        return $this;
1888
    }
1889
1890
    public function getDateOfBirth(): ?DateTime
1891
    {
1892
        return $this->dateOfBirth;
1893
    }
1894
1895
    public function setDateOfBirth(DateTime $dateOfBirth = null): self
1896
    {
1897
        $this->dateOfBirth = $dateOfBirth;
1898
1899
        return $this;
1900
    }
1901
1902
    public function getProfileUrl(): string
1903
    {
1904
        return '/main/social/profile.php?u='.$this->id;
1905
    }
1906
1907
    public function getIconStatus(): string
1908
    {
1909
        $status = $this->getStatus();
1910
        $hasCertificates = $this->getGradeBookCertificates()->count() > 0;
1911
        $urlImg = '/img/';
1912
        $iconStatus = '';
1913
        switch ($status) {
1914
            case self::STUDENT:
1915
                if ($hasCertificates) {
1916
                    $iconStatus = $urlImg.'icons/svg/identifier_graduated.svg';
1917
                } else {
1918
                    $iconStatus = $urlImg.'icons/svg/identifier_student.svg';
1919
                }
1920
1921
                break;
1922
            case self::COURSE_MANAGER:
1923
                if ($this->isAdmin()) {
1924
                    $iconStatus = $urlImg.'icons/svg/identifier_admin.svg';
1925
                } else {
1926
                    $iconStatus = $urlImg.'icons/svg/identifier_teacher.svg';
1927
                }
1928
1929
                break;
1930
            case STUDENT_BOSS:
1931
                $iconStatus = $urlImg.'icons/svg/identifier_teacher.svg';
1932
1933
                break;
1934
        }
1935
1936
        return $iconStatus;
1937
    }
1938
1939
    public function getStatus(): int
1940
    {
1941
        return $this->status;
1942
    }
1943
1944
    public function setStatus(int $status): self
1945
    {
1946
        $this->status = $status;
1947
1948
        return $this;
1949
    }
1950
1951
    public function getPictureUri(): ?string
1952
    {
1953
        return $this->pictureUri;
1954
    }
1955
1956
    public function getGradeBookCertificates(): Collection
1957
    {
1958
        return $this->gradeBookCertificates;
1959
    }
1960
1961
    /**
1962
     * @param Collection<int, GradebookCertificate>|GradebookCertificate[] $gradeBookCertificates
1963
     */
1964
    public function setGradeBookCertificates(Collection $gradeBookCertificates): self
1965
    {
1966
        $this->gradeBookCertificates = $gradeBookCertificates;
1967
1968
        return $this;
1969
    }
1970
1971
    public function isAdmin(): bool
1972
    {
1973
        return $this->hasRole('ROLE_ADMIN');
1974
    }
1975
1976
    /**
1977
     * @return GradebookCategory[]|Collection
1978
     */
1979
    public function getGradeBookCategories()
1980
    {
1981
        return $this->gradeBookCategories;
1982
    }
1983
1984
    /**
1985
     * @return GradebookComment[]|Collection
1986
     */
1987
    public function getGradeBookComments()
1988
    {
1989
        return $this->gradeBookComments;
1990
    }
1991
1992
    /**
1993
     * @return GradebookEvaluation[]|Collection
1994
     */
1995
    public function getGradeBookEvaluations()
1996
    {
1997
        return $this->gradeBookEvaluations;
1998
    }
1999
2000
    /**
2001
     * @return GradebookLink[]|Collection
2002
     */
2003
    public function getGradeBookLinks()
2004
    {
2005
        return $this->gradeBookLinks;
2006
    }
2007
2008
    /**
2009
     * @return GradebookResult[]|Collection
2010
     */
2011
    public function getGradeBookResults()
2012
    {
2013
        return $this->gradeBookResults;
2014
    }
2015
2016
    /**
2017
     * @return GradebookResultLog[]|Collection
2018
     */
2019
    public function getGradeBookResultLogs()
2020
    {
2021
        return $this->gradeBookResultLogs;
2022
    }
2023
2024
    /**
2025
     * @return GradebookScoreLog[]|Collection
2026
     */
2027
    public function getGradeBookScoreLogs()
2028
    {
2029
        return $this->gradeBookScoreLogs;
2030
    }
2031
2032
    /**
2033
     * @return GradebookLinkevalLog[]|Collection
2034
     */
2035
    public function getGradeBookLinkEvalLogs()
2036
    {
2037
        return $this->gradeBookLinkEvalLogs;
2038
    }
2039
2040
    /**
2041
     * @return UserRelCourseVote[]|Collection
2042
     */
2043
    public function getUserRelCourseVotes()
2044
    {
2045
        return $this->userRelCourseVotes;
2046
    }
2047
2048
    /**
2049
     * @return UserRelTag[]|Collection
2050
     */
2051
    public function getUserRelTags()
2052
    {
2053
        return $this->userRelTags;
2054
    }
2055
2056
    /**
2057
     * @return PersonalAgenda[]|Collection
2058
     */
2059
    public function getPersonalAgendas()
2060
    {
2061
        return $this->personalAgendas;
2062
    }
2063
2064
    /**
2065
     * @return Collection|mixed[]
2066
     */
2067
    public function getCurriculumItems()
2068
    {
2069
        return $this->curriculumItems;
2070
    }
2071
2072
    /**
2073
     * @return UserRelUser[]|Collection
2074
     */
2075
    public function getUserRelUsers()
2076
    {
2077
        return $this->userRelUsers;
2078
    }
2079
2080
    /**
2081
     * @return Templates[]|Collection
2082
     */
2083
    public function getTemplates()
2084
    {
2085
        return $this->templates;
2086
    }
2087
2088
    /**
2089
     * @return ArrayCollection|Collection
2090
     */
2091
    public function getDropBoxReceivedFiles()
2092
    {
2093
        return $this->dropBoxReceivedFiles;
2094
    }
2095
2096
    /**
2097
     * @return SequenceValue[]|Collection
2098
     */
2099
    public function getSequenceValues()
2100
    {
2101
        return $this->sequenceValues;
2102
    }
2103
2104
    /**
2105
     * @return TrackEExerciseConfirmation[]|Collection
2106
     */
2107
    public function getTrackEExerciseConfirmations()
2108
    {
2109
        return $this->trackEExerciseConfirmations;
2110
    }
2111
2112
    /**
2113
     * @return TrackEAttempt[]|Collection
2114
     */
2115
    public function getTrackEAccessCompleteList()
2116
    {
2117
        return $this->trackEAccessCompleteList;
2118
    }
2119
2120
    /**
2121
     * @return TrackEAttempt[]|Collection
2122
     */
2123
    public function getTrackEAttempts()
2124
    {
2125
        return $this->trackEAttempts;
2126
    }
2127
2128
    /**
2129
     * @return TrackECourseAccess[]|Collection
2130
     */
2131
    public function getTrackECourseAccess()
2132
    {
2133
        return $this->trackECourseAccess;
2134
    }
2135
2136
    /**
2137
     * @return UserCourseCategory[]|Collection
2138
     */
2139
    public function getUserCourseCategories()
2140
    {
2141
        return $this->userCourseCategories;
2142
    }
2143
2144
    public function getCourseGroupsAsTutorFromCourse(Course $course): Collection
2145
    {
2146
        $criteria = Criteria::create();
2147
        $criteria->where(
2148
            Criteria::expr()->eq('cId', $course->getId())
2149
        );
2150
2151
        return $this->courseGroupsAsTutor->matching($criteria);
2152
    }
2153
2154
    /**
2155
     * Retrieves this user's related student sessions.
2156
     *
2157
     * @return Session[]
2158
     */
2159
    public function getStudentSessions(): array
2160
    {
2161
        return $this->getSessions(0);
2162
    }
2163
2164
    /**
2165
     * @return SessionRelUser[]|Collection
2166
     */
2167
    public function getSessionsRelUser()
2168
    {
2169
        return $this->sessionsRelUser;
2170
    }
2171
2172
    public function isSkipResourceNode(): bool
2173
    {
2174
        return $this->skipResourceNode;
2175
    }
2176
2177
    public function setSkipResourceNode(bool $skipResourceNode): self
2178
    {
2179
        $this->skipResourceNode = $skipResourceNode;
2180
2181
        return $this;
2182
    }
2183
2184
    /**
2185
     * Retreives this user's related sessions.
2186
     *
2187
     * @param int $relationType \Chamilo\CoreBundle\Entity\SessionRelUser::relationTypeList key
2188
     *
2189
     * @return Session[]
2190
     */
2191
    public function getSessions(int $relationType): array
2192
    {
2193
        $sessions = [];
2194
        foreach ($this->getSessionsRelUser() as $sessionRelUser) {
2195
            if ($sessionRelUser->getRelationType() === $relationType) {
2196
                $sessions[] = $sessionRelUser->getSession();
2197
            }
2198
        }
2199
2200
        return $sessions;
2201
    }
2202
2203
    /**
2204
     * Retrieves this user's related DRH sessions.
2205
     *
2206
     * @return Session[]
2207
     */
2208
    public function getDRHSessions(): array
2209
    {
2210
        return $this->getSessions(1);
2211
    }
2212
2213
    /**
2214
     * Get this user's related accessible sessions of a type, student by default.
2215
     *
2216
     * @param int $relationType \Chamilo\CoreBundle\Entity\SessionRelUser::relationTypeList key
2217
     *
2218
     * @return Session[]
2219
     */
2220
    public function getCurrentlyAccessibleSessions(int $relationType = 0): array
2221
    {
2222
        $sessions = [];
2223
        foreach ($this->getSessions($relationType) as $session) {
2224
            if ($session->isCurrentlyAccessible()) {
2225
                $sessions[] = $session;
2226
            }
2227
        }
2228
2229
        return $sessions;
2230
    }
2231
2232
    public function getResourceIdentifier(): int
2233
    {
2234
        return $this->id;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->id could return the type null which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
2235
    }
2236
2237
    public function getResourceName(): string
2238
    {
2239
        return $this->getUsername();
2240
    }
2241
2242
    public function setResourceName(string $name): void
2243
    {
2244
        $this->setUsername($name);
2245
    }
2246
2247
    public function setParent(AbstractResource $parent): void
2248
    {
2249
    }
2250
2251
    public function getDefaultIllustration(int $size): string
2252
    {
2253
        $size = empty($size) ? 32 : $size;
2254
2255
        return sprintf('/img/icons/%s/unknown.png', $size);
2256
    }
2257
2258
    public function getAdmin(): ?Admin
2259
    {
2260
        return $this->admin;
2261
    }
2262
2263
    public function setAdmin(?Admin $admin): self
2264
    {
2265
        $this->admin = $admin;
2266
2267
        return $this;
2268
    }
2269
2270
    public function addUserAsAdmin(): self
2271
    {
2272
        if (null === $this->admin) {
2273
            $admin = new Admin();
2274
            $admin->setUser($this);
2275
            $this->setAdmin($admin);
2276
        }
2277
2278
        return $this;
2279
    }
2280
2281
    /**
2282
     * @return SessionRelCourseRelUser[]|Collection
2283
     */
2284
    public function getSessionRelCourseRelUsers()
2285
    {
2286
        return $this->sessionRelCourseRelUsers;
2287
    }
2288
2289
    /**
2290
     * @param SessionRelCourseRelUser[]|Collection $sessionRelCourseRelUsers
2291
     */
2292
    public function setSessionRelCourseRelUsers($sessionRelCourseRelUsers): self
2293
    {
2294
        $this->sessionRelCourseRelUsers = $sessionRelCourseRelUsers;
2295
2296
        return $this;
2297
    }
2298
2299
    public function getGender(): ?string
2300
    {
2301
        return $this->gender;
2302
    }
2303
2304
    public function setGender(?string $gender): self
2305
    {
2306
        $this->gender = $gender;
2307
2308
        return $this;
2309
    }
2310
2311
    /**
2312
     * @return CSurveyInvitation[]|Collection
2313
     */
2314
    public function getSurveyInvitations()
2315
    {
2316
        return $this->surveyInvitations;
2317
    }
2318
2319
    public function setSurveyInvitations(Collection $surveyInvitations): self
2320
    {
2321
        $this->surveyInvitations = $surveyInvitations;
2322
2323
        return $this;
2324
    }
2325
2326
    /**
2327
     * @return TrackELogin[]|Collection
2328
     */
2329
    public function getLogins()
2330
    {
2331
        return $this->logins;
2332
    }
2333
2334
    public function setLogins(Collection $logins): self
2335
    {
2336
        $this->logins = $logins;
2337
2338
        return $this;
2339
    }
2340
2341
    /**
2342
     * @todo move in a repo
2343
     * Find the largest sort value in a given UserCourseCategory
2344
     * This method is used when we are moving a course to a different category
2345
     * and also when a user subscribes to courses (the new course is added at the end of the main category).
2346
     *
2347
     * Used to be implemented in global function \api_max_sort_value.
2348
     * Reimplemented using the ORM cache.
2349
     *
2350
     * @param null|UserCourseCategory $userCourseCategory the user_course_category
2351
     *
2352
     * @return int|mixed
2353
     */
2354
    public function getMaxSortValue(?UserCourseCategory $userCourseCategory = null)
2355
    {
2356
        $categoryCourses = $this->courses->matching(
2357
            Criteria::create()
2358
                ->where(Criteria::expr()->neq('relationType', COURSE_RELATION_TYPE_RRHH))
2359
                ->andWhere(Criteria::expr()->eq('userCourseCat', $userCourseCategory))
2360
        );
2361
2362
        return $categoryCourses->isEmpty()
2363
            ? 0
2364
            : max(
2365
                $categoryCourses->map(
2366
                    /** @var CourseRelUser $courseRelUser */
2367
                    function ($courseRelUser) {
2368
                        return $courseRelUser->getSort();
2369
                    }
2370
                )->toArray()
2371
            );
2372
    }
2373
}
2374