Completed
Push — master ( 83f4f4...7038dd )
by Julito
11:28
created

User::getUuid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
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 Doctrine\Common\Collections\ArrayCollection;
14
use Doctrine\Common\Collections\Collection;
15
use Doctrine\Common\Collections\Criteria;
16
use Doctrine\ORM\Event\LifecycleEventArgs;
17
use Doctrine\ORM\Mapping as ORM;
18
use Ramsey\Uuid\Uuid;
19
use Ramsey\Uuid\UuidInterface;
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\Validator\Constraints as Assert;
25
use Symfony\Component\Validator\Mapping\ClassMetadata;
26
27
/**
28
 * @ApiResource(
29
 *      attributes={"security"="is_granted('ROLE_ADMIN')"},
30
 *      iri="http://schema.org/Person",
31
 *      attributes={"security"="is_granted('ROLE_ADMIN')"},
32
 *      normalizationContext={"groups"={"user:read"}},
33
 *      denormalizationContext={"groups"={"user:write"}},
34
 *      collectionOperations={"get"},
35
 *      itemOperations={
36
 *          "get"={},
37
 *          "put"={},
38
 *          "delete"={},
39
 *     }
40
 * )
41
 *
42
 * @ApiFilter(SearchFilter::class, properties={"username": "partial", "firstname" : "partial"})
43
 * @ApiFilter(BooleanFilter::class, properties={"isActive"})
44
 *
45
 * @ORM\HasLifecycleCallbacks
46
 * @ORM\Table(
47
 *  name="user",
48
 *  indexes={
49
 *      @ORM\Index(name="status", columns={"status"})
50
 *  }
51
 * )
52
 * @UniqueEntity("username")
53
 * @ORM\Entity()
54
 */
