Passed
Push — master ( 48aeb9...852133 )
by Julito
09:44
created

User::isSuperAdmin()   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
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Entity;
6
7
use ApiPlatform\Core\Annotation\ApiFilter;
8
use ApiPlatform\Core\Annotation\ApiProperty;
9
use ApiPlatform\Core\Annotation\ApiResource;
10
use ApiPlatform\Core\Annotation\ApiSubresource;
11
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
12
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
13
use Chamilo\CourseBundle\Entity\CGroupRelUser;
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Doctrine\Common\Collections\Criteria;
17
use Doctrine\ORM\Event\LifecycleEventArgs;
18
use Doctrine\ORM\Mapping as ORM;
19
use Gedmo\Timestampable\Traits\TimestampableEntity;
20
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
21
use Symfony\Component\Security\Core\User\EquatableInterface;
22
use Symfony\Component\Security\Core\User\UserInterface;
23
use Symfony\Component\Serializer\Annotation\Groups;
24
use Symfony\Component\Uid\Uuid;
25
use Symfony\Component\Uid\UuidV4;
26
use Symfony\Component\Validator\Constraints as Assert;
27
use Symfony\Component\Validator\Mapping\ClassMetadata;
28
29
/**
30
 * @ApiResource(
31
 *      attributes={"security"="is_granted('ROLE_ADMIN')"},
32
 *      iri="http://schema.org/Person",
33
 *      normalizationContext={"groups"={"user:read"}},
34
 *      denormalizationContext={"groups"={"user:write"}},
35
 *      collectionOperations={"get"},
36
 *      itemOperations={
37
 *          "get"={},
38
 *          "put"={},
39
 *          "delete"={},
40
 *     }
41
 * )
42
 *
43
 * @ApiFilter(SearchFilter::class, properties={"username": "partial", "firstname" : "partial"})
44
 * @ApiFilter(BooleanFilter::class, properties={"isActive"})
45
 *
46
 * @ORM\HasLifecycleCallbacks
47
 * @ORM\Table(
48
 *  name="user",
49
 *  indexes={
50
 *      @ORM\Index(name="status", columns={"status"})
51
 *  }
52
 * )
53
 * @UniqueEntity("username")
54
 * @ORM\Entity
55
 */
