Completed
Push — master ( 036366...035555 )
by Julito
12:18
created

User::removeGroup()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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

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