55
class User implements UserInterface, EquatableInterface
56
{
57
    public const ROLE_DEFAULT = 'ROLE_USER';
58
    public const ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN';
59
60
    public const COURSE_MANAGER = 1;
61
    public const TEACHER = 1;
62
    public const SESSION_ADMIN = 3;
63
    public const DRH = 4;
64
    public const STUDENT = 5;
65
    public const ANONYMOUS = 6;
66
67
    /**
68
     * @var int
69
     * @Groups({"user:read"})
70
     * @ORM\Column(name="id", type="integer")
71
     * @ORM\Id
72
     * @ORM\GeneratedValue(strategy="AUTO")
73
     */
74
    protected $id;
75
76
    /**
77
     *
78
     * @var UuidInterface|null
79
     *
80
     * @ORM\Column(type="uuid", unique=true)
81
     */
82
    protected $uuid;
83
84
    /**
85
     * @ORM\Column(type="string", unique=true, nullable=true)
86
     */
87
    protected $apiToken;
88
89
    /**
90
     * @var string
91
     * @Assert\NotBlank()
92
     * @ApiProperty(iri="http://schema.org/name")
93
     * @Groups({"user:read", "user:write"})
94
     * @ORM\Column(name="firstname", type="string", length=64, nullable=true, unique=false)
95
     */
96
    protected $firstname;
97
98
    /**
99
     * @var string
100
     * @Groups({"user:read", "user:write"})
101
     * @ORM\Column(name="lastname", type="string", length=64, nullable=true, unique=false)
102
     */
103
    protected $lastname;
104
105
    /**
106
     * @var string
107
     * @Groups({"user:read", "user:write"})
108
     * @ORM\Column(name="website", type="string", length=64, nullable=true)
109
     */
110
    protected $website;
111
112
    /**
113
     * @var string
114
     * @Groups({"user:read", "user:write"})
115
     * @ORM\Column(name="biography", type="text", nullable=true)
116
     */
117
    protected $biography;
118
119
    /**
120
     * @var string
121
     * @Groups({"user:read", "user:write"})
122
     * @ORM\Column(name="locale", type="string", length=8, nullable=true, unique=false)
123
     */
124
    protected $locale;
125
126
    /**
127
     * @var string
128
     * @Groups({"user:read", "user:write", "course:read"})
129
     * @Assert\NotBlank()
130
     * @ORM\Column(name="username", type="string", length=100, nullable=false, unique=true)
131
     */
132
    protected $username;
133
134
    /**
135
     * @var string|null
136
     */
137
    protected $plainPassword;
138
139
    /**
140
     * @var string
141
     * @ORM\Column(name="password", type="string", length=255, nullable=false, unique=false)
142
     */
143
    protected $password;
144
145
    /**
146
     * @var string
147
     *
148
     * @ORM\Column(name="username_canonical", type="string", length=180, nullable=false)
149
     */
150
    protected $usernameCanonical;
151
152
    /**
153
     * @var string
154
     * @Groups({"user:read", "user:write"})
155
     * @ORM\Column(name="timezone", type="string", length=64)
156
     */
157
    protected $timezone;
158
159
    /**
160
     * @var string
161
     * @ORM\Column(name="email_canonical", type="string", length=100, nullable=false, unique=false)
162
     */
163
    protected $emailCanonical;
164
165
    /**
166
     * @var string
167
     * @var string
168
     * @Groups({"user:read", "user:write"})
169
     * @Assert\NotBlank()
170
     * @Assert\Email()
171
     *
172
     * @ORM\Column(name="email", type="string", length=100, nullable=false, unique=false)
173
     */
174
    protected $email;
175
176
    /**
177
     * @var bool
178
     *
179
     * @ORM\Column(name="locked", type="boolean")
180
     */
181
    protected $locked;
182
183
    /**
184
     * @var bool
185
     * @Assert\NotBlank()
186
     * @Groups({"user:read", "user:write"})
187
     * @ORM\Column(name="enabled", type="boolean")
188
     */
189
    protected $enabled;
190
191
    /**
192
     * @var bool
193
     * @Groups({"user:read", "user:write"})
194
     * @ORM\Column(name="expired", type="boolean")
195
     */
196
    protected $expired;
197
198
    /**
199
     * @var bool
200
     *
201
     * @ORM\Column(name="credentials_expired", type="boolean")
202
     */
203
    protected $credentialsExpired;
204
205
    /**
206
     * @var \DateTime
207
     *
208
     * @ORM\Column(name="credentials_expire_at", type="datetime", nullable=true, unique=false)
209
     */
210
    protected $credentialsExpireAt;
211
212
    /**
213
     * @var \DateTime
214
     *
215
     * @ORM\Column(name="date_of_birth", type="datetime", nullable=true)
216
     */
217
    protected $dateOfBirth;
218
219
    /**
220
     * @var \DateTime
221
     * @Groups({"user:read", "user:write"})
222
     * @ORM\Column(name="expires_at", type="datetime", nullable=true, unique=false)
223
     */
224
    protected $expiresAt;
225
226
    /**
227
     * @var string
228
     * @Groups({"user:read", "user:write"})
229
     * @ORM\Column(name="phone", type="string", length=64, nullable=true, unique=false)
230
     */
231
    protected $phone;
232
233
    /**
234
     * @var string
235
     * @Groups({"user:read", "user:write"})
236
     * @ORM\Column(name="address", type="string", length=250, nullable=true, unique=false)
237
     */
238
    protected $address;
239
240
    /**
241
     * @var AccessUrl
242
     */
243
    protected $currentUrl;
244
245
    /**
246
     * @ORM\Column(type="string", length=255)
247
     */
248
    protected $salt;
249
250
    /**
251
     * @var \DateTime
252
     * @Groups({"user:read", "user:write"})
253
     * @ORM\Column(name="last_login", type="datetime", nullable=true, unique=false)
254
     */
255
    protected $lastLogin;
256
257
    /**
258
     * Random string sent to the user email address in order to verify it.
259
     *
260
     * @var string
261
     * @ORM\Column(name="confirmation_token", type="string", length=255, nullable=true)
262
     */
263
    protected $confirmationToken;
264
265
    /**
266
     * @var \DateTime
267
     *
268
     * @ORM\Column(name="password_requested_at", type="datetime", nullable=true, unique=false)
269
     */
270
    protected $passwordRequestedAt;
271
272
    /**
273
     * @ApiSubresource()
274
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CourseRelUser", mappedBy="user", orphanRemoval=true)
275
     */
276
    protected $courses;
277
278
    /**
279
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\UsergroupRelUser", mappedBy="user")
280
     */
281
    protected $classes;
282
283
    /**
284
     * ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CDropboxPost", mappedBy="user").
285
     */
286
    protected $dropBoxReceivedFiles;
287
288
    /**
289
     * ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CDropboxFile", mappedBy="userSent").
290
     */
291
    protected $dropBoxSentFiles;
292
293
    /**
294
     * @Groups({"user:read", "user:write"})
295
     * @ORM\Column(type="array")
296
     */
297
    protected $roles;
298
299
    /**
300
     * @var bool
301
     *
302
     * @ORM\Column(name="profile_completed", type="boolean", nullable=true)
303
     */
304
    protected $profileCompleted;
305
306
    /**
307
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\JuryMembers", mappedBy="user")
308
     */
309
    //protected $jurySubscriptions;
310
311
    /**
312
     * @var Group[]
313
     * @ORM\ManyToMany(targetEntity="Chamilo\CoreBundle\Entity\Group", inversedBy="users")
314
     * @ORM\JoinTable(
315
     *      name="fos_user_user_group",
316
     *      joinColumns={
317
     *          @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="cascade")
318
     *      },
319
     *      inverseJoinColumns={
320
     *          @ORM\JoinColumn(name="group_id", referencedColumnName="id")
321
     *      }
322
     * )
323
     */
324
    protected $groups;
325
326
    /**
327
     * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CurriculumItemRelUser", mappedBy="user").
328
     */
329
    protected $curriculumItems;
330
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
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\GradebookCategory", mappedBy="user")
394
     */
395
    protected $gradeBookCategories;
396
397
    /**
398
     * @ORM\OneToMany(
399
     *     targetEntity="Chamilo\CoreBundle\Entity\SessionRelUser",
400
     *     mappedBy="user",
401
     *     cascade={"persist", "remove"},
402
     *     orphanRemoval=true
403
     * )
404
     */
405
    protected $sessions;
406
407
    /**
408
     * @var Collection
409
     *
410
     * @ORM\OneToMany(
411
     *     targetEntity="Chamilo\CourseBundle\Entity\CGroupRelUser",
412
     *     mappedBy="user",
413
     *     cascade={"persist", "remove"},
414
     *     orphanRemoval=true
415
     * )
416
     */
417
    protected $courseGroupsAsMember;
418
419
    /**
420
     * @var Collection
421
     *
422
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CGroupRelTutor", mappedBy="user", orphanRemoval=true)
423
     */
424
    protected $courseGroupsAsTutor;
425
426
    /**
427
     * @var string
428
     *
429
     * @ORM\Column(name="auth_source", type="string", length=50, nullable=true, unique=false)
430
     */
431
    protected $authSource;
432
433
    /**
434
     * @var int
435
     *
436
     * @ORM\Column(name="status", type="integer", nullable=false)
437
     */
438
    protected $status;
439
440
    /**
441
     * @var string
442
     *
443
     * @ORM\Column(name="official_code", type="string", length=40, nullable=true, unique=false)
444
     */
445
    protected $officialCode;
446
447
    /**
448
     * @var string
449
     *
450
     * @ORM\Column(name="picture_uri", type="string", length=250, nullable=true, unique=false)
451
     */
452
    protected $pictureUri;
453
454
    /**
455
     * @var int
456
     *
457
     * @ORM\Column(name="creator_id", type="integer", nullable=true, unique=false)
458
     */
459
    protected $creatorId;
460
461
    /**
462
     * @var string
463
     *
464
     * @ORM\Column(name="competences", type="text", nullable=true, unique=false)
465
     */
466
    protected $competences;
467
468
    /**
469
     * @var string
470
     *
471
     * @ORM\Column(name="diplomas", type="text", nullable=true, unique=false)
472
     */
473
    protected $diplomas;
474
475
    /**
476
     * @var string
477
     *
478
     * @ORM\Column(name="openarea", type="text", nullable=true, unique=false)
479
     */
480
    protected $openarea;
481
482
    /**
483
     * @var string
484
     *
485
     * @ORM\Column(name="teach", type="text", nullable=true, unique=false)
486
     */
487
    protected $teach;
488
489
    /**
490
     * @var string
491
     *
492
     * @ORM\Column(name="productions", type="string", length=250, nullable=true, unique=false)
493
     */
494
    protected $productions;
495
496
    /**
497
     * @var string
498
     *
499
     * @ORM\Column(name="language", type="string", length=40, nullable=true, unique=false)
500
     */
501
    protected $language;
502
503
    /**
504
     * @var \DateTime
505
     *
506
     * @ORM\Column(name="registration_date", type="datetime", nullable=false, unique=false)
507
     */
508
    protected $registrationDate;
509
510
    /**
511
     * @var \DateTime
512
     *
513
     * @ORM\Column(name="expiration_date", type="datetime", nullable=true, unique=false)
514
     */
515
    protected $expirationDate;
516
517
    /**
518
     * @var bool
519
     *
520
     * @ORM\Column(name="active", type="boolean", nullable=false, unique=false)
521
     */
522
    protected $active;
523
524
    /**
525
     * @var string
526
     *
527
     * @ORM\Column(name="openid", type="string", length=255, nullable=true, unique=false)
528
     */
529
    protected $openid;
530
531
    /**
532
     * @var string
533
     *
534
     * @ORM\Column(name="theme", type="string", length=255, nullable=true, unique=false)
535
     */
536
    protected $theme;
537
538
    /**
539
     * @var int
540
     *
541
     * @ORM\Column(name="hr_dept_id", type="smallint", nullable=true, unique=false)
542
     */
543
    protected $hrDeptId;
544
545
    /**
546
     * @var ArrayCollection
547
     *
548
     * @ORM\OneToMany(
549
     *     targetEntity="Chamilo\CoreBundle\Entity\Message",
550
     *     mappedBy="userSender",
551
     *     cascade={"persist", "remove"},
552
     *     orphanRemoval=true
553
     * )
554
     */
555
    protected $sentMessages;
556
557
    /**
558
     * @var ArrayCollection
559
     *
560
     * @ORM\OneToMany(
561
     *     targetEntity="Chamilo\CoreBundle\Entity\Message",
562
     *     mappedBy="userReceiver",
563
     *     cascade={"persist", "remove"},
564
     *     orphanRemoval=true
565
     * )
566
     */
567
    protected $receivedMessages;
568
569
    /**
570
     * @var \DateTime
571
     * @ORM\Column(name="created_at", type="datetime", nullable=true, unique=false)
572
     */
573
    protected $createdAt;
574
575
    /**
576
     * @var \DateTime
577
     * @ORM\Column(name="updated_at", type="datetime", nullable=true, unique=false)
578
     */
579
    protected $updatedAt;
580
581
    /**
582
     * Constructor.
583
     */
584
    public function __construct()
585
    {
586
        $this->uuid = Uuid::uuid4()->toString();
587
        $this->status = self::STUDENT;
588
        $this->salt = sha1(uniqid(null, true));
589
        $this->active = true;
590
        $this->registrationDate = new \DateTime();
591
        $this->authSource = 'platform';
592
        $this->courses = new ArrayCollection();
593
        //$this->items = new ArrayCollection();
594
        $this->classes = new ArrayCollection();
595
        $this->curriculumItems = new ArrayCollection();
596
        $this->portals = new ArrayCollection();
597
        $this->dropBoxSentFiles = new ArrayCollection();
598
        $this->dropBoxReceivedFiles = new ArrayCollection();
599
        $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...
600
        //$this->extraFields = new ArrayCollection();
601
        $this->createdAt = new \DateTime();
602
        $this->updatedAt = new \DateTime();
603
604
        $this->enabled = false;
605
        $this->locked = false;
606
        $this->expired = false;
607
        $this->roles = [];
608
        $this->credentialsExpired = false;
609
610
        $this->courseGroupsAsMember = new ArrayCollection();
611
        $this->courseGroupsAsTutor = new ArrayCollection();
612
    }
613
614
    /**
615
     * @return int
616
     */
617
    public function getId()
618
    {
619
        return $this->id;
620
    }
621
622
    /**
623
     * @param int $userId
624
     */
625
    public function setId($userId)
626
    {
627
        $this->id = $userId;
628
    }
629
630
    public function getUuid(): UuidInterface
631
    {
632
        return $this->uuid;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->uuid could return the type null which is incompatible with the type-hinted return Ramsey\Uuid\UuidInterface. Consider adding an additional type-check to rule them out.
Loading history...
633
    }
634
635
    /**
636
     * @return string
637
     */
638
    public function __toString()
639
    {
640
        return $this->username;
641
    }
642
643
    /**
644
     * @return $this
645
     */
646
    public function setResourceNode(ResourceNode $resourceNode): self
647
    {
648
        $this->resourceNode = $resourceNode;
649
650
        return $this;
651
    }
652
653
    public function getResourceNode(): ResourceNode
654
    {
655
        return $this->resourceNode;
656
    }
657
658
    /**
659
     * @return ArrayCollection|ResourceNode[]
660
     */
661
    public function getResourceNodes()
662
    {
663
        return $this->resourceNodes;
664
    }
665
666
    /**
667
     * @return User
668
     */
669
    public function setResourceNodes($resourceNodes)
670
    {
671
        $this->resourceNodes = $resourceNodes;
672
673
        return $this;
674
    }
675
676
    /**
677
     * @ORM\PostPersist()
678
     */
679
    public function postPersist(LifecycleEventArgs $args)
680
    {
681
        /*$user = $args->getEntity();
682
        */
683
    }
684
685
686
    /**
687
     * @return ArrayCollection
688
     */
689
    public function getDropBoxSentFiles()
690
    {
691
        return $this->dropBoxSentFiles;
692
    }
693
694
    /**
695
     * @return ArrayCollection
696
     */
697
    public function getDropBoxReceivedFiles()
698
    {
699
        return $this->dropBoxReceivedFiles;
700
    }
701
702
    /**
703
     * @param ArrayCollection $value
704
     */
705
    public function setDropBoxSentFiles($value)
706
    {
707
        $this->dropBoxSentFiles = $value;
708
    }
709
710
    /**
711
     * @param ArrayCollection $value
712
     */
713
    public function setDropBoxReceivedFiles($value)
714
    {
715
        $this->dropBoxReceivedFiles = $value;
716
    }
717
718
    /**
719
     * @param ArrayCollection $courses
720
     */
721
    public function setCourses($courses)
722
    {
723
        $this->courses = $courses;
724
    }
725
726
    public function getCourses(): Collection
727
    {
728
        return $this->courses;
729
    }
730
731
    /**
732
     * @return array
733
     */
734
    public static function getPasswordConstraints()
735
    {
736
        return
737
            [
738
                new Assert\Length(['min' => 5]),
739
                // Alpha numeric + "_" or "-"
740
                new Assert\Regex(
741
                    [
742
                        'pattern' => '/^[a-z\-_0-9]+$/i',
743
                        'htmlPattern' => '/^[a-z\-_0-9]+$/i', ]
744
                ),
745
                // Min 3 letters - not needed
746
                /*new Assert\Regex(array(
747
                    'pattern' => '/[a-z]{3}/i',
748
                    'htmlPattern' => '/[a-z]{3}/i')
749
                ),*/
750
                // Min 2 numbers
751
                new Assert\Regex(
752
                    [
753
                        'pattern' => '/[0-9]{2}/',
754
                        'htmlPattern' => '/[0-9]{2}/', ]
755
                ),
756
            ]
757
            ;
758
    }
759
760
    public static function loadValidatorMetadata(ClassMetadata $metadata)
761
    {
762
        //$metadata->addPropertyConstraint('firstname', new Assert\NotBlank());
763
        //$metadata->addPropertyConstraint('lastname', new Assert\NotBlank());
764
        //$metadata->addPropertyConstraint('email', new Assert\Email());
765
        /*
766
        $metadata->addPropertyConstraint('password',
767
            new Assert\Collection(self::getPasswordConstraints())
768
        );*/
769
770
        /*$metadata->addConstraint(new UniqueEntity(array(
771
            'fields'  => 'username',
772
            'message' => 'This value is already used.',
773
        )));*/
774
775
        /*$metadata->addPropertyConstraint(
776
            'username',
777
            new Assert\Length(array(
778
                'min'        => 2,
779
                'max'        => 50,
780
                '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.',
781
                '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.',
782
            ))
783
        );*/
784
    }
785
786
    /**
787
     * @return ArrayCollection
788
     */
789
    public function getPortals()
790
    {
791
        return $this->portals;
792
    }
793
794
    /**
795
     * @param $portal
796
     */
797
    public function setPortal($portal)
798
    {
799
        $this->portals->add($portal);
800
    }
801
802
    /**
803
     * @param $value
804
     * @param (mixed|string|string[])[] $value
805
     */
806
    public function setPortals(array $value)
807
    {
808
        $this->portals = $value;
809
    }
810
811
    /**
812
     * @return ArrayCollection
813
     */
814
    public function getCurriculumItems()
815
    {
816
        return $this->curriculumItems;
817
    }
818
819
    /**
820
     * @param $items
821
     *
822
     * @return $this
823
     */
824
    public function setCurriculumItems(array $items)
825
    {
826
        $this->curriculumItems = $items;
827
828
        return $this;
829
    }
830
831
    /**
832
     * @return bool
833
     */
834
    public function getIsActive()
835
    {
836
        return 1 == $this->active;
837
    }
838
839
    /**
840
     * @return bool
841
     */
842
    public function isActive()
843
    {
844
        return $this->getIsActive();
845
    }
846
847
    public function isEnabled()
848
    {
849
        return 1 == $this->getActive();
850
    }
851
852
    /**
853
     * Set salt.
854
     *
855
     * @param string $salt
856
     *
857
     * @return User
858
     */
859
    public function setSalt($salt)
860
    {
861
        $this->salt = $salt;
862
863
        return $this;
864
    }
865
866
    /**
867
     * Get salt.
868
     *
869
     * @return string
870
     */
871
    public function getSalt()
872
    {
873
        return $this->salt;
874
    }
875
876
    /**
877
     * @param ArrayCollection $classes
878
     *
879
     * @return $this
880
     */
881
    public function setClasses($classes)
882
    {
883
        $this->classes = $classes;
884
885
        return $this;
886
    }
887
888
    /**
889
     * @return ArrayCollection
890
     */
891
    public function getClasses()
892
    {
893
        return $this->classes;
894
    }
895
896
    public function getLps()
897
    {
898
        //return $this->lps;
899
        /*$criteria = Criteria::create()
900
            ->where(Criteria::expr()->eq("id", "666"))
901
            //->orderBy(array("username" => "ASC"))
902
            //->setFirstResult(0)
903
            //->setMaxResults(20)
904
        ;
905
        $lps = $this->lps->matching($criteria);*/
906
        /*return $this->lps->filter(
907
            function($entry) use ($idsToFilter) {
908
                return $entry->getId() == 1;
909
        });*/
910
    }
911
912
    /**
913
     * Returns the list of classes for the user.
914
     *
915
     * @return string
916
     */
917
    public function getCompleteNameWithClasses()
918
    {
919
        $classSubscription = $this->getClasses();
920
        $classList = [];
921
        /** @var UsergroupRelUser $subscription */
922
        foreach ($classSubscription as $subscription) {
923
            $class = $subscription->getUsergroup();
924
            $classList[] = $class->getName();
925
        }
926
        $classString = !empty($classList) ? ' ['.implode(', ', $classList).']' : null;
927
928
        return \UserManager::formatUserFullName($this).$classString;
929
    }
930
931
    /**
932
     * Set lastname.
933
     *
934
     * @return User
935
     */
936
    public function setLastname(string $lastname): self
937
    {
938
        $this->lastname = $lastname;
939
940
        return $this;
941
    }
942
943
    /**
944
     * Set firstname.
945
     *
946
     * @return User
947
     */
948
    public function setFirstname(string $firstname): self
949
    {
950
        $this->firstname = $firstname;
951
952
        return $this;
953
    }
954
955
    public function getPassword()
956
    {
957
        return $this->password;
958
    }
959
960
    public function setPassword(string $password): self
961
    {
962
        $this->password = $password;
963
964
        return $this;
965
    }
966
967
    /**
968
     * Set authSource.
969
     *
970
     * @param string $authSource
971
     *
972
     * @return User
973
     */
974
    public function setAuthSource($authSource)
975
    {
976
        $this->authSource = $authSource;
977
978
        return $this;
979
    }
980
981
    /**
982
     * Get authSource.
983
     *
984
     * @return string
985
     */
986
    public function getAuthSource()
987
    {
988
        return $this->authSource;
989
    }
990
991
    /**
992
     * Set email.
993
     *
994
     * @param string $email
995
     *
996
     * @return User
997
     */
998
    public function setEmail($email)
999
    {
1000
        $this->email = $email;
1001
1002
        return $this;
1003
    }
1004
1005
    /**
1006
     * Get email.
1007
     *
1008
     * @return string
1009
     */
1010
    public function getEmail()
1011
    {
1012
        return $this->email;
1013
    }
1014
1015
    /**
1016
     * Set status.
1017
     *
1018
     * @return User
1019
     */
1020
    public function setStatus(int $status)
1021
    {
1022
        $this->status = $status;
1023
1024
        return $this;
1025
    }
1026
1027
    /**
1028
     * Get status.
1029
     *
1030
     * @return int
1031
     */
1032
    public function getStatus()
1033
    {
1034
        return (int) $this->status;
1035
    }
1036
1037
    /**
1038
     * Set officialCode.
1039
     *
1040
     * @param string $officialCode
1041
     *
1042
     * @return User
1043
     */
1044
    public function setOfficialCode($officialCode)
1045
    {
1046
        $this->officialCode = $officialCode;
1047
1048
        return $this;
1049
    }
1050
1051
    /**
1052
     * Get officialCode.
1053
     *
1054
     * @return string
1055
     */
1056
    public function getOfficialCode()
1057
    {
1058
        return $this->officialCode;
1059
    }
1060
1061
    /**
1062
     * Set phone.
1063
     *
1064
     * @param string $phone
1065
     *
1066
     * @return User
1067
     */
1068
    public function setPhone($phone)
1069
    {
1070
        $this->phone = $phone;
1071
1072
        return $this;
1073
    }
1074
1075
    /**
1076
     * Get phone.
1077
     *
1078
     * @return string
1079
     */
1080
    public function getPhone()
1081
    {
1082
        return $this->phone;
1083
    }
1084
1085
    /**
1086
     * Set address.
1087
     *
1088
     * @param string $address
1089
     *
1090
     * @return User
1091
     */
1092
    public function setAddress($address)
1093
    {
1094
        $this->address = $address;
1095
1096
        return $this;
1097
    }
1098
1099
    /**
1100
     * Get address.
1101
     *
1102
     * @return string
1103
     */
1104
    public function getAddress()
1105
    {
1106
        return $this->address;
1107
    }
1108
1109
    /**
1110
     * Set creatorId.
1111
     *
1112
     * @param int $creatorId
1113
     *
1114
     * @return User
1115
     */
1116
    public function setCreatorId($creatorId)
1117
    {
1118
        $this->creatorId = $creatorId;
1119
1120
        return $this;
1121
    }
1122
1123
    /**
1124
     * Get creatorId.
1125
     *
1126
     * @return int
1127
     */
1128
    public function getCreatorId()
1129
    {
1130
        return $this->creatorId;
1131
    }
1132
1133
    /**
1134
     * Set competences.
1135
     *
1136
     * @param string $competences
1137
     *
1138
     * @return User
1139
     */
1140
    public function setCompetences($competences)
1141
    {
1142
        $this->competences = $competences;
1143
1144
        return $this;
1145
    }
1146
1147
    /**
1148
     * Get competences.
1149
     *
1150
     * @return string
1151
     */
1152
    public function getCompetences()
1153
    {
1154
        return $this->competences;
1155
    }
1156
1157
    /**
1158
     * Set diplomas.
1159
     *
1160
     * @param string $diplomas
1161
     *
1162
     * @return User
1163
     */
1164
    public function setDiplomas($diplomas)
1165
    {
1166
        $this->diplomas = $diplomas;
1167
1168
        return $this;
1169
    }
1170
1171
    /**
1172
     * Get diplomas.
1173
     *
1174
     * @return string
1175
     */
1176
    public function getDiplomas()
1177
    {
1178
        return $this->diplomas;
1179
    }
1180
1181
    /**
1182
     * Set openarea.
1183
     *
1184
     * @param string $openarea
1185
     *
1186
     * @return User
1187
     */
1188
    public function setOpenarea($openarea)
1189
    {
1190
        $this->openarea = $openarea;
1191
1192
        return $this;
1193
    }
1194
1195
    /**
1196
     * Get openarea.
1197
     *
1198
     * @return string
1199
     */
1200
    public function getOpenarea()
1201
    {
1202
        return $this->openarea;
1203
    }
1204
1205
    /**
1206
     * Set teach.
1207
     *
1208
     * @param string $teach
1209
     *
1210
     * @return User
1211
     */
1212
    public function setTeach($teach)
1213
    {
1214
        $this->teach = $teach;
1215
1216
        return $this;
1217
    }
1218
1219
    /**
1220
     * Get teach.
1221
     *
1222
     * @return string
1223
     */
1224
    public function getTeach()
1225
    {
1226
        return $this->teach;
1227
    }
1228
1229
    /**
1230
     * Set productions.
1231
     *
1232
     * @param string $productions
1233
     *
1234
     * @return User
1235
     */
1236
    public function setProductions($productions)
1237
    {
1238
        $this->productions = $productions;
1239
1240
        return $this;
1241
    }
1242
1243
    /**
1244
     * Get productions.
1245
     *
1246
     * @return string
1247
     */
1248
    public function getProductions()
1249
    {
1250
        return $this->productions;
1251
    }
1252
1253
    /**
1254
     * Set language.
1255
     *
1256
     * @param string $language
1257
     *
1258
     * @return User
1259
     */
1260
    public function setLanguage($language)
1261
    {
1262
        $this->language = $language;
1263
1264
        return $this;
1265
    }
1266
1267
    /**
1268
     * Get language.
1269
     *
1270
     * @return string
1271
     */
1272
    public function getLanguage()
1273
    {
1274
        return $this->language;
1275
    }
1276
1277
    /**
1278
     * Set registrationDate.
1279
     *
1280
     * @param \DateTime $registrationDate
1281
     *
1282
     * @return User
1283
     */
1284
    public function setRegistrationDate($registrationDate)
1285
    {
1286
        $this->registrationDate = $registrationDate;
1287
1288
        return $this;
1289
    }
1290
1291
    /**
1292
     * Get registrationDate.
1293
     *
1294
     * @return \DateTime
1295
     */
1296
    public function getRegistrationDate()
1297
    {
1298
        return $this->registrationDate;
1299
    }
1300
1301
    /**
1302
     * Set expirationDate.
1303
     *
1304
     * @param \DateTime $expirationDate
1305
     *
1306
     * @return User
1307
     */
1308
    public function setExpirationDate($expirationDate)
1309
    {
1310
        $this->expirationDate = $expirationDate;
1311
1312
        return $this;
1313
    }
1314
1315
    /**
1316
     * Get expirationDate.
1317
     *
1318
     * @return \DateTime
1319
     */
1320
    public function getExpirationDate()
1321
    {
1322
        return $this->expirationDate;
1323
    }
1324
1325
    /**
1326
     * Set active.
1327
     *
1328
     * @param bool $active
1329
     *
1330
     * @return User
1331
     */
1332
    public function setActive($active)
1333
    {
1334
        $this->active = $active;
1335
1336
        return $this;
1337
    }
1338
1339
    /**
1340
     * Get active.
1341
     *
1342
     * @return bool
1343
     */
1344
    public function getActive()
1345
    {
1346
        return $this->active;
1347
    }
1348
1349
    /**
1350
     * Set openid.
1351
     *
1352
     * @param string $openid
1353
     *
1354
     * @return User
1355
     */
1356
    public function setOpenid($openid)
1357
    {
1358
        $this->openid = $openid;
1359
1360
        return $this;
1361
    }
1362
1363
    /**
1364
     * Get openid.
1365
     *
1366
     * @return string
1367
     */
1368
    public function getOpenid()
1369
    {
1370
        return $this->openid;
1371
    }
1372
1373
    /**
1374
     * Set theme.
1375
     *
1376
     * @param string $theme
1377
     *
1378
     * @return User
1379
     */
1380
    public function setTheme($theme)
1381
    {
1382
        $this->theme = $theme;
1383
1384
        return $this;
1385
    }
1386
1387
    /**
1388
     * Get theme.
1389
     *
1390
     * @return string
1391
     */
1392
    public function getTheme()
1393
    {
1394
        return $this->theme;
1395
    }
1396
1397
    /**
1398
     * Set hrDeptId.
1399
     *
1400
     * @param int $hrDeptId
1401
     *
1402
     * @return User
1403
     */
1404
    public function setHrDeptId($hrDeptId)
1405
    {
1406
        $this->hrDeptId = $hrDeptId;
1407
1408
        return $this;
1409
    }
1410
1411
    /**
1412
     * Get hrDeptId.
1413
     *
1414
     * @return int
1415
     */
1416
    public function getHrDeptId()
1417
    {
1418
        return $this->hrDeptId;
1419
    }
1420
1421
    /**
1422
     * @return \DateTime
1423
     */
1424
    public function getMemberSince()
1425
    {
1426
        return $this->registrationDate;
1427
    }
1428
1429
    /**
1430
     * @return bool
1431
     */
1432
    public function isOnline()
1433
    {
1434
        return false;
1435
    }
1436
1437
    /**
1438
     * @return int
1439
     */
1440
    public function getIdentifier()
1441
    {
1442
        return $this->getId();
1443
    }
1444
1445
    /**
1446
     * @return string
1447
     */
1448
    public function getSlug()
1449
    {
1450
        return $this->getUsername();
1451
    }
1452
1453
    /**
1454
     * @param string $slug
1455
     *
1456
     * @return User
1457
     */
1458
    public function setSlug($slug)
1459
    {
1460
        return $this->setUsername($slug);
1461
    }
1462
1463
    public function setUsername($username)
1464
    {
1465
        $this->username = $username;
1466
1467
        return $this;
1468
    }
1469
1470
    public function setUsernameCanonical($usernameCanonical)
1471
    {
1472
        $this->usernameCanonical = $usernameCanonical;
1473
1474
        return $this;
1475
    }
1476
1477
    public function setEmailCanonical($emailCanonical)
1478
    {
1479
        $this->emailCanonical = $emailCanonical;
1480
1481
        return $this;
1482
    }
1483
1484
    /**
1485
     * Set lastLogin.
1486
     *
1487
     * @param \DateTime $lastLogin
1488
     *
1489
     * @return User
1490
     */
1491
    public function setLastLogin(\DateTime $lastLogin = null)
1492
    {
1493
        $this->lastLogin = $lastLogin;
1494
1495
        return $this;
1496
    }
1497
1498
    /**
1499
     * Get lastLogin.
1500
     *
1501
     * @return \DateTime
1502
     */
1503
    public function getLastLogin()
1504
    {
1505
        return $this->lastLogin;
1506
    }
1507
1508
    /**
1509
     * Get sessionCourseSubscription.
1510
     *
1511
     * @return ArrayCollection
1512
     */
1513
    public function getSessionCourseSubscriptions()
1514
    {
1515
        return $this->sessionCourseSubscriptions;
1516
    }
1517
1518
    /**
1519
     * @param $value
1520
     * @param string[][] $value
1521
     *
1522
     * @return $this
1523
     */
1524
    public function setSessionCourseSubscriptions(array $value)
1525
    {
1526
        $this->sessionCourseSubscriptions = $value;
1527
1528
        return $this;
1529
    }
1530
1531
    /**
1532
     * @return string
1533
     */
1534
    public function getConfirmationToken()
1535
    {
1536
        return $this->confirmationToken;
1537
    }
1538
1539
    /**
1540
     * @param string $confirmationToken
1541
     *
1542
     * @return User
1543
     */
1544
    public function setConfirmationToken($confirmationToken)
1545
    {
1546
        $this->confirmationToken = $confirmationToken;
1547
1548
        return $this;
1549
    }
1550
1551
    /**
1552
     * @return \DateTime
1553
     */
1554
    public function getPasswordRequestedAt()
1555
    {
1556
        return $this->passwordRequestedAt;
1557
    }
1558
1559
    /**
1560
     * @return bool
1561
     */
1562
    /*public function isPasswordRequestNonExpired($ttl)
1563
    {
1564
        return $this->getPasswordRequestedAt() instanceof \DateTime &&
1565
            $this->getPasswordRequestedAt()->getTimestamp() + $ttl > time();
1566
    }*/
1567
1568
    public function getUsername(): string
1569
    {
1570
        return (string) $this->username;
1571
    }
1572
1573
    public function getPlainPassword(): ?string
1574
    {
1575
        return $this->plainPassword;
1576
    }
1577
1578
    public function setPlainPassword(string $password)
1579
    {
1580
        $this->plainPassword = $password;
1581
1582
        // forces the object to look "dirty" to Doctrine. Avoids
1583
        // Doctrine *not* saving this entity, if only plainPassword changes
1584
        $this->password = null;
1585
1586
        return $this;
1587
    }
1588
1589
    /**
1590
     * Returns the expiration date.
1591
     *
1592
     * @return \DateTime|null
1593
     */
1594
    public function getExpiresAt()
1595
    {
1596
        return $this->expiresAt;
1597
    }
1598
1599
    /**
1600
     * Returns the credentials expiration date.
1601
     *
1602
     * @return \DateTime
1603
     */
1604
    public function getCredentialsExpireAt()
1605
    {
1606
        return $this->credentialsExpireAt;
1607
    }
1608
1609
    /**
1610
     * Sets the credentials expiration date.
1611
     *
1612
     * @return User
1613
     */
1614
    public function setCredentialsExpireAt(\DateTime $date = null)
1615
    {
1616
        $this->credentialsExpireAt = $date;
1617
1618
        return $this;
1619
    }
1620
1621
    public function addGroup($group)
1622
    {
1623
        if (!$this->getGroups()->contains($group)) {
1624
            $this->getGroups()->add($group);
1625
        }
1626
1627
        return $this;
1628
    }
1629
1630
    /**
1631
     * Sets the user groups.
1632
     *
1633
     * @param array $groups
1634
     *
1635
     * @return User
1636
     */
1637
    public function setGroups($groups)
1638
    {
1639
        foreach ($groups as $group) {
1640
            $this->addGroup($group);
1641
        }
1642
1643
        return $this;
1644
    }
1645
1646
    /**
1647
     * @return string
1648
     */
1649
    public function getFullname()
1650
    {
1651
        return sprintf('%s %s', $this->getFirstname(), $this->getLastname());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getFirstname() targeting Chamilo\CoreBundle\Entity\User::getFirstname() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure the usage of $this->getLastname() targeting Chamilo\CoreBundle\Entity\User::getLastname() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1652
    }
1653
1654
    public function getGroups()
1655
    {
1656
        return $this->groups;
1657
    }
1658
1659
    /**
1660
     * @return array
1661
     */
1662
    public function getGroupNames()
1663
    {
1664
        $names = [];
1665
        foreach ($this->getGroups() as $group) {
1666
            $names[] = $group->getName();
1667
        }
1668
1669
        return $names;
1670
    }
1671
1672
    /**
1673
     * @param string $name
1674
     *
1675
     * @return bool
1676
     */
1677
    public function hasGroup($name)
1678
    {
1679
        return in_array($name, $this->getGroupNames());
1680
    }
1681
1682
    public function removeGroup($group)
1683
    {
1684
        if ($this->getGroups()->contains($group)) {
1685
            $this->getGroups()->removeElement($group);
1686
        }
1687
1688
        return $this;
1689
    }
1690
1691
    /**
1692
     * @param string $role
1693
     *
1694
     * @return $this
1695
     */
1696
    public function addRole($role)
1697
    {
1698
        $role = strtoupper($role);
1699
        if ($role === static::ROLE_DEFAULT) {
1700
            return $this;
1701
        }
1702
1703
        if (!in_array($role, $this->roles, true)) {
1704
            $this->roles[] = $role;
1705
        }
1706
1707
        return $this;
1708
    }
1709
1710
    /**
1711
     * Returns the user roles.
1712
     *
1713
     * @return array The roles
1714
     */
1715
    public function getRoles()
1716
    {
1717
        $roles = $this->roles;
1718
1719
        foreach ($this->getGroups() as $group) {
1720
            $roles = array_merge($roles, $group->getRoles());
1721
        }
1722
1723
        // we need to make sure to have at least one role
1724
        $roles[] = 'ROLE_USER';
1725
1726
        return array_unique($roles);
1727
    }
1728
1729
    public function isAccountNonExpired()
1730
    {
1731
        /*if (true === $this->expired) {
1732
            return false;
1733
        }
1734
1735
        if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
1736
            return false;
1737
        }*/
1738
1739
        return true;
1740
    }
1741
1742
    public function isAccountNonLocked()
1743
    {
1744
        return true;
1745
        //return !$this->locked;
1746
    }
1747
1748
    public function isCredentialsNonExpired()
1749
    {
1750
        /*if (true === $this->credentialsExpired) {
1751
            return false;
1752
        }
1753
1754
        if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
1755
            return false;
1756
        }*/
1757
1758
        return true;
1759
    }
1760
1761
    /**
1762
     * @return bool
1763
     */
1764
    public function getCredentialsExpired()
1765
    {
1766
        return $this->credentialsExpired;
1767
    }
1768
1769
    /**
1770
     * @param bool $boolean
1771
     *
1772
     * @return User
1773
     */
1774
    public function setCredentialsExpired($boolean)
1775
    {
1776
        $this->credentialsExpired = $boolean;
1777
1778
        return $this;
1779
    }
1780
1781
    /**
1782
     * @param $boolean
1783
     *
1784
     * @return $this
1785
     */
1786
    public function setEnabled($boolean)
1787
    {
1788
        $this->enabled = (bool) $boolean;
1789
1790
        return $this;
1791
    }
1792
1793
    /**
1794
     * @return bool
1795
     */
1796
    public function getExpired()
1797
    {
1798
        return $this->expired;
1799
    }
1800
1801
    /**
1802
     * Sets this user to expired.
1803
     *
1804
     * @param bool $boolean
1805
     *
1806
     * @return User
1807
     */
1808
    public function setExpired($boolean)
1809
    {
1810
        $this->expired = (bool) $boolean;
1811
1812
        return $this;
1813
    }
1814
1815
    /**
1816
     * @return User
1817
     */
1818
    public function setExpiresAt(\DateTime $date)
1819
    {
1820
        $this->expiresAt = $date;
1821
1822
        return $this;
1823
    }
1824
1825
    public function getLocked(): bool
1826
    {
1827
        return $this->locked;
1828
    }
1829
1830
    /**
1831
     * @param $boolean
1832
     *
1833
     * @return $this
1834
     */
1835
    public function setLocked($boolean)
1836
    {
1837
        $this->locked = $boolean;
1838
1839
        return $this;
1840
    }
1841
1842
    /**
1843
     * @return $this
1844
     */
1845
    public function setRoles(array $roles)
1846
    {
1847
        $this->roles = [];
1848
1849
        foreach ($roles as $role) {
1850
            $this->addRole($role);
1851
        }
1852
1853
        return $this;
1854
    }
1855
1856
    /**
1857
     * Get achievedSkills.
1858
     *
1859
     * @return ArrayCollection
1860
     */
1861
    public function getAchievedSkills()
1862
    {
1863
        return $this->achievedSkills;
1864
    }
1865
1866
    /**
1867
     * @param $value
1868
     * @param string[] $value
1869
     *
1870
     * @return $this
1871
     */
1872
    public function setAchievedSkills(array $value)
1873
    {
1874
        $this->achievedSkills = $value;
1875
1876
        return $this;
1877
    }
1878
1879
    /**
1880
     * Check if the user has the skill.
1881
     *
1882
     * @param Skill $skill The skill
1883
     *
1884
     * @return bool
1885
     */
1886
    public function hasSkill(Skill $skill)
1887
    {
1888
        $achievedSkills = $this->getAchievedSkills();
1889
1890
        foreach ($achievedSkills as $userSkill) {
1891
            if ($userSkill->getSkill()->getId() !== $skill->getId()) {
1892
                continue;
1893
            }
1894
1895
            return true;
1896
        }
1897
    }
1898
1899
    /**
1900
     * @return bool
1901
     */
1902
    public function isProfileCompleted()
1903
    {
1904
        return $this->profileCompleted;
1905
    }
1906
1907
    /**
1908
     * @return User
1909
     */
1910
    public function setProfileCompleted($profileCompleted)
1911
    {
1912
        $this->profileCompleted = $profileCompleted;
1913
1914
        return $this;
1915
    }
1916
1917
    /**
1918
     * Sets the AccessUrl for the current user in memory.
1919
     *
1920
     * @return $this
1921
     */
1922
    public function setCurrentUrl(AccessUrl $url)
1923
    {
1924
        $urlList = $this->getPortals();
1925
        /** @var AccessUrlRelUser $item */
1926
        foreach ($urlList as $item) {
1927
            if ($item->getUrl()->getId() === $url->getId()) {
1928
                $this->currentUrl = $url;
1929
1930
                break;
1931
            }
1932
        }
1933
1934
        return $this;
1935
    }
1936
1937
    /**
1938
     * @return AccessUrl
1939
     */
1940
    public function getCurrentUrl()
1941
    {
1942
        return $this->currentUrl;
1943
    }
1944
1945
    /**
1946
     * Get sessionAsGeneralCoach.
1947
     *
1948
     * @return ArrayCollection
1949
     */
1950
    public function getSessionAsGeneralCoach()
1951
    {
1952
        return $this->sessionAsGeneralCoach;
1953
    }
1954
1955
    /**
1956
     * Get sessionAsGeneralCoach.
1957
     *
1958
     * @param ArrayCollection $value
1959
     *
1960
     * @return $this
1961
     */
1962
    public function setSessionAsGeneralCoach($value)
1963
    {
1964
        $this->sessionAsGeneralCoach = $value;
1965
1966
        return $this;
1967
    }
1968
1969
    public function getCommentedUserSkills()
1970
    {
1971
        return $this->commentedUserSkills;
1972
    }
1973
1974
    /**
1975
     * @return User
1976
     */
1977
    public function setCommentedUserSkills(array $commentedUserSkills)
1978
    {
1979
        $this->commentedUserSkills = $commentedUserSkills;
1980
1981
        return $this;
1982
    }
1983
1984
    /**
1985
     * @return bool
1986
     */
1987
    public function isEqualTo(UserInterface $user)
1988
    {
1989
        if ($this->password !== $user->getPassword()) {
1990
            return false;
1991
        }
1992
1993
        if ($this->salt !== $user->getSalt()) {
1994
            return false;
1995
        }
1996
1997
        if ($this->username !== $user->getUsername()) {
1998
            return false;
1999
        }
2000
2001
        return true;
2002
    }
2003
2004
    /**
2005
     * Get sentMessages.
2006
     *
2007
     * @return ArrayCollection
2008
     */
2009
    public function getSentMessages()
2010
    {
2011
        return $this->sentMessages;
2012
    }
2013
2014
    /**
2015
     * Get receivedMessages.
2016
     *
2017
     * @return ArrayCollection
2018
     */
2019
    public function getReceivedMessages()
2020
    {
2021
        return $this->receivedMessages;
2022
    }
2023
2024
    /**
2025
     * @param int $lastId Optional. The ID of the last received message
2026
     */
2027
    public function getUnreadReceivedMessages($lastId = 0): ArrayCollection
2028
    {
2029
        $criteria = Criteria::create();
2030
        $criteria->where(
2031
            Criteria::expr()->eq('msgStatus', MESSAGE_STATUS_UNREAD)
2032
        );
2033
2034
        if ($lastId > 0) {
2035
            $criteria->andWhere(
2036
                Criteria::expr()->gt('id', (int) $lastId)
2037
            );
2038
        }
2039
2040
        $criteria->orderBy(['sendDate' => Criteria::DESC]);
2041
2042
        return $this->receivedMessages->matching($criteria);
2043
    }
2044
2045
    public function getCourseGroupsAsMember(): Collection
2046
    {
2047
        return $this->courseGroupsAsMember;
2048
    }
2049
2050
    public function getCourseGroupsAsTutor(): Collection
2051
    {
2052
        return $this->courseGroupsAsTutor;
2053
    }
2054
2055
    public function getCourseGroupsAsMemberFromCourse(Course $course): ArrayCollection
2056
    {
2057
        $criteria = Criteria::create();
2058
        $criteria->where(
2059
            Criteria::expr()->eq('cId', $course)
2060
        );
2061
2062
        return $this->courseGroupsAsMember->matching($criteria);
2063
    }
2064
2065
    public function getFirstname()
2066
    {
2067
    }
2068
2069
    public function getLastname()
2070
    {
2071
    }
2072
2073
    public function eraseCredentials()
2074
    {
2075
        $this->plainPassword = null;
2076
    }
2077
2078
    public function hasRole($role)
2079
    {
2080
        return in_array(strtoupper($role), $this->getRoles(), true);
2081
    }
2082
2083
    public function isSuperAdmin()
2084
    {
2085
        return $this->hasRole('ROLE_SUPER_ADMIN');
2086
    }
2087
2088
    public function isUser(UserInterface $user = null)
2089
    {
2090
        return null !== $user && $this->getId() === $user->getId();
2091
    }
2092
2093
    public function removeRole($role)
2094
    {
2095
        if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
2096
            unset($this->roles[$key]);
2097
            $this->roles = array_values($this->roles);
2098
        }
2099
2100
        return $this;
2101
    }