56
class User implements UserInterface, EquatableInterface, ResourceInterface, ResourceIllustrationInterface
57
{
58
    use TimestampableEntity;
59
60
    public const ROLE_DEFAULT = 'ROLE_USER';
61
    public const ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN';
62
63
    public const COURSE_MANAGER = 1;
64
    public const TEACHER = 1;
65
    public const SESSION_ADMIN = 3;
66
    public const DRH = 4;
67
    public const STUDENT = 5;
68
    public const ANONYMOUS = 6;
69
70
    /**
71
     * @Groups({"user:read", "resource_node:read"})
72
     * @ORM\Column(name="id", type="integer")
73
     * @ORM\Id
74
     * @ORM\GeneratedValue(strategy="AUTO")
75
     */
76
    protected int $id;
77
78
    /**
79
     * @ORM\Column(name="api_token", type="string", unique=true, nullable=true)
80
     */
81
    protected $apiToken;
82
83
    /**
84
     * @var string
85
     * @Assert\NotBlank()
86
     * @ApiProperty(iri="http://schema.org/name")
87
     * @Groups({"user:read", "user:write", "resource_node:read"})
88
     * @ORM\Column(name="firstname", type="string", length=64, nullable=true, unique=false)
89
     */
90
    protected $firstname;
91
92
    /**
93
     * @var string
94
     * @Groups({"user:read", "user:write", "resource_node:read"})
95
     * @ORM\Column(name="lastname", type="string", length=64, nullable=true, unique=false)
96
     */
97
    protected $lastname;
98
99
    /**
100
     * @var string
101
     * @Groups({"user:read", "user:write"})
102
     * @ORM\Column(name="website", type="string", length=255, nullable=true)
103
     */
104
    protected $website;
105
106
    /**
107
     * @var string
108
     * @Groups({"user:read", "user:write"})
109
     * @ORM\Column(name="biography", type="text", nullable=true)
110
     */
111
    protected $biography;
112
113
    /**
114
     * @var string
115
     * @Groups({"user:read", "user:write"})
116
     * @ORM\Column(name="locale", type="string", length=8, nullable=true, unique=false)
117
     */
118
    protected $locale;
119
120
    /**
121
     * @var string
122
     * @Groups({"user:read", "user:write", "course:read", "resource_node:read"})
123
     * @Assert\NotBlank()
124
     * @ORM\Column(name="username", type="string", length=100, nullable=false, unique=true)
125
     */
126
    protected $username;
127
128
    /**
129
     * @var string|null
130
     */
131
    protected $plainPassword;
132
133
    /**
134
     * @var string
135
     * @ORM\Column(name="password", type="string", length=255, nullable=false, unique=false)
136
     */
137
    protected $password;
138
139
    /**
140
     * @var string
141
     *
142
     * @ORM\Column(name="username_canonical", type="string", length=180, nullable=false)
143
     */
144
    protected $usernameCanonical;
145
146
    /**
147
     * @var string
148
     * @Groups({"user:read", "user:write"})
149
     * @ORM\Column(name="timezone", type="string", length=64)
150
     */
151
    protected $timezone;
152
153
    /**
154
     * @var string
155
     * @ORM\Column(name="email_canonical", type="string", length=100, nullable=false, unique=false)
156
     */
157
    protected $emailCanonical;
158
159
    /**
160
     * @var string
161
     * @var string
162
     * @Groups({"user:read", "user:write"})
163
     * @Assert\NotBlank()
164
     * @Assert\Email()
165
     *
166
     * @ORM\Column(name="email", type="string", length=100, nullable=false, unique=false)
167
     */
168
    protected $email;
169
170
    /**
171
     * @var bool
172
     *
173
     * @ORM\Column(name="locked", type="boolean")
174
     */
175
    protected $locked;
176
177
    /**
178
     * @var bool
179
     * @Assert\NotBlank()
180
     * @Groups({"user:read", "user:write"})
181
     * @ORM\Column(name="enabled", type="boolean")
182
     */
183
    protected $enabled;
184
185
    /**
186
     * @var bool
187
     * @Groups({"user:read", "user:write"})
188
     * @ORM\Column(name="expired", type="boolean")
189
     */
190
    protected $expired;
191
192
    /**
193
     * @var bool
194
     *
195
     * @ORM\Column(name="credentials_expired", type="boolean")
196
     */
197
    protected $credentialsExpired;
198
199
    /**
200
     * @var \DateTime
201
     *
202
     * @ORM\Column(name="credentials_expire_at", type="datetime", nullable=true, unique=false)
203
     */
204
    protected $credentialsExpireAt;
205
206
    /**
207
     * @var \DateTime
208
     *
209
     * @ORM\Column(name="date_of_birth", type="datetime", nullable=true)
210
     */
211
    protected $dateOfBirth;
212
213
    /**
214
     * @var \DateTime
215
     * @Groups({"user:read", "user:write"})
216
     * @ORM\Column(name="expires_at", type="datetime", nullable=true, unique=false)
217
     */
218
    protected $expiresAt;
219
220
    /**
221
     * @var string
222
     * @Groups({"user:read", "user:write"})
223
     * @ORM\Column(name="phone", type="string", length=64, nullable=true, unique=false)
224
     */
225
    protected $phone;
226
227
    /**
228
     * @var string
229
     * @Groups({"user:read", "user:write"})
230
     * @ORM\Column(name="address", type="string", length=250, nullable=true, unique=false)
231
     */
232
    protected $address;
233
234
    /**
235
     * @var AccessUrl
236
     */
237
    protected $currentUrl;
238
239
    /**
240
     * @ORM\Column(type="string", length=255)
241
     */
242
    protected $salt;
243
244
    /**
245
     * @var \DateTime
246
     * @Groups({"user:read", "user:write"})
247
     * @ORM\Column(name="last_login", type="datetime", nullable=true, unique=false)
248
     */
249
    protected $lastLogin;
250
251
    /**
252
     * Random string sent to the user email address in order to verify it.
253
     *
254
     * @var string
255
     * @ORM\Column(name="confirmation_token", type="string", length=255, nullable=true)
256
     */
257
    protected $confirmationToken;
258
259
    /**
260
     * @var \DateTime
261
     *
262
     * @ORM\Column(name="password_requested_at", type="datetime", nullable=true, unique=false)
263
     */
264
    protected $passwordRequestedAt;
265
266
    /**
267
     * @var CourseRelUser[]|ArrayCollection
268
     *
269
     * @ApiSubresource()
270
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CourseRelUser", mappedBy="user", orphanRemoval=true)
271
     */
272
    protected $courses;
273
274
    /**
275
     * @var UsergroupRelUser[]|ArrayCollection
276
     *
277
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\UsergroupRelUser", mappedBy="user")
278
     */
279
    protected $classes;
280
281
    /**
282
     * ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CDropboxPost", mappedBy="user").
283
     */
284
    protected $dropBoxReceivedFiles;
285
286
    /**
287
     * ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CDropboxFile", mappedBy="userSent").
288
     */
289
    protected $dropBoxSentFiles;
290
291
    /**
292
     * @Groups({"user:read", "user:write"})
293
     * @ORM\Column(type="array")
294
     */
295
    protected $roles;
296
297
    /**
298
     * @var bool
299
     *
300
     * @ORM\Column(name="profile_completed", type="boolean", nullable=true)
301
     */
302
    protected $profileCompleted;
303
304
    /**
305
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\JuryMembers", mappedBy="user")
306
     */
307
    //protected $jurySubscriptions;
308
309
    /**
310
     * @var Group[]
311
     * @ORM\ManyToMany(targetEntity="Chamilo\CoreBundle\Entity\Group", inversedBy="users")
312
     * @ORM\JoinTable(
313
     *      name="fos_user_user_group",
314
     *      joinColumns={
315
     *          @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="cascade")
316
     *      },
317
     *      inverseJoinColumns={
318
     *          @ORM\JoinColumn(name="group_id", referencedColumnName="id")
319
     *      }
320
     * )
321
     */
322
    protected $groups;
323
324
    /**
325
     * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CurriculumItemRelUser", mappedBy="user").
326
     */
327
    protected $curriculumItems;
328
329
    /**
330
     * @var AccessUrlRelUser[]|ArrayCollection
331
     *
332
     * @ORM\OneToMany(
333
     *     targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelUser",
334
     *     mappedBy="user",
335
     *     cascade={"persist", "remove"},
336
     *     orphanRemoval=true
337
     * )
338
     */
339
    protected $portals;
340
341
    /**
342
     * @var ArrayCollection
343
     *
344
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Session", mappedBy="generalCoach")
345
     */
346
    protected $sessionAsGeneralCoach;
347
348
    /**
349
     * @ORM\OneToOne(
350
     *     targetEntity="Chamilo\CoreBundle\Entity\ResourceNode", cascade={"remove"}, orphanRemoval=true
351
     * )
352
     * @ORM\JoinColumn(name="resource_node_id", referencedColumnName="id", onDelete="CASCADE")
353
     */
354
    protected $resourceNode;
355
356
    /**
357
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\ResourceNode", mappedBy="creator")
358
     */
359
    protected $resourceNodes;
360
361
    /**
362
     * @ApiSubresource()
363
     * @ORM\OneToMany(
364
     *     targetEntity="Chamilo\CoreBundle\Entity\SessionRelCourseRelUser",
365
     *     mappedBy="user",
366
     *     cascade={"persist"},
367
     *     orphanRemoval=true
368
     * )
369
     */
370
    protected $sessionCourseSubscriptions;
371
372
    /**
373
     * @ORM\OneToMany(
374
     *     targetEntity="Chamilo\CoreBundle\Entity\SkillRelUser",
375
     *     mappedBy="user",
376
     *     cascade={"persist", "remove"},
377
     *     orphanRemoval=true
378
     * )
379
     */
380
    protected $achievedSkills;
381
382
    /**
383
     * @ORM\OneToMany(
384
     *     targetEntity="Chamilo\CoreBundle\Entity\SkillRelUserComment",
385
     *     mappedBy="feedbackGiver",
386
     *     cascade={"persist", "remove"},
387
     *     orphanRemoval=true
388
     * )
389
     */
390
    protected $commentedUserSkills;
391
392
    /**
393
     * @var ArrayCollection|GradebookCategory[]
394
     *
395
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\GradebookCategory", mappedBy="user")
396
     */
397
    protected $gradeBookCategories;
398
399
    /**
400
     * @var ArrayCollection|GradebookCertificate[]
401
     *
402
     * @ORM\OneToMany(
403
     *  targetEntity="GradebookCertificate", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true
404
     * )
405
     */
406
    protected $gradeBookCertificates;
407
408
    /**
409
     * @var ArrayCollection|GradebookComment[]
410
     *
411
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\GradebookComment", mappedBy="user")
412
     */
413
    protected $gradeBookComments;
414
415
    /**
416
     * @var ArrayCollection
417
     *
418
     * @ORM\OneToMany(
419
     *     targetEntity="GradebookEvaluation", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true
420
     * )
421
     */
422
    protected $gradeBookEvaluations;
423
424
    /**
425
     * @var ArrayCollection
426
     *
427
     * @ORM\OneToMany(targetEntity="GradebookLink", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
428
     */
429
    protected $gradeBookLinks;
430
431
    /**
432
     * @var ArrayCollection
433
     *
434
     * @ORM\OneToMany(targetEntity="GradebookResult", mappedBy="user", cascade={"persist","remove"}, orphanRemoval=true)
435
     */
436
    protected $gradeBookResults;
437
438
    /**
439
     * @var ArrayCollection
440
     *
441
     * @ORM\OneToMany(
442
     *     targetEntity="GradebookResultLog", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true
443
     * )
444
     */
445
    protected $gradeBookResultLogs;
446
447
    /**
448
     * @var ArrayCollection
449
     * @ORM\OneToMany(
450
     *     targetEntity="GradebookScoreLog", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true
451
     * )
452
     */
453
    protected $gradeBookScoreLogs;
454
455
    /**
456
     * @var ArrayCollection|UserRelUser[]
457
     * @ORM\OneToMany(targetEntity="UserRelUser", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
458
     */
459
    protected $userRelUsers;
460
461
    /**
462
     * @var ArrayCollection|GradebookLinkevalLog[]
463
     * @ORM\OneToMany(
464
     *     targetEntity="GradebookLinkevalLog",
465
     *     mappedBy="user",
466
     *     cascade={"persist", "remove"},
467
     *     orphanRemoval=true
468
     * )
469
     */
470
    protected $gradeBookLinkEvalLogs;
471
472
    /**
473
     * @var ArrayCollection|SequenceValue[]
474
     * @ORM\OneToMany(targetEntity="SequenceValue", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
475
     */
476
    protected $sequenceValues;
477
478
    /**
479
     * @var ArrayCollection|TrackEExerciseConfirmation[]
480
     * @ORM\OneToMany(
481
     *     targetEntity="Chamilo\CoreBundle\Entity\TrackEExerciseConfirmation",
482
     *     mappedBy="user",
483
     *     cascade={"persist", "remove"},
484
     *     orphanRemoval=true
485
     * )
486
     */
487
    protected $trackEExerciseConfirmations;
488
489
    /**
490
     * @var ArrayCollection|TrackEAttempt[]
491
     * @ORM\OneToMany(
492
     *     targetEntity="TrackEAccessComplete", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true
493
     * )
494
     */
495
    protected $trackEAccessCompleteList;
496
497
    /**
498
     * @var ArrayCollection|Templates[]
499
     * @ORM\OneToMany(targetEntity="Templates", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
500
     */
501
    protected $templates;
502
503
    /**
504
     * @var ArrayCollection|TrackEAttempt[]
505
     * @ORM\OneToMany(targetEntity="TrackEAttempt", mappedBy="user", cascade={"persist", "remove"},orphanRemoval=true)
506
     */
507
    protected $trackEAttempts;
508
509
    /**
510
     * @var ArrayCollection
511
     * @ORM\OneToMany(
512
     *     targetEntity="Chamilo\CoreBundle\Entity\TrackECourseAccess",
513
     *     mappedBy="user",
514
     *     cascade={"persist", "remove"},
515
     *     orphanRemoval=true
516
     * )
517
     */
518
    protected $trackECourseAccess;
519
520
    /**
521
     * @var ArrayCollection|UserCourseCategory[]
522
     *
523
     * @ORM\OneToMany(
524
     *     targetEntity="UserCourseCategory",
525
     *     mappedBy="user",
526
     *     cascade={"persist", "remove"},
527
     *     orphanRemoval=true
528
     * )
529
     */
530
    protected $userCourseCategories;
531
532
    /**
533
     * @var ArrayCollection|UserRelCourseVote[]
534
     * @ORM\OneToMany(targetEntity="UserRelCourseVote", mappedBy="user",cascade={"persist","remove"},orphanRemoval=true)
535
     */
536
    protected $userRelCourseVotes;
537
538
    /**
539
     * @var ArrayCollection|UserRelTag[]
540
     * @ORM\OneToMany(targetEntity="UserRelTag", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
541
     */
542
    protected $userRelTags;
543
544
    /**
545
     * @var ArrayCollection|PersonalAgenda[]
546
     * @ORM\OneToMany(targetEntity="PersonalAgenda",mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
547
     */
548
    protected $personalAgendas;
549
550
    /**
551
     * @var Session[]|ArrayCollection
552
     *
553
     * @ORM\OneToMany(
554
     *     targetEntity="Chamilo\CoreBundle\Entity\SessionRelUser",
555
     *     mappedBy="user",
556
     *     cascade={"persist", "remove"},
557
     *     orphanRemoval=true
558
     * )
559
     */
560
    protected $sessions;
561
562
    /**
563
     * @var CGroupRelUser[]|ArrayCollection
564
     *
565
     * @ORM\OneToMany(
566
     *     targetEntity="Chamilo\CourseBundle\Entity\CGroupRelUser",
567
     *     mappedBy="user",
568
     *     cascade={"persist", "remove"},
569
     *     orphanRemoval=true
570
     * )
571
     */
572
    protected $courseGroupsAsMember;
573
574
    /**
575
     * @var Collection
576
     *
577
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CGroupRelTutor", mappedBy="user", orphanRemoval=true)
578
     */
579
    protected $courseGroupsAsTutor;
580
581
    /**
582
     * @var string
583
     *
584
     * @ORM\Column(name="auth_source", type="string", length=50, nullable=true, unique=false)
585
     */
586
    protected $authSource;
587
588
    /**
589
     * @var int
590
     *
591
     * @ORM\Column(name="status", type="integer", nullable=false)
592
     */
593
    protected $status;
594
595
    /**
596
     * @var string
597
     *
598
     * @ORM\Column(name="official_code", type="string", length=40, nullable=true, unique=false)
599
     */
600
    protected $officialCode;
601
602
    /**
603
     * @var string
604
     *
605
     * @ORM\Column(name="picture_uri", type="string", length=250, nullable=true, unique=false)
606
     */
607
    protected $pictureUri;
608
609
    /**
610
     * @var int
611
     *
612
     * @ORM\Column(name="creator_id", type="integer", nullable=true, unique=false)
613
     */
614
    protected $creatorId;
615
616
    /**
617
     * @var string
618
     *
619
     * @ORM\Column(name="competences", type="text", nullable=true, unique=false)
620
     */
621
    protected $competences;
622
623
    /**
624
     * @var string
625
     *
626
     * @ORM\Column(name="diplomas", type="text", nullable=true, unique=false)
627
     */
628
    protected $diplomas;
629
630
    /**
631
     * @var string
632
     *
633
     * @ORM\Column(name="openarea", type="text", nullable=true, unique=false)
634
     */
635
    protected $openarea;
636
637
    /**
638
     * @var string
639
     *
640
     * @ORM\Column(name="teach", type="text", nullable=true, unique=false)
641
     */
642
    protected $teach;
643
644
    /**
645
     * @var string
646
     *
647
     * @ORM\Column(name="productions", type="string", length=250, nullable=true, unique=false)
648
     */
649
    protected $productions;
650
651
    /**
652
     * @var string
653
     *
654
     * @ORM\Column(name="language", type="string", length=40, nullable=true, unique=false)
655
     */
656
    protected $language;
657
658
    /**
659
     * @var \DateTime
660
     *
661
     * @ORM\Column(name="registration_date", type="datetime", nullable=false, unique=false)
662
     */
663
    protected $registrationDate;
664
665
    /**
666
     * @var \DateTime
667
     *
668
     * @ORM\Column(name="expiration_date", type="datetime", nullable=true, unique=false)
669
     */
670
    protected $expirationDate;
671
672
    /**
673
     * @var bool
674
     *
675
     * @ORM\Column(name="active", type="boolean", nullable=false, unique=false)
676
     */
677
    protected $active;
678
679
    /**
680
     * @var string
681
     *
682
     * @ORM\Column(name="openid", type="string", length=255, nullable=true, unique=false)
683
     */
684
    protected $openid;
685
686
    /**
687
     * @var string
688
     *
689
     * @ORM\Column(name="theme", type="string", length=255, nullable=true, unique=false)
690
     */
691
    protected $theme;
692
693
    /**
694
     * @var int
695
     *
696
     * @ORM\Column(name="hr_dept_id", type="smallint", nullable=true, unique=false)
697
     */
698
    protected $hrDeptId;
699
700
    /**
701
     * @var \DateTime
702
     * @Gedmo\Timestampable(on="create")
703
     * @ORM\Column(name="created_at", type="datetime")
704
     */
705
    protected $createdAt;
706
707
    /**
708
     * @var \DateTime
709
     * @Gedmo\Timestampable(on="update")
710
     * @ORM\Column(name="updated_at", type="datetime")
711
     */
712
    protected $updatedAt;
713
714
    /**
715
     * @var ArrayCollection
716
     *
717
     * @ORM\OneToMany(
718
     *     targetEntity="Chamilo\CoreBundle\Entity\Message",
719
     *     mappedBy="userSender",
720
     *     cascade={"persist", "remove"},
721
     *     orphanRemoval=true
722
     * )
723
     */
724
    protected $sentMessages;
725
726
    /**
727
     * @var ArrayCollection
728
     *
729
     * @ORM\OneToMany(
730
     *     targetEntity="Chamilo\CoreBundle\Entity\Message",
731
     *     mappedBy="userReceiver",
732
     *     cascade={"persist", "remove"},
733
     *     orphanRemoval=true
734
     * )
735
     */
736
    protected $receivedMessages;
737
738
    /**
739
     * @var Admin
740
     *
741
     * @ORM\OneToOne(targetEntity="Admin", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
742
     */
743
    protected $admin;
744
745
    /**
746
     * @ORM\Column(type="uuid", unique=true)
747
     */
748
    protected $uuid;
749
750
    public function __construct()
751
    {
752
        $this->uuid = Uuid::v4();
753
        $this->apiToken = null;
754
        $this->status = self::STUDENT;
755
        $this->salt = sha1(uniqid(null, true));
756
        $this->active = true;
757
        $this->registrationDate = new \DateTime();
758
        $this->authSource = 'platform';
759
        $this->courses = new ArrayCollection();
760
        //$this->items = new ArrayCollection();
761
        $this->classes = new ArrayCollection();
762
        $this->curriculumItems = new ArrayCollection();
763
        $this->portals = new ArrayCollection();
764
        $this->dropBoxSentFiles = new ArrayCollection();
765
        $this->dropBoxReceivedFiles = new ArrayCollection();
766
        $this->groups = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Doctrine\Common\Collections\ArrayCollection() of type Doctrine\Common\Collections\ArrayCollection is incompatible with the declared type Chamilo\CoreBundle\Entity\Group[] of property $groups.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
767
        $this->gradeBookCertificates = new ArrayCollection();
768
        $this->courseGroupsAsMember = new ArrayCollection();
769
        $this->courseGroupsAsTutor = new ArrayCollection();
770
        //$this->extraFields = new ArrayCollection();
771
        $this->createdAt = new \DateTime();
772
        $this->updatedAt = new \DateTime();
773
774
        $this->enabled = false;
775
        $this->locked = false;
776
        $this->expired = false;
777
        $this->roles = [];
778
        $this->credentialsExpired = false;
779
    }
780
781
    /**
782
     * @return array
783
     */
784
    public static function getPasswordConstraints()
785
    {
786
        return
787
            [
788
                new Assert\Length(['min' => 5]),
789
                // Alpha numeric + "_" or "-"
790
                new Assert\Regex(
791
                    [
792
                        'pattern' => '/^[a-z\-_0-9]+$/i',
793
                        'htmlPattern' => '/^[a-z\-_0-9]+$/i',
794
                    ]
795
                ),
796
                // Min 3 letters - not needed
797
                /*new Assert\Regex(array(
798
                    'pattern' => '/[a-z]{3}/i',
799
                    'htmlPattern' => '/[a-z]{3}/i')
800
                ),*/
801
                // Min 2 numbers
802
                new Assert\Regex(
803
                    [
804
                        'pattern' => '/[0-9]{2}/',
805
                        'htmlPattern' => '/[0-9]{2}/',
806
                    ]
807
                ),
808
            ];
809
    }
810
811
    public static function loadValidatorMetadata(ClassMetadata $metadata)
812
    {
813
        //$metadata->addPropertyConstraint('firstname', new Assert\NotBlank());
814
        //$metadata->addPropertyConstraint('lastname', new Assert\NotBlank());
815
        //$metadata->addPropertyConstraint('email', new Assert\Email());
816
        /*
817
        $metadata->addPropertyConstraint('password',
818
            new Assert\Collection(self::getPasswordConstraints())
819
        );*/
820
821
        /*$metadata->addConstraint(new UniqueEntity(array(
822
            'fields'  => 'username',
823
            'message' => 'This value is already used.',
824
        )));*/
825
826
        /*$metadata->addPropertyConstraint(
827
            'username',
828
            new Assert\Length(array(
829
                'min'        => 2,
830
                'max'        => 50,
831
                '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.',
832
                '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.',
833
            ))
834
        );*/
835
    }
836
837
    public function __toString(): string
838
    {
839
        return (string) $this->username;
840
    }
841
842
    public function getUuid()
843
    {
844
        return $this->uuid;
845
    }
846
847
    public function setUuid(UuidV4 $uuid): User
848
    {
849
        $this->uuid = $uuid;
850
851
        return $this;
852
    }
853
854
    public function getResourceNode(): ResourceNode
855
    {
856
        return $this->resourceNode;
857
    }
858
859
    public function setResourceNode(ResourceNode $resourceNode): ResourceInterface
860
    {
861
        $this->resourceNode = $resourceNode;
862
863
        return $this;
864
    }
865
866
    public function hasResourceNode(): bool
867
    {
868
        return $this->resourceNode instanceof ResourceNode;
869
    }
870
871
    /**
872
     * @return ArrayCollection|ResourceNode[]
873
     */
874
    public function getResourceNodes()
875
    {
876
        return $this->resourceNodes;
877
    }
878
879
    /**
880
     * @return User
881
     */
882
    public function setResourceNodes($resourceNodes)
883
    {
884
        $this->resourceNodes = $resourceNodes;
885
886
        return $this;
887
    }
888
889
    /**
890
     * @ORM\PostPersist()
891
     */
892
    public function postPersist(LifecycleEventArgs $args)
893
    {
894
        /*$user = $args->getEntity();
895
        */
896
    }
897
898
    /**
899
     * @return ArrayCollection
900
     */
901
    public function getDropBoxSentFiles()
902
    {
903
        return $this->dropBoxSentFiles;
904
    }
905
906
    /**
907
     * @param ArrayCollection $value
908
     */
909
    public function setDropBoxSentFiles($value)
910
    {
911
        $this->dropBoxSentFiles = $value;
912
    }
913
914
    /**
915
     * @return ArrayCollection
916
     */
917
    public function getDropBoxReceivedFiles()
918
    {
919
        return $this->dropBoxReceivedFiles;
920
    }
921
922
    /**
923
     * @param ArrayCollection $value
924
     */
925
    public function setDropBoxReceivedFiles($value)
926
    {
927
        $this->dropBoxReceivedFiles = $value;
928
    }
929
930
    public function getCourses()
931
    {
932
        return $this->courses;
933
    }
934
935
    /**
936
     * @param ArrayCollection $courses
937
     */
938
    public function setCourses($courses): self
939
    {
940
        $this->courses = $courses;
941
942
        return $this;
943
    }
944
945
    /**
946
     * @param $portal
947
     */
948
    public function setPortal($portal)
949
    {
950
        $this->portals->add($portal);
951
    }
952
953
    /**
954
     * @return ArrayCollection
955
     */
956
    public function getCurriculumItems()
957
    {
958
        return $this->curriculumItems;
959
    }
960
961
    public function setCurriculumItems(array $items): self
962
    {
963
        $this->curriculumItems = $items;
964
965
        return $this;
966
    }
967
968
    public function getIsActive(): bool
969
    {
970
        return true === $this->active;
971
    }
972
973
    public function isEnabled()
974
    {
975
        return $this->isActive();
976
    }
977
978
    /**
979
     * @param $boolean
980
     */
981
    public function setEnabled($boolean): self
982
    {
983
        $this->enabled = (bool) $boolean;
984
985
        return $this;
986
    }
987
988
    /**
989
     * Get salt.
990
     *
991
     * @return string
992
     */
993
    public function getSalt()
994
    {
995
        return $this->salt;
996
    }
997
998
    /**
999
     * Set salt.
1000
     *
1001
     * @param string $salt
1002
     *
1003
     * @return User
1004
     */
1005
    public function setSalt($salt)
1006
    {
1007
        $this->salt = $salt;
1008
1009
        return $this;
1010
    }
1011
1012
    public function getLps()
1013
    {
1014
        //return $this->lps;
1015
        /*$criteria = Criteria::create()
1016
            ->where(Criteria::expr()->eq("id", "666"))
1017
            //->orderBy(array("username" => "ASC"))
1018
            //->setFirstResult(0)
1019
            //->setMaxResults(20)
1020
        ;
1021
        $lps = $this->lps->matching($criteria);*/
1022
        /*return $this->lps->filter(
1023
            function($entry) use ($idsToFilter) {
1024
                return $entry->getId() == 1;
1025
        });*/
1026
    }
1027
1028
    /**
1029
     * Returns the list of classes for the user.
1030
     *
1031
     * @return string
1032
     */
1033
    public function getCompleteNameWithClasses()
1034
    {
1035
        $classSubscription = $this->getClasses();
1036
        $classList = [];
1037
        /** @var UsergroupRelUser $subscription */
1038
        foreach ($classSubscription as $subscription) {
1039
            $class = $subscription->getUsergroup();
1040
            $classList[] = $class->getName();
1041
        }
1042
        $classString = !empty($classList) ? ' ['.implode(', ', $classList).']' : null;
1043
1044
        return \UserManager::formatUserFullName($this).$classString;
1045
    }
1046
1047
    /**
1048
     * @return ArrayCollection
1049
     */
1050
    public function getClasses()
1051
    {
1052
        return $this->classes;
1053
    }
1054
1055
    /**
1056
     * @param ArrayCollection $classes
1057
     *
1058
     * @return $this
1059
     */
1060
    public function setClasses($classes)
1061
    {
1062
        $this->classes = $classes;
1063
1064
        return $this;
1065
    }
1066
1067
    public function getPassword()
1068
    {
1069
        return $this->password;
1070
    }
1071
1072
    public function setPassword(string $password): self
1073
    {
1074
        $this->password = $password;
1075
1076
        return $this;
1077
    }
1078
1079
    /**
1080
     * Get authSource.
1081
     *
1082
     * @return string
1083
     */
1084
    public function getAuthSource()
1085
    {
1086
        return $this->authSource;
1087
    }
1088
1089
    /**
1090
     * Set authSource.
1091
     *
1092
     * @param string $authSource
1093
     *
1094
     * @return User
1095
     */
1096
    public function setAuthSource($authSource)
1097
    {
1098
        $this->authSource = $authSource;
1099
1100
        return $this;
1101
    }
1102
1103
    /**
1104
     * Get email.
1105
     *
1106
     * @return string
1107
     */
1108
    public function getEmail()
1109
    {
1110
        return $this->email;
1111
    }
1112
1113
    /**
1114
     * Set email.
1115
     *
1116
     * @param string $email
1117
     *
1118
     * @return User
1119
     */
1120
    public function setEmail($email)
1121
    {
1122
        $this->email = $email;
1123
1124
        return $this;
1125
    }
1126
1127
    /**
1128
     * Get officialCode.
1129
     *
1130
     * @return string
1131
     */
1132
    public function getOfficialCode()
1133
    {
1134
        return $this->officialCode;
1135
    }
1136
1137
    /**
1138
     * Set officialCode.
1139
     *
1140
     * @param string $officialCode
1141
     *
1142
     * @return User
1143
     */
1144
    public function setOfficialCode($officialCode)
1145
    {
1146
        $this->officialCode = $officialCode;
1147
1148
        return $this;
1149
    }
1150
1151
    /**
1152
     * Get phone.
1153
     *
1154
     * @return string
1155
     */
1156
    public function getPhone()
1157
    {
1158
        return $this->phone;
1159
    }
1160
1161
    /**
1162
     * Set phone.
1163
     *
1164
     * @param string $phone
1165
     *
1166
     * @return User
1167
     */
1168
    public function setPhone($phone)
1169
    {
1170
        $this->phone = $phone;
1171
1172
        return $this;
1173
    }
1174
1175
    /**
1176
     * Get address.
1177
     *
1178
     * @return string
1179
     */
1180
    public function getAddress()
1181
    {
1182
        return $this->address;
1183
    }
1184
1185
    /**
1186
     * Set address.
1187
     *
1188
     * @param string $address
1189
     *
1190
     * @return User
1191
     */
1192
    public function setAddress($address)
1193
    {
1194
        $this->address = $address;
1195
1196
        return $this;
1197
    }
1198
1199
    /**
1200
     * Get creatorId.
1201
     *
1202
     * @return int
1203
     */
1204
    public function getCreatorId()
1205
    {
1206
        return $this->creatorId;
1207
    }
1208
1209
    /**
1210
     * Set creatorId.
1211
     *
1212
     * @param int $creatorId
1213
     *
1214
     * @return User
1215
     */
1216
    public function setCreatorId($creatorId)
1217
    {
1218
        $this->creatorId = $creatorId;
1219
1220
        return $this;
1221
    }
1222
1223
    /**
1224
     * Get competences.
1225
     *
1226
     * @return string
1227
     */
1228
    public function getCompetences()
1229
    {
1230
        return $this->competences;
1231
    }
1232
1233
    /**
1234
     * Set competences.
1235
     *
1236
     * @param string $competences
1237
     *
1238
     * @return User
1239
     */
1240
    public function setCompetences($competences)
1241
    {
1242
        $this->competences = $competences;
1243
1244
        return $this;
1245
    }
1246
1247
    /**
1248
     * Get diplomas.
1249
     *
1250
     * @return string
1251
     */
1252
    public function getDiplomas()
1253
    {
1254
        return $this->diplomas;
1255
    }
1256
1257
    /**
1258
     * Set diplomas.
1259
     *
1260
     * @param string $diplomas
1261
     *
1262
     * @return User
1263
     */
1264
    public function setDiplomas($diplomas)
1265
    {
1266
        $this->diplomas = $diplomas;
1267
1268
        return $this;
1269
    }
1270
1271
    /**
1272
     * Get openarea.
1273
     *
1274
     * @return string
1275
     */
1276
    public function getOpenarea()
1277
    {
1278
        return $this->openarea;
1279
    }
1280
1281
    /**
1282
     * Set openarea.
1283
     *
1284
     * @param string $openarea
1285
     *
1286
     * @return User
1287
     */
1288
    public function setOpenarea($openarea)
1289
    {
1290
        $this->openarea = $openarea;
1291
1292
        return $this;
1293
    }
1294
1295
    /**
1296
     * Get teach.
1297
     *
1298
     * @return string
1299
     */
1300
    public function getTeach()
1301
    {
1302
        return $this->teach;
1303
    }
1304
1305
    /**
1306
     * Set teach.
1307
     *
1308
     * @param string $teach
1309
     *
1310
     * @return User
1311
     */
1312
    public function setTeach($teach)
1313
    {
1314
        $this->teach = $teach;
1315
1316
        return $this;
1317
    }
1318
1319
    /**
1320
     * Get productions.
1321
     *
1322
     * @return string
1323
     */
1324
    public function getProductions()
1325
    {
1326
        return $this->productions;
1327
    }
1328
1329
    /**
1330
     * Set productions.
1331
     *
1332
     * @param string $productions
1333
     *
1334
     * @return User
1335
     */
1336
    public function setProductions($productions)
1337
    {
1338
        $this->productions = $productions;
1339
1340
        return $this;
1341
    }
1342
1343
    /**
1344
     * Get language.
1345
     *
1346
     * @return string
1347
     */
1348
    public function getLanguage()
1349
    {
1350
        return $this->language;
1351
    }
1352
1353
    /**
1354
     * Set language.
1355
     */
1356
    public function setLanguage(string $language): User
1357
    {
1358
        $this->language = $language;
1359
1360
        return $this;
1361
    }
1362
1363
    /**
1364
     * Get registrationDate.
1365
     *
1366
     * @return \DateTime
1367
     */
1368
    public function getRegistrationDate()
1369
    {
1370
        return $this->registrationDate;
1371
    }
1372
1373
    /**
1374
     * Set registrationDate.
1375
     *
1376
     * @param \DateTime $registrationDate
1377
     *
1378
     * @return User
1379
     */
1380
    public function setRegistrationDate($registrationDate)
1381
    {
1382
        $this->registrationDate = $registrationDate;
1383
1384
        return $this;
1385
    }
1386
1387
    /**
1388
     * Get expirationDate.
1389
     *
1390
     * @return \DateTime
1391
     */
1392
    public function getExpirationDate()
1393
    {
1394
        return $this->expirationDate;
1395
    }
1396
1397
    /**
1398
     * Set expirationDate.
1399
     *
1400
     * @param \DateTime $expirationDate
1401
     *
1402
     * @return User
1403
     */
1404
    public function setExpirationDate($expirationDate)
1405
    {
1406
        $this->expirationDate = $expirationDate;
1407
1408
        return $this;
1409
    }
1410
1411
    /**
1412
     * Get active.
1413
     *
1414
     * @return bool
1415
     */
1416
    public function getActive()
1417
    {
1418
        return $this->active;
1419
    }
1420
1421
    public function isActive(): bool
1422
    {
1423
        return $this->getIsActive();
1424
    }
1425
1426
    /**
1427
     * Set active.
1428
     *
1429
     * @param bool $active
1430
     *
1431
     * @return User
1432
     */
1433
    public function setActive($active)
1434
    {
1435
        $this->active = $active;
1436
1437
        return $this;
1438
    }
1439
1440
    /**
1441
     * Get openid.
1442
     *
1443
     * @return string
1444
     */
1445
    public function getOpenid()
1446
    {
1447
        return $this->openid;
1448
    }
1449
1450
    /**
1451
     * Set openid.
1452
     *
1453
     * @param string $openid
1454
     *
1455
     * @return User
1456
     */
1457
    public function setOpenid($openid)
1458
    {
1459
        $this->openid = $openid;
1460
1461
        return $this;
1462
    }
1463
1464
    /**
1465
     * Get theme.
1466
     *
1467
     * @return string
1468
     */
1469
    public function getTheme()
1470
    {
1471
        return $this->theme;
1472
    }
1473
1474
    /**
1475
     * Set theme.
1476
     *
1477
     * @param string $theme
1478
     *
1479
     * @return User
1480
     */
1481
    public function setTheme($theme)
1482
    {
1483
        $this->theme = $theme;
1484
1485
        return $this;
1486
    }
1487
1488
    /**
1489
     * Get hrDeptId.
1490
     *
1491
     * @return int
1492
     */
1493
    public function getHrDeptId()
1494
    {
1495
        return $this->hrDeptId;
1496
    }
1497
1498
    /**
1499
     * Set hrDeptId.
1500
     *
1501
     * @param int $hrDeptId
1502
     *
1503
     * @return User
1504
     */
1505
    public function setHrDeptId($hrDeptId)
1506
    {
1507
        $this->hrDeptId = $hrDeptId;
1508
1509
        return $this;
1510
    }
1511
1512
    /**
1513
     * @return \DateTime
1514
     */
1515
    public function getMemberSince()
1516
    {
1517
        return $this->registrationDate;
1518
    }
1519
1520
    /**
1521
     * @return bool
1522
     */
1523
    public function isOnline()
1524
    {
1525
        return false;
1526
    }
1527
1528
    /**
1529
     * @return int
1530
     */
1531
    public function getIdentifier()
1532
    {
1533
        return $this->getId();
1534
    }
1535
1536
    /**
1537
     * @return int
1538
     */
1539
    public function getId()
1540
    {
1541
        return $this->id;
1542
    }
1543
1544
    /**
1545
     * @param int $userId
1546
     */
1547
    public function setId($userId)
1548
    {
1549
        $this->id = $userId;
1550
    }
1551
1552
    /**
1553
     * @return string
1554
     */
1555
    public function getSlug()
1556
    {
1557
        return $this->getUsername();
1558
    }
1559
1560
    public function getUsername(): string
1561
    {
1562
        return (string) $this->username;
1563
    }
1564
1565
    public function setUsername($username): self
1566
    {
1567
        $this->username = $username;
1568
1569
        return $this;
1570
    }
1571
1572
    /**
1573
     * @param string $slug
1574
     *
1575
     * @return User
1576
     */
1577
    public function setSlug($slug)
1578
    {
1579
        return $this->setUsername($slug);
1580
    }
1581
1582
    /**
1583
     * Get lastLogin.
1584
     *
1585
     * @return \DateTime
1586
     */
1587
    public function getLastLogin()
1588
    {
1589
        return $this->lastLogin;
1590
    }
1591
1592
    /**
1593
     * Set lastLogin.
1594
     *
1595
     * @param \DateTime $lastLogin
1596
     */
1597
    public function setLastLogin(\DateTime $lastLogin = null): self
1598
    {
1599
        $this->lastLogin = $lastLogin;
1600
1601
        return $this;
1602
    }
1603
1604
    /**
1605
     * Get sessionCourseSubscription.
1606
     *
1607
     * @return ArrayCollection
1608
     */
1609
    public function getSessionCourseSubscriptions()
1610
    {
1611
        return $this->sessionCourseSubscriptions;
1612
    }
1613
1614
    public function setSessionCourseSubscriptions(array $value): self
1615
    {
1616
        $this->sessionCourseSubscriptions = $value;
1617
1618
        return $this;
1619
    }
1620
1621
    /**
1622
     * @return string
1623
     */
1624
    public function getConfirmationToken()
1625
    {
1626
        return $this->confirmationToken;
1627
    }
1628
1629
    /**
1630
     * @param string $confirmationToken
1631
     */
1632
    public function setConfirmationToken($confirmationToken): self
1633
    {
1634
        $this->confirmationToken = $confirmationToken;
1635
1636
        return $this;
1637
    }
1638
1639
    public function isPasswordRequestNonExpired($ttl)
1640
    {
1641
        return $this->getPasswordRequestedAt() instanceof \DateTime &&
1642
            $this->getPasswordRequestedAt()->getTimestamp() + $ttl > time();
1643
    }
1644
1645
    /**
1646
     * @return \DateTime
1647
     */
1648
    public function getPasswordRequestedAt()
1649
    {
1650
        return $this->passwordRequestedAt;
1651
    }
1652
1653
    public function setPasswordRequestedAt(\DateTime $date = null)
1654
    {
1655
        $this->passwordRequestedAt = $date;
1656
1657
        return $this;
1658
    }
1659
1660
    public function getPlainPassword(): ?string
1661
    {
1662
        return $this->plainPassword;
1663
    }
1664
1665
    public function setPlainPassword(string $password): self
1666
    {
1667
        $this->plainPassword = $password;
1668
1669
        // forces the object to look "dirty" to Doctrine. Avoids
1670
        // Doctrine *not* saving this entity, if only plainPassword changes
1671
        $this->password = null;
1672
1673
        return $this;
1674
    }
1675
1676
    /**
1677
     * Returns the expiration date.
1678
     *
1679
     * @return \DateTime|null
1680
     */
1681
    public function getExpiresAt()
1682
    {
1683
        return $this->expiresAt;
1684
    }
1685
1686
    public function setExpiresAt(\DateTime $date): self
1687
    {
1688
        $this->expiresAt = $date;
1689
1690
        return $this;
1691
    }
1692
1693
    /**
1694
     * Returns the credentials expiration date.
1695
     *
1696
     * @return \DateTime
1697
     */
1698
    public function getCredentialsExpireAt()
1699
    {
1700
        return $this->credentialsExpireAt;
1701
    }
1702
1703
    /**
1704
     * Sets the credentials expiration date.
1705
     */
1706
    public function setCredentialsExpireAt(\DateTime $date = null): self
1707
    {
1708
        $this->credentialsExpireAt = $date;
1709
1710
        return $this;
1711
    }
1712
1713
    public function getFullname(): string
1714
    {
1715
        return sprintf('%s %s', $this->getFirstname(), $this->getLastname());
1716
    }
1717
1718
    public function getFirstname()
1719
    {
1720
        return $this->firstname;
1721
    }
1722
1723
    /**
1724
     * Set firstname.
1725
     *
1726
     * @return User
1727
     */
1728
    public function setFirstname(string $firstname): self
1729
    {
1730
        $this->firstname = $firstname;
1731
1732
        return $this;
1733
    }
1734
1735
    public function getLastname()
1736
    {
1737
        return $this->lastname;
1738
    }
1739
1740
    /**
1741
     * Set lastname.
1742
     *
1743
     * @return User
1744
     */
1745
    public function setLastname(string $lastname): self
1746
    {
1747
        $this->lastname = $lastname;
1748
1749
        return $this;
1750
    }
1751
1752
    /**
1753
     * @param string $name
1754
     */
1755
    public function hasGroup($name): bool
1756
    {
1757
        return in_array($name, $this->getGroupNames());
1758
    }
1759
1760
    public function getGroupNames(): array
1761
    {
1762
        $names = [];
1763
        foreach ($this->getGroups() as $group) {
1764
            $names[] = $group->getName();
1765
        }
1766
1767
        return $names;
1768
    }
1769
1770
    public function getGroups()
1771
    {
1772
        return $this->groups;
1773
    }
1774
1775
    /**
1776
     * Sets the user groups.
1777
     *
1778
     * @param array $groups
1779
     */
1780
    public function setGroups($groups): self
1781
    {
1782
        foreach ($groups as $group) {
1783
            $this->addGroup($group);
1784
        }
1785
1786
        return $this;
1787
    }
1788
1789
    public function addGroup($group): self
1790
    {
1791
        if (!$this->getGroups()->contains($group)) {
1792
            $this->getGroups()->add($group);
1793
        }
1794
1795
        return $this;
1796
    }
1797
1798
    public function removeGroup($group): self
1799
    {
1800
        if ($this->getGroups()->contains($group)) {
1801
            $this->getGroups()->removeElement($group);
1802
        }
1803
1804
        return $this;
1805
    }
1806
1807
    public function isAccountNonExpired()
1808
    {
1809
        /*if (true === $this->expired) {
1810
            return false;
1811
        }
1812
1813
        if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
1814
            return false;
1815
        }*/
1816
1817
        return true;
1818
    }
1819
1820
    public function isAccountNonLocked()
1821
    {
1822
        return true;
1823
        //return !$this->locked;
1824
    }
1825
1826
    public function isCredentialsNonExpired()
1827
    {
1828
        /*if (true === $this->credentialsExpired) {
1829
            return false;
1830
        }
1831
1832
        if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
1833
            return false;
1834
        }*/
1835
1836
        return true;
1837
    }
1838
1839
    /**
1840
     * @return bool
1841
     */
1842
    public function getCredentialsExpired()
1843
    {
1844
        return $this->credentialsExpired;
1845
    }
1846
1847
    /**
1848
     * @param bool $boolean
1849
     */
1850
    public function setCredentialsExpired($boolean): self
1851
    {
1852
        $this->credentialsExpired = $boolean;
1853
1854
        return $this;
1855
    }
1856
1857
    /**
1858
     * @return bool
1859
     */
1860
    public function getExpired()
1861
    {
1862
        return $this->expired;
1863
    }
1864
1865
    /**
1866
     * Sets this user to expired.
1867
     *
1868
     * @param bool $boolean
1869
     */
1870
    public function setExpired($boolean): self
1871
    {
1872
        $this->expired = (bool) $boolean;
1873
1874
        return $this;
1875
    }
1876
1877
    public function getLocked(): bool
1878
    {
1879
        return $this->locked;
1880
    }
1881
1882
    /**
1883
     * @param $boolean
1884
     */
1885
    public function setLocked($boolean): self
1886
    {
1887
        $this->locked = $boolean;
1888
1889
        return $this;
1890
    }
1891
1892
    /**
1893
     * Check if the user has the skill.
1894
     *
1895
     * @param Skill $skill The skill
1896
     */
1897
    public function hasSkill(Skill $skill): bool
1898
    {
1899
        $achievedSkills = $this->getAchievedSkills();
1900
1901
        foreach ($achievedSkills as $userSkill) {
1902
            if ($userSkill->getSkill()->getId() !== $skill->getId()) {
1903
                continue;
1904
            }
1905
1906
            return true;
1907
        }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
1908
    }
1909
1910
    /**
1911
     * Get achievedSkills.
1912
     *
1913
     * @return ArrayCollection
1914
     */
1915
    public function getAchievedSkills()
1916
    {
1917
        return $this->achievedSkills;
1918
    }
1919
1920
    /**
1921
     * @param string[] $value
1922
     */
1923
    public function setAchievedSkills(array $value): self
1924
    {
1925
        $this->achievedSkills = $value;
1926
1927
        return $this;
1928
    }
1929
1930
    /**
1931
     * @return bool
1932
     */
1933
    public function isProfileCompleted()
1934
    {
1935
        return $this->profileCompleted;
1936
    }
1937
1938
    public function setProfileCompleted($profileCompleted): self
1939
    {
1940
        $this->profileCompleted = $profileCompleted;
1941
1942
        return $this;
1943
    }
1944
1945
    /**
1946
     * @return AccessUrl
1947
     */
1948
    public function getCurrentUrl()
1949
    {
1950
        return $this->currentUrl;
1951
    }
1952
1953
    /**
1954
     * Sets the AccessUrl for the current user in memory.
1955
     */
1956
    public function setCurrentUrl(AccessUrl $url): self
1957
    {
1958
        $urlList = $this->getPortals();
1959
        /** @var AccessUrlRelUser $item */
1960
        foreach ($urlList as $item) {
1961
            if ($item->getUrl()->getId() === $url->getId()) {
1962
                $this->currentUrl = $url;
1963
1964
                break;
1965
            }
1966
        }
1967
1968
        return $this;
1969
    }
1970
1971
    /**
1972
     * @return ArrayCollection
1973
     */
1974
    public function getPortals()
1975
    {
1976
        return $this->portals;
1977
    }
1978
1979
    public function setPortals(array $value)
1980
    {
1981
        $this->portals = $value;
1982
    }
1983
1984
    /**
1985
     * Get sessionAsGeneralCoach.
1986
     *
1987
     * @return ArrayCollection
1988
     */
1989
    public function getSessionAsGeneralCoach()
1990
    {
1991
        return $this->sessionAsGeneralCoach;
1992
    }
1993
1994
    /**
1995
     * Get sessionAsGeneralCoach.
1996
     *
1997
     * @param ArrayCollection $value
1998
     */
1999
    public function setSessionAsGeneralCoach($value): self
2000
    {
2001
        $this->sessionAsGeneralCoach = $value;
2002
2003
        return $this;
2004
    }
2005
2006
    public function getCommentedUserSkills()
2007
    {
2008
        return $this->commentedUserSkills;
2009
    }
2010
2011
    /**
2012
     * @return User
2013
     */
2014
    public function setCommentedUserSkills(array $commentedUserSkills): self
2015
    {
2016
        $this->commentedUserSkills = $commentedUserSkills;
2017
2018
        return $this;
2019
    }
2020
2021
    /**
2022
     * @return bool
2023
     */
2024
    public function isEqualTo(UserInterface $user)
2025
    {
2026
        if ($this->password !== $user->getPassword()) {
2027
            return false;
2028
        }
2029
2030
        if ($this->salt !== $user->getSalt()) {
2031
            return false;
2032
        }
2033
2034
        if ($this->username !== $user->getUsername()) {
2035
            return false;
2036
        }
2037
2038
        return true;
2039
    }
2040
2041
    /**
2042
     * Get sentMessages.
2043
     *
2044
     * @return ArrayCollection
2045
     */
2046
    public function getSentMessages()
2047
    {
2048
        return $this->sentMessages;
2049
    }
2050
2051
    /**
2052
     * Get receivedMessages.
2053
     *
2054
     * @return ArrayCollection
2055
     */
2056
    public function getReceivedMessages()
2057
    {
2058
        return $this->receivedMessages;
2059
    }
2060
2061
    /**
2062
     * @param int $lastId Optional. The ID of the last received message
2063
     */
2064
    public function getUnreadReceivedMessages($lastId = 0): ArrayCollection
2065
    {
2066
        $criteria = Criteria::create();
2067
        $criteria->where(
2068
            Criteria::expr()->eq('msgStatus', MESSAGE_STATUS_UNREAD)
2069
        );
2070
2071
        if ($lastId > 0) {
2072
            $criteria->andWhere(
2073
                Criteria::expr()->gt('id', (int) $lastId)
2074
            );
2075
        }
2076
2077
        $criteria->orderBy(['sendDate' => Criteria::DESC]);
2078
2079
        return $this->receivedMessages->matching($criteria);
2080
    }
2081
2082
    public function getCourseGroupsAsMember(): Collection
2083
    {
2084
        return $this->courseGroupsAsMember;
2085
    }
2086
2087
    public function getCourseGroupsAsTutor(): Collection
2088
    {
2089
        return $this->courseGroupsAsTutor;
2090
    }
2091
2092
    public function getCourseGroupsAsMemberFromCourse(Course $course): ArrayCollection
2093
    {
2094
        $criteria = Criteria::create();
2095
        $criteria->where(
2096
            Criteria::expr()->eq('cId', $course)
2097
        );
2098
2099
        return $this->courseGroupsAsMember->matching($criteria);
2100
    }
2101
2102
    public function eraseCredentials()
2103
    {
2104
        $this->plainPassword = null;
2105
    }
2106
2107
    public function isSuperAdmin()
2108
    {
2109
        return $this->hasRole('ROLE_SUPER_ADMIN');
2110
    }
2111
2112
    public function hasRole($role)
2113
    {
2114
        return in_array(strtoupper($role), $this->getRoles(), true);
2115
    }
2116
2117
    /**
2118
     * Returns the user roles.
2119
     *
2120
     * @return array The roles
2121
     */
2122
    public function getRoles()
2123
    {
2124
        $roles = $this->roles;
2125
2126
        foreach ($this->getGroups() as $group) {
2127
            $roles = array_merge($roles, $group->getRoles());
2128
        }
2129
2130
        // we need to make sure to have at least one role
2131
        $roles[] = 'ROLE_USER';
2132
2133
        return array_unique($roles);
2134
    }
2135
2136
    public function setRoles(array $roles): self
2137
    {
2138
        $this->roles = [];
2139
2140
        foreach ($roles as $role) {
2141
            $this->addRole($role);
2142
        }
2143
2144
        return $this;
2145
    }
2146
2147
    /**
2148
     * @param string $role
2149
     */
2150
    public function addRole($role): self
2151
    {
2152
        $role = strtoupper($role);
2153
        if ($role === static::ROLE_DEFAULT) {
2154
            return $this;
2155
        }
2156
2157
        if (!in_array($role, $this->roles, true)) {
2158
            $this->roles[] = $role;
2159
        }
2160
2161
        return $this;
2162
    }
2163
2164
    public function isUser(UserInterface $user = null)
2165
    {
2166
        return null !== $user && $this->getId() === $user->getId();
2167
    }
2168
2169
    public function removeRole($role)
2170
    {
2171
        if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
2172
            unset($this->roles[$key]);
2173
            $this->roles = array_values($this->roles);
2174
        }
2175
2176
        return $this;
2177
    }
