Completed
Push — master ( ddfd23...1a5e2c )
by Julito
11:34
created

User::setWebsite()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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

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

1670
            /** @scrutinizer ignore-call */ 
1671
            $names[] = $group->getName();

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