Completed
Push — master ( c5384e...ddfd23 )
by Julito
09:27
created

User::getUserId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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

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