2178
2179
    public function getUsernameCanonical()
2180
    {
2181
        return $this->usernameCanonical;
2182
    }
2183
2184
    public function setUsernameCanonical($usernameCanonical)
2185
    {
2186
        $this->usernameCanonical = $usernameCanonical;
2187
2188
        return $this;
2189
    }
2190
2191
    public function getEmailCanonical()
2192
    {
2193
        return $this->emailCanonical;
2194
    }
2195
2196
    public function setEmailCanonical($emailCanonical): self
2197
    {
2198
        $this->emailCanonical = $emailCanonical;
2199
2200
        return $this;
2201
    }
2202
2203
    /**
2204
     * @return string
2205
     */
2206
    public function getTimezone()
2207
    {
2208
        return $this->timezone;
2209
    }
2210
2211
    /**
2212
     * @param string $timezone
2213
     *
2214
     * @return User
2215
     */
2216
    public function setTimezone($timezone)
2217
    {
2218
        $this->timezone = $timezone;
2219
2220
        return $this;
2221
    }
2222
2223
    /**
2224
     * @return string
2225
     */
2226
    public function getLocale()
2227
    {
2228
        return $this->locale;
2229
    }
2230
2231
    /**
2232
     * @param string $locale
2233
     *
2234
     * @return User
2235
     */