2102
2103
    public function getUsernameCanonical()
2104
    {
2105
        return $this->usernameCanonical;
2106
    }
2107
2108
    public function getEmailCanonical()
2109
    {
2110
        return $this->emailCanonical;
2111
    }
2112
2113
    /**
2114
     * @param string $timezone
2115
     *
2116
     * @return User
2117
     */
2118
    public function setTimezone($timezone)
2119
    {
2120
        $this->timezone = $timezone;
2121
2122
        return $this;
2123
    }
2124
2125
    /**
2126
     * @return string
2127
     */
2128
    public function getTimezone()
2129
    {
2130
        return $this->timezone;
2131
    }
2132
2133
    /**
2134
     * @param string $locale
2135
     *
2136
     * @return User
2137
     */
2138
    public function setLocale($locale)
2139
    {
2140
        $this->locale = $locale;
2141
2142
        return $this;
2143
    }
2144
2145
    /**
2146
     * @return string
2147
     */
2148
    public function getLocale()
2149
    {
2150
        return $this->locale;
2151
    }
2152
2153
    /**
2154
     * @return string
2155
     */
2156
    public function getApiToken()
2157
    {
2158
        return $this->apiToken;
2159
    }
2160
2161
    /**
2162
     * @param string $apiToken
2163
     *
2164
     * @return User
2165
     */
