Passed
Push — master ( 4dcdf9...859955 )
by Julito
09:10
created

User::hasSkill()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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

2377
            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...
2378
                $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

2378
                /** @scrutinizer ignore-call */ 
2379
                $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...
2379
            }
2380
        }
2381
2382
        return $sessions;
2383
    }
2384
2385
    /**
2386
     * Retreives this user's related DRH sessions.
2387
     *
2388
     * @return Session[]
2389
     */
2390
    public function getDRHSessions()
2391
    {
2392
        return $this->getSessions(1);
2393
    }
2394
2395
    /**
2396
     * Get this user's related accessible sessions of a type, student by default.
2397
     *
2398
     * @param int $relationType \Chamilo\CoreBundle\Entity\SessionRelUser::relationTypeList key
2399
     *
2400
     * @return Session[]
2401
     */
2402
    public function getCurrentlyAccessibleSessions($relationType = 0)
2403
    {
2404
        $sessions = [];
2405
        foreach ($this->getSessions($relationType) as $session) {
2406
            if ($session->isCurrentlyAccessible()) {
2407
                $sessions[] = $session;
2408
            }
2409
        }
2410
2411
        return $sessions;
2412
    }
2413
2414
    public function getResourceIdentifier(): int
2415
    {
2416
        return $this->id;
2417
    }
2418
2419
    public function getResourceName(): string
2420
    {
2421
        return $this->getUsername();
2422
    }
2423
2424
    public function setResourceName(string $name)
2425
    {
2426
        $this->setUsername($name);
2427
    }
2428
2429
    public function setParent(AbstractResource $parent)
2430
    {
2431
    }
2432
2433
    public function getDefaultIllustration($size): string
2434
    {
2435
        $size = empty($size) ? 32 : (int) $size;
2436
2437
        return "/img/icons/$size/unknown.png";
2438
    }
2439
2440
    /**
2441
     * Find the largest sort value in a given UserCourseCategory
2442
     * This method is used when we are moving a course to a different category
2443
     * and also when a user subscribes to courses (the new course is added at the end of the main category).
2444
     *
2445
     * Used to be implemented in global function \api_max_sort_value.
2446
     * Reimplemented using the ORM cache.
2447
     *
2448
     * @param UserCourseCategory|null $userCourseCategory the user_course_category
2449
     *
2450
     * @return int|mixed
2451
     */
2452
    public function getMaxSortValue($userCourseCategory = null)
2453
    {
2454
        $categoryCourses = $this->courses->matching(
2455
            Criteria::create()
2456
                ->where(Criteria::expr()->neq('relationType', COURSE_RELATION_TYPE_RRHH))
2457
                ->andWhere(Criteria::expr()->eq('userCourseCat', $userCourseCategory))
2458
        );
2459
2460
        return $categoryCourses->isEmpty()
2461
            ? 0
2462
            : max(
2463
                $categoryCourses->map(
2464
                    /** @var CourseRelUser $courseRelUser */
2465
                    function ($courseRelUser) {
2466
                        return $courseRelUser->getSort();
2467
                    }
2468
                )->toArray()
2469
            );
2470
    }
2471
}
2472