2236
    public function setLocale($locale)
2237
    {
2238
        $this->locale = $locale;
2239
2240
        return $this;
2241
    }
2242
2243
    /**
2244
     * @return string
2245
     */
2246
    public function getApiToken()
2247
    {
2248
        return $this->apiToken;
2249
    }
2250
2251
    /**
2252
     * @param string $apiToken
2253
     *
2254
     * @return User
2255
     */
2256
    public function setApiToken($apiToken)
2257
    {
2258
        $this->apiToken = $apiToken;
2259
2260
        return $this;
2261
    }
2262
2263
    public function getWebsite(): ?string
2264
    {
2265
        return $this->website;
2266
    }
2267
2268
    public function setWebsite(string $website): self
2269
    {
2270
        $this->website = $website;
2271
2272
        return $this;
2273
    }
2274
2275
    public function getBiography(): ?string
2276
    {
2277
        return $this->biography;
2278
    }
2279
2280
    public function setBiography(string $biography): self
2281
    {
2282
        $this->biography = $biography;
2283
2284
        return $this;
2285
    }
2286
2287
    /**
2288
     * @return \DateTime
2289
     */
2290
    public function getDateOfBirth()
2291
    {
2292
        return $this->dateOfBirth;
2293
    }
2294
2295
    /**
2296
     * @param \DateTime $dateOfBirth
2297
     */