2166
    public function setApiToken($apiToken)
2167
    {
2168
        $this->apiToken = $apiToken;
2169
2170
        return $this;
2171
    }
2172
2173
    public function getWebsite(): ?string
2174
    {
2175
        return $this->website;
2176
    }
2177
2178
    public function setWebsite(string $website): self
2179
    {
2180
        $this->website = $website;
2181
2182
        return $this;
2183
    }
2184
2185
    public function getBiography(): ?string
2186
    {
2187
        return $this->biography;
2188
    }
2189
2190
    public function setBiography(string $biography): self
2191
    {
2192
        $this->biography = $biography;
2193
2194
        return $this;
2195
    }
2196
2197
    /**
2198
     * @param \DateTime $dateOfBirth
2199
     *
2200
     * @return User
2201
     */
2202
    public function setDateOfBirth($dateOfBirth)
2203
    {
2204
        $this->dateOfBirth = $dateOfBirth;
2205
2206
        return $this;
2207
    }
2208
2209
    /**
2210
     * @return \DateTime
2211
     */
2212
    public function getDateOfBirth()
2213
    {
2214
        return $this->dateOfBirth;
2215
    }
2216
2217
    public function getCourseGroupsAsTutorFromCourse(Course $course): ArrayCollection
2218
    {
2219
        $criteria = Criteria::create();
2220
        $criteria->where(
2221
            Criteria::expr()->eq('cId', $course->getId())
2222
        );
2223
2224
        return $this->courseGroupsAsTutor->matching($criteria);
2225
    }
2226
}
2227