2298
    public function setDateOfBirth($dateOfBirth): self
2299
    {
2300
        $this->dateOfBirth = $dateOfBirth;
2301
2302
        return $this;
2303
    }
2304
2305
    public function getProfileUrl(): string
2306
    {
2307
        return '/main/social/profile.php?u='.$this->id;
2308
    }
2309
2310
    public function getIconStatus(): string
2311
    {
2312
        $status = $this->getStatus();
2313
        $hasCertificates = $this->getGradeBookCertificates()->count() > 0;
2314
        $urlImg = '/img/';
2315
        $iconStatus = '';
2316
        switch ($status) {
2317
            case STUDENT:
2318
                if ($hasCertificates) {
2319
                    $iconStatus = $urlImg.'icons/svg/identifier_graduated.svg';
2320
                } else {
2321
                    $iconStatus = $urlImg.'icons/svg/identifier_student.svg';
2322
                }
2323
                break;
2324
            case COURSEMANAGER:
2325
                if ($this->isAdmin()) {
2326
                    $iconStatus = $urlImg.'icons/svg/identifier_admin.svg';
2327
                } else {
2328
                    $iconStatus = $urlImg.'icons/svg/identifier_teacher.svg';
2329
                }
2330
                break;
2331
            case STUDENT_BOSS:
2332
                $iconStatus = $urlImg.'icons/svg/identifier_teacher.svg';
2333
                break;
2334
        }
2335
2336
        return $iconStatus;
2337
    }
2338
2339
    /**
2340
     * Get status.
2341
     *
2342
     * @return int
2343
     */
2344
    public function getStatus()
2345
    {
2346
        return (int) $this->status;
2347
    }
2348
2349
    /**
2350
     * Set status.
2351
     *
2352
     * @return User
2353
     */
2354
    public function setStatus(int $status)
2355
    {
2356
        $this->status = $status;
2357
2358
        return $this;
2359
    }
2360
2361
    /**
2362
     * @return GradebookCertificate[]|ArrayCollection
2363
     */
2364
    public function getGradeBookCertificates()
2365
    {
2366
        return $this->gradeBookCertificates;
2367
    }
2368
2369
    /**
2370
     * @param GradebookCertificate[]|ArrayCollection $gradeBookCertificates
2371
     */
2372
    public function setGradeBookCertificates($gradeBookCertificates): self
2373
    {
2374
        $this->gradeBookCertificates = $gradeBookCertificates;
2375
2376
        return $this;
2377
    }
2378
2379
    public function isAdmin()
2380
    {
2381
        return $this->hasRole('ROLE_ADMIN');
2382
    }
2383
2384
    public function getCourseGroupsAsTutorFromCourse(Course $course): ArrayCollection
2385
    {
2386
        $criteria = Criteria::create();
2387
        $criteria->where(
2388
            Criteria::expr()->eq('cId', $course->getId())
2389
        );
2390
2391
        return $this->courseGroupsAsTutor->matching($criteria);
2392
    }
2393
2394
    /**
2395
     * Retreives this user's related student sessions.
2396
     *
2397
     * @return Session[]
2398
     */
2399
    public function getStudentSessions()
2400
    {
2401
        return $this->getSessions(0);
2402
    }
2403
2404
    /**
2405
     * Retreives this user's related sessions.
2406
     *
2407
     * @param int $relationType \Chamilo\CoreBundle\Entity\SessionRelUser::relationTypeList key
2408
     *
2409
     * @return Session[]
2410
     */
2411
    public function getSessions($relationType)
2412
    {
2413
        $sessions = [];
2414
        foreach ($this->sessions as $sessionRelUser) {
2415
            if ($sessionRelUser->getRelationType() == $relationType) {
0 ignored issues
show
Bug introduced by
The method getRelationType() does not exist on Chamilo\CoreBundle\Entity\Session. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2415
            if ($sessionRelUser->/** @scrutinizer ignore-call */ getRelationType() == $relationType) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2416
                $sessions[] = $sessionRelUser->getSession();
0 ignored issues
show
Bug introduced by
The method getSession() does not exist on Chamilo\CoreBundle\Entity\Session. Did you maybe mean getSessionAdmin()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2416
                /** @scrutinizer ignore-call */ 
2417
                $sessions[] = $sessionRelUser->getSession();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2417
            }
2418
        }
2419
2420
        return $sessions;
2421
    }
2422
2423
    /**
2424
     * Retreives this user's related DRH sessions.
2425
     *
2426
     * @return Session[]
2427
     */
2428
    public function getDRHSessions()
2429
    {
2430
        return $this->getSessions(1);
2431
    }
2432
2433
    /**
2434
     * Get this user's related accessible sessions of a type, student by default.
2435
     *
2436
     * @param int $relationType \Chamilo\CoreBundle\Entity\SessionRelUser::relationTypeList key
2437
     *
2438
     * @return Session[]
2439
     */
2440
    public function getCurrentlyAccessibleSessions($relationType = 0)
2441
    {
2442
        $sessions = [];
2443
        foreach ($this->getSessions($relationType) as $session) {
2444
            if ($session->isCurrentlyAccessible()) {
2445
                $sessions[] = $session;
2446
            }
2447
        }
2448
2449
        return $sessions;
2450
    }
2451
2452
    public function getResourceIdentifier(): int
2453
    {
2454
        return $this->id;
2455
    }
2456
2457
    public function getResourceName(): string
2458
    {
2459
        return $this->getUsername();
2460
    }
2461
2462
    public function setResourceName(string $name)
2463
    {
2464
        $this->setUsername($name);
2465
    }
2466
2467
    public function setParent(AbstractResource $parent)
2468
    {
2469
    }
2470
2471
    public function getDefaultIllustration($size): string
2472
    {
2473
        $size = empty($size) ? 32 : (int) $size;
2474
2475
        return "/img/icons/$size/unknown.png";
2476
    }
2477
2478
    /**
2479
     * Find the largest sort value in a given UserCourseCategory
2480
     * This method is used when we are moving a course to a different category
2481
     * and also when a user subscribes to courses (the new course is added at the end of the main category).
2482
     *
2483
     * Used to be implemented in global function \api_max_sort_value.
2484
     * Reimplemented using the ORM cache.
2485
     *
2486
     * @param UserCourseCategory|null $userCourseCategory the user_course_category
2487
     *
2488
     * @return int|mixed
2489
     */
2490
    public function getMaxSortValue($userCourseCategory = null)
2491
    {
2492
        $categoryCourses = $this->courses->matching(
2493
            Criteria::create()
2494
                ->where(Criteria::expr()->neq('relationType', COURSE_RELATION_TYPE_RRHH))
2495
                ->andWhere(Criteria::expr()->eq('userCourseCat', $userCourseCategory))
2496
        );
2497
2498
        return $categoryCourses->isEmpty()
2499
            ? 0
2500
            : max(
2501
                $categoryCourses->map(
2502
                    /** @var CourseRelUser $courseRelUser */
2503
                    function ($courseRelUser) {
2504
                        return $courseRelUser->getSort();
2505
                    }
2506
                )->toArray()
2507
            );
2508
    }
2509
}
2510