Completed
Push — master ( 0dfc19...c58ed8 )
by Julito
10:02
created

User::getCompleteNameWithClasses()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
c 0
b 0
f 0
nc 4
nop 0
dl 0
loc 12
rs 10
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Entity;
6
7
use ApiPlatform\Core\Annotation\ApiFilter;
8
use ApiPlatform\Core\Annotation\ApiProperty;
9
use ApiPlatform\Core\Annotation\ApiResource;
10
use ApiPlatform\Core\Annotation\ApiSubresource;
11
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
12
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
13
use Chamilo\CoreBundle\Entity\Resource\ResourceNode;
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Doctrine\Common\Collections\Criteria;
17
use Doctrine\ORM\Event\LifecycleEventArgs;
18
use Doctrine\ORM\Mapping as ORM;
19
use 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
 *      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"})
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
     * @ORM\Column(type="array")
281
     */
282
    protected $roles;
283
284
    /**
285
     * @var bool
286
     *
287
     * @ORM\Column(name="profile_completed", type="boolean", nullable=true)
288
     */
289
    protected $profileCompleted;
290
291
    /**
292
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\JuryMembers", mappedBy="user")
293
     */
294
    //protected $jurySubscriptions;
295
296
    /**
297
     * @var Group[]
298
     * @ORM\ManyToMany(targetEntity="Chamilo\CoreBundle\Entity\Group", inversedBy="users")
299
     * @ORM\JoinTable(
300
     *      name="fos_user_user_group",
301
     *      joinColumns={
302
     *          @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="cascade")
303
     *      },
304
     *      inverseJoinColumns={
305
     *          @ORM\JoinColumn(name="group_id", referencedColumnName="id")
306
     *      }
307
     * )
308
     */
309
    protected $groups;
310
311
    /**
312
     * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CurriculumItemRelUser", mappedBy="user").
313
     */
314
    protected $curriculumItems;
315
316
    /**
317
     * @ORM\OneToMany(
318
     *     targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelUser",
319
     *     mappedBy="user",
320
     *     cascade={"persist", "remove"},
321
     *     orphanRemoval=true
322
     * )
323
     */
324
    protected $portals;
325
326
    /**
327
     * @var ArrayCollection
328
     *
329
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Session", mappedBy="generalCoach")
330
     */
331
    protected $sessionAsGeneralCoach;
332
333
    /**
334
     * @ORM\OneToOne(
335
     *     targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", cascade={"remove"}, orphanRemoval=true
336
     * )
337
     * @ORM\JoinColumn(name="resource_node_id", referencedColumnName="id", onDelete="CASCADE")
338
     */
339
    protected $resourceNode;
340
341
    /**
342
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", mappedBy="creator")
343
     */
344
    protected $resourceNodes;
345
346
    /**
347
     * @ORM\OneToMany(
348
     *     targetEntity="Chamilo\CoreBundle\Entity\SessionRelCourseRelUser",
349
     *     mappedBy="user",
350
     *     cascade={"persist"},
351
     *     orphanRemoval=true
352
     * )
353
     */
354
    protected $sessionCourseSubscriptions;
355
356
    /**
357
     * @ORM\OneToMany(
358
     *     targetEntity="Chamilo\CoreBundle\Entity\SkillRelUser",
359
     *     mappedBy="user",
360
     *     cascade={"persist", "remove"},
361
     *     orphanRemoval=true
362
     * )
363
     */
364
    protected $achievedSkills;
365
366
    /**
367
     * @ORM\OneToMany(
368
     *     targetEntity="Chamilo\CoreBundle\Entity\SkillRelUserComment",
369
     *     mappedBy="feedbackGiver",
370
     *     cascade={"persist", "remove"},
371
     *     orphanRemoval=true
372
     * )
373
     */
374
    protected $commentedUserSkills;
375
376
    /**
377
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\GradebookCategory", mappedBy="user")
378
     */
379
    protected $gradeBookCategories;
380
381
    /**
382
     * @ORM\OneToMany(
383
     *     targetEntity="Chamilo\CoreBundle\Entity\SessionRelUser",
384
     *     mappedBy="user",
385
     *     cascade={"persist", "remove"},
386
     *     orphanRemoval=true
387
     * )
388
     */
389
    protected $sessions;
390
391
    /**
392
     * @var Collection
393
     *
394
     * @ORM\OneToMany(
395
     *     targetEntity="Chamilo\CourseBundle\Entity\CGroupRelUser",
396
     *     mappedBy="user",
397
     *     cascade={"persist", "remove"},
398
     *     orphanRemoval=true
399
     * )
400
     */
401
    protected $courseGroupsAsMember;
402
403
    /**
404
     * @var Collection
405
     *
406
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CGroupRelTutor", mappedBy="user", orphanRemoval=true)
407
     */
408
    protected $courseGroupsAsTutor;
409
410
    /**
411
     * @var string
412
     *
413
     * @ORM\Column(name="auth_source", type="string", length=50, nullable=true, unique=false)
414
     */
415
    protected $authSource;
416
417
    /**
418
     * @var int
419
     *
420
     * @ORM\Column(name="status", type="integer", nullable=false)
421
     */
422
    protected $status;
423
424
    /**
425
     * @var string
426
     *
427
     * @ORM\Column(name="official_code", type="string", length=40, nullable=true, unique=false)
428
     */
429
    protected $officialCode;
430
431
    /**
432
     * @var string
433
     *
434
     * @ORM\Column(name="picture_uri", type="string", length=250, nullable=true, unique=false)
435
     */
436
    protected $pictureUri;
437
438
    /**
439
     * @var int
440
     *
441
     * @ORM\Column(name="creator_id", type="integer", nullable=true, unique=false)
442
     */
443
    protected $creatorId;
444
445
    /**
446
     * @var string
447
     *
448
     * @ORM\Column(name="competences", type="text", nullable=true, unique=false)
449
     */
450
    protected $competences;
451
452
    /**
453
     * @var string
454
     *
455
     * @ORM\Column(name="diplomas", type="text", nullable=true, unique=false)
456
     */
457
    protected $diplomas;
458
459
    /**
460
     * @var string
461
     *
462
     * @ORM\Column(name="openarea", type="text", nullable=true, unique=false)
463
     */
464
    protected $openarea;
465
466
    /**
467
     * @var string
468
     *
469
     * @ORM\Column(name="teach", type="text", nullable=true, unique=false)
470
     */
471
    protected $teach;
472
473
    /**
474
     * @var string
475
     *
476
     * @ORM\Column(name="productions", type="string", length=250, nullable=true, unique=false)
477
     */
478
    protected $productions;
479
480
    /**
481
     * @var string
482
     *
483
     * @ORM\Column(name="language", type="string", length=40, nullable=true, unique=false)
484
     */
485
    protected $language;
486
487
    /**
488
     * @var \DateTime
489
     *
490
     * @ORM\Column(name="registration_date", type="datetime", nullable=false, unique=false)
491
     */
492
    protected $registrationDate;
493
494
    /**
495
     * @var \DateTime
496
     *
497
     * @ORM\Column(name="expiration_date", type="datetime", nullable=true, unique=false)
498
     */
499
    protected $expirationDate;
500
501
    /**
502
     * @var bool
503
     *
504
     * @ORM\Column(name="active", type="boolean", nullable=false, unique=false)
505
     */
506
    protected $active;
507
508
    /**
509
     * @var string
510
     *
511
     * @ORM\Column(name="openid", type="string", length=255, nullable=true, unique=false)
512
     */
513
    protected $openid;
514
515
    /**
516
     * @var string
517
     *
518
     * @ORM\Column(name="theme", type="string", length=255, nullable=true, unique=false)
519
     */
520
    protected $theme;
521
522
    /**
523
     * @var int
524
     *
525
     * @ORM\Column(name="hr_dept_id", type="smallint", nullable=true, unique=false)
526
     */
527
    protected $hrDeptId;
528
529
    /**
530
     * @var ArrayCollection
531
     *
532
     * @ORM\OneToMany(
533
     *     targetEntity="Chamilo\CoreBundle\Entity\Message",
534
     *     mappedBy="userSender",
535
     *     cascade={"persist", "remove"},
536
     *     orphanRemoval=true
537
     * )
538
     */
539
    protected $sentMessages;
540
541
    /**
542
     * @var ArrayCollection
543
     *
544
     * @ORM\OneToMany(
545
     *     targetEntity="Chamilo\CoreBundle\Entity\Message",
546
     *     mappedBy="userReceiver",
547
     *     cascade={"persist", "remove"},
548
     *     orphanRemoval=true
549
     * )
550
     */
551
    protected $receivedMessages;
552
553
    /**
554
     * @var \DateTime
555
     * @ORM\Column(name="created_at", type="datetime", nullable=true, unique=false)
556
     */
557
    protected $createdAt;
558
559
    /**
560
     * @var \DateTime
561
     * @ORM\Column(name="updated_at", type="datetime", nullable=true, unique=false)
562
     */
563
    protected $updatedAt;
564
565
    /**
566
     * Constructor.
567
     */
568
    public function __construct()
569
    {
570
        $this->status = self::STUDENT;
571
        $this->salt = sha1(uniqid(null, true));
572
        $this->active = true;
573
        $this->registrationDate = new \DateTime();
574
        $this->authSource = 'platform';
575
        $this->courses = new ArrayCollection();
576
        //$this->items = new ArrayCollection();
577
        $this->classes = new ArrayCollection();
578
        $this->curriculumItems = new ArrayCollection();
579
        $this->portals = new ArrayCollection();
580
        $this->dropBoxSentFiles = new ArrayCollection();
581
        $this->dropBoxReceivedFiles = new ArrayCollection();
582
        $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...
583
        //$this->extraFields = new ArrayCollection();
584
        //$this->userId = 0;
585
        //$this->createdAt = new \DateTime();
586
        //$this->updatedAt = new \DateTime();
587
588
        $this->enabled = false;
589
        $this->locked = false;
590
        $this->expired = false;
591
        $this->roles = [];
592
        $this->credentialsExpired = false;
593
594
        $this->courseGroupsAsMember = new ArrayCollection();
595
        $this->courseGroupsAsTutor = new ArrayCollection();
596
    }
597
598
    /**
599
     * @return string
600
     */
601
    public function __toString()
602
    {
603
        return $this->username;
604
    }
605
606
    /**
607
     * @return $this
608
     */
609
    public function setResourceNode(ResourceNode $resourceNode): self
610
    {
611
        $this->resourceNode = $resourceNode;
612
613
        return $this;
614
    }
615
616
    public function getResourceNode(): ResourceNode
617
    {
618
        return $this->resourceNode;
619
    }
620
621
    /**
622
     * @return ArrayCollection|ResourceNode[]
623
     */
624
    public function getResourceNodes()
625
    {
626
        return $this->resourceNodes;
627
    }
628
629
    /**
630
     * @return User
631
     */
632
    public function setResourceNodes($resourceNodes)
633
    {
634
        $this->resourceNodes = $resourceNodes;
635
636
        return $this;
637
    }
638
639
    /**
640
     * Updates the id with the user_id.
641
     *
642
     * @ORM\PostPersist()
643
     */
644
    public function postPersist(LifecycleEventArgs $args)
645
    {
646
        $user = $args->getEntity();
647
        $this->setUserId($user->getId());
648
    }
649
650
    /**
651
     * @param int $userId
652
     */
653
    public function setId($userId)
654
    {
655
        $this->id = $userId;
656
    }
657
658
    /**
659
     * @param int $userId
660
     */
661
    public function setUserId($userId)
662
    {
663
        if (!empty($userId)) {
664
            $this->userId = $userId;
665
        }
666
    }
667
668
    /**
669
     * @return int
670
     */
671
    public function getId()
672
    {
673
        return $this->id;
674
    }
675
676
    /**
677
     * @return ArrayCollection
678
     */
679
    public function getDropBoxSentFiles()
680
    {
681
        return $this->dropBoxSentFiles;
682
    }
683
684
    /**
685
     * @return ArrayCollection
686
     */
687
    public function getDropBoxReceivedFiles()
688
    {
689
        return $this->dropBoxReceivedFiles;
690
    }
691
692
    /**
693
     * @param ArrayCollection $value
694
     */
695
    public function setDropBoxSentFiles($value)
696
    {
697
        $this->dropBoxSentFiles = $value;
698
    }
699
700
    /**
701
     * @param ArrayCollection $value
702
     */
703
    public function setDropBoxReceivedFiles($value)
704
    {
705
        $this->dropBoxReceivedFiles = $value;
706
    }
707
708
    /**
709
     * @param ArrayCollection $courses
710
     */
711
    public function setCourses($courses)
712
    {
713
        $this->courses = $courses;
714
    }
715
716
    public function getCourses(): Collection
717
    {
718
        return $this->courses;
719
    }
720
721
    /**
722
     * @return array
723
     */
724
    public static function getPasswordConstraints()
725
    {
726
        return
727
            [
728
                new Assert\Length(['min' => 5]),
729
                // Alpha numeric + "_" or "-"
730
                new Assert\Regex(
731
                    [
732
                        'pattern' => '/^[a-z\-_0-9]+$/i',
733
                        'htmlPattern' => '/^[a-z\-_0-9]+$/i', ]
734
                ),
735
                // Min 3 letters - not needed
736
                /*new Assert\Regex(array(
737
                    'pattern' => '/[a-z]{3}/i',
738
                    'htmlPattern' => '/[a-z]{3}/i')
739
                ),*/
740
                // Min 2 numbers
741
                new Assert\Regex(
742
                    [
743
                        'pattern' => '/[0-9]{2}/',
744
                        'htmlPattern' => '/[0-9]{2}/', ]
745
                ),
746
            ]
747
            ;
748
    }
749
750
    public static function loadValidatorMetadata(ClassMetadata $metadata)
751
    {
752
        //$metadata->addPropertyConstraint('firstname', new Assert\NotBlank());
753
        //$metadata->addPropertyConstraint('lastname', new Assert\NotBlank());
754
        //$metadata->addPropertyConstraint('email', new Assert\Email());
755
        /*
756
        $metadata->addPropertyConstraint('password',
757
            new Assert\Collection(self::getPasswordConstraints())
758
        );*/
759
760
        /*$metadata->addConstraint(new UniqueEntity(array(
761
            'fields'  => 'username',
762
            'message' => 'This value is already used.',
763
        )));*/
764
765
        /*$metadata->addPropertyConstraint(
766
            'username',
767
            new Assert\Length(array(
768
                'min'        => 2,
769
                'max'        => 50,
770
                '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.',
771
                '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.',
772
            ))
773
        );*/
774
    }
775
776
    /**
777
     * @return ArrayCollection
778
     */
779
    public function getPortals()
780
    {
781
        return $this->portals;
782
    }
783
784
    /**
785
     * @param $portal
786
     */
787
    public function setPortal($portal)
788
    {
789
        $this->portals->add($portal);
790
    }
791
792
    /**
793
     * @param $value
794
     * @param (mixed|string|string[])[] $value
795
     */
796
    public function setPortals(array $value)
797
    {
798
        $this->portals = $value;
799
    }
800
801
    /**
802
     * @return ArrayCollection
803
     */
804
    public function getCurriculumItems()
805
    {
806
        return $this->curriculumItems;
807
    }
808
809
    /**
810
     * @param $items
811
     *
812
     * @return $this
813
     */
814
    public function setCurriculumItems(array $items)
815
    {
816
        $this->curriculumItems = $items;
817
818
        return $this;
819
    }
820
821
    /**
822
     * @return bool
823
     */
824
    public function getIsActive()
825
    {
826
        return 1 == $this->active;
827
    }
828
829
    /**
830
     * @return bool
831
     */
832
    public function isActive()
833
    {
834
        return $this->getIsActive();
835
    }
836
837
    public function isEnabled()
838
    {
839
        return 1 == $this->getActive();
840
    }
841
842
    /**
843
     * Set salt.
844
     *
845
     * @param string $salt
846
     *
847
     * @return User
848
     */
849
    public function setSalt($salt)
850
    {
851
        $this->salt = $salt;
852
853
        return $this;
854
    }
855
856
    /**
857
     * Get salt.
858
     *
859
     * @return string
860
     */
861
    public function getSalt()
862
    {
863
        return $this->salt;
864
    }
865
866
    /**
867
     * @param ArrayCollection $classes
868
     *
869
     * @return $this
870
     */
871
    public function setClasses($classes)
872
    {
873
        $this->classes = $classes;
874
875
        return $this;
876
    }
877
878
    /**
879
     * @return ArrayCollection
880
     */
881
    public function getClasses()
882
    {
883
        return $this->classes;
884
    }
885
886
    public function getLps()
887
    {
888
        //return $this->lps;
889
        /*$criteria = Criteria::create()
890
            ->where(Criteria::expr()->eq("id", "666"))
891
            //->orderBy(array("username" => "ASC"))
892
            //->setFirstResult(0)
893
            //->setMaxResults(20)
894
        ;
895
        $lps = $this->lps->matching($criteria);*/
896
        /*return $this->lps->filter(
897
            function($entry) use ($idsToFilter) {
898
                return $entry->getId() == 1;
899
        });*/
900
    }
901
902
    /**
903
     * Returns the list of classes for the user.
904
     *
905
     * @return string
906
     */
907
    public function getCompleteNameWithClasses()
908
    {
909
        $classSubscription = $this->getClasses();
910
        $classList = [];
911
        /** @var UsergroupRelUser $subscription */
912
        foreach ($classSubscription as $subscription) {
913
            $class = $subscription->getUsergroup();
914
            $classList[] = $class->getName();
915
        }
916
        $classString = !empty($classList) ? ' ['.implode(', ', $classList).']' : null;
917
918
        return \UserManager::formatUserFullName($this).$classString;
919
    }
920
921
    /**
922
     * Get userId.
923
     *
924
     * @return int
925
     */
926
    public function getUserId()
927
    {
928
        return $this->userId;
929
    }
930
931
    /**
932
     * Set lastname.
933
     *
934
     *
935
     * @return User
936
     */
937
    public function setLastname(string $lastname): self
938
    {
939
        $this->lastname = $lastname;
940
941
        return $this;
942
    }
943
944
    /**
945
     * Set firstname.
946
     *
947
     *
948
     * @return User
949
     */
950
    public function setFirstname(string $firstname): self
951
    {
952
        $this->firstname = $firstname;
953
954
        return $this;
955
    }
956
957
    public function getPassword()
958
    {
959
        return $this->password;
960
    }
961
962
    public function setPassword(string $password): self
963
    {
964
        $this->password = $password;
965
966
        return $this;
967
    }
968
969
    /**
970
     * Set authSource.
971
     *
972
     * @param string $authSource
973
     *
974
     * @return User
975
     */
976
    public function setAuthSource($authSource)
977
    {
978
        $this->authSource = $authSource;
979
980
        return $this;
981
    }
982
983
    /**
984
     * Get authSource.
985
     *
986
     * @return string
987
     */
988
    public function getAuthSource()
989
    {
990
        return $this->authSource;
991
    }
992
993
    /**
994
     * Set email.
995
     *
996
     * @param string $email
997
     *
998
     * @return User
999
     */
1000
    public function setEmail($email)
1001
    {
1002
        $this->email = $email;
1003
1004
        return $this;
1005
    }
1006
1007
    /**
1008
     * Get email.
1009
     *
1010
     * @return string
1011
     */
1012
    public function getEmail()
1013
    {
1014
        return $this->email;
1015
    }
1016
1017
    /**
1018
     * Set status.
1019
     *
1020
     * @param int $status
1021
     *
1022
     * @return User
1023
     */
1024
    public function setStatus($status)
1025
    {
1026
        $this->status = $status;
1027
1028
        return $this;
1029
    }
1030
1031
    /**
1032
     * Get status.
1033
     *
1034
     * @return int
1035
     */
1036
    public function getStatus()
1037
    {
1038
        return $this->status;
1039
    }
1040
1041
    /**
1042
     * Set officialCode.
1043
     *
1044
     * @param string $officialCode
1045
     *
1046
     * @return User
1047
     */
1048
    public function setOfficialCode($officialCode)
1049
    {
1050
        $this->officialCode = $officialCode;
1051
1052
        return $this;
1053
    }
1054
1055
    /**
1056
     * Get officialCode.
1057
     *
1058
     * @return string
1059
     */
1060
    public function getOfficialCode()
1061
    {
1062
        return $this->officialCode;
1063
    }
1064
1065
    /**
1066
     * Set phone.
1067
     *
1068
     * @param string $phone
1069
     *
1070
     * @return User
1071
     */
1072
    public function setPhone($phone)
1073
    {
1074
        $this->phone = $phone;
1075
1076
        return $this;
1077
    }
1078
1079
    /**
1080
     * Get phone.
1081
     *
1082
     * @return string
1083
     */
1084
    public function getPhone()
1085
    {
1086
        return $this->phone;
1087
    }
1088
1089
    /**
1090
     * Set address.
1091
     *
1092
     * @param string $address
1093
     *
1094
     * @return User
1095
     */
1096
    public function setAddress($address)
1097
    {
1098
        $this->address = $address;
1099
1100
        return $this;
1101
    }
1102
1103
    /**
1104
     * Get address.
1105
     *
1106
     * @return string
1107
     */
1108
    public function getAddress()
1109
    {
1110
        return $this->address;
1111
    }
1112
1113
    /**
1114
     * Set creatorId.
1115
     *
1116
     * @param int $creatorId
1117
     *
1118
     * @return User
1119
     */
1120
    public function setCreatorId($creatorId)
1121
    {
1122
        $this->creatorId = $creatorId;
1123
1124
        return $this;
1125
    }
1126
1127
    /**
1128
     * Get creatorId.
1129
     *
1130
     * @return int
1131
     */
1132
    public function getCreatorId()
1133
    {
1134
        return $this->creatorId;
1135
    }
1136
1137
    /**
1138
     * Set competences.
1139
     *
1140
     * @param string $competences
1141
     *
1142
     * @return User
1143
     */
1144
    public function setCompetences($competences)
1145
    {
1146
        $this->competences = $competences;
1147
1148
        return $this;
1149
    }
1150
1151
    /**
1152
     * Get competences.
1153
     *
1154
     * @return string
1155
     */
1156
    public function getCompetences()
1157
    {
1158
        return $this->competences;
1159
    }
1160
1161
    /**
1162
     * Set diplomas.
1163
     *
1164
     * @param string $diplomas
1165
     *
1166
     * @return User
1167
     */
1168
    public function setDiplomas($diplomas)
1169
    {
1170
        $this->diplomas = $diplomas;
1171
1172
        return $this;
1173
    }
1174
1175
    /**
1176
     * Get diplomas.
1177
     *
1178
     * @return string
1179
     */
1180
    public function getDiplomas()
1181
    {
1182
        return $this->diplomas;
1183
    }
1184
1185
    /**
1186
     * Set openarea.
1187
     *
1188
     * @param string $openarea
1189
     *
1190
     * @return User
1191
     */
1192
    public function setOpenarea($openarea)
1193
    {
1194
        $this->openarea = $openarea;
1195
1196
        return $this;
1197
    }
1198
1199
    /**
1200
     * Get openarea.
1201
     *
1202
     * @return string
1203
     */
1204
    public function getOpenarea()
1205
    {
1206
        return $this->openarea;
1207
    }
1208
1209
    /**
1210
     * Set teach.
1211
     *
1212
     * @param string $teach
1213
     *
1214
     * @return User
1215
     */
1216
    public function setTeach($teach)
1217
    {
1218
        $this->teach = $teach;
1219
1220
        return $this;
1221
    }
1222
1223
    /**
1224
     * Get teach.
1225
     *
1226
     * @return string
1227
     */
1228
    public function getTeach()
1229
    {
1230
        return $this->teach;
1231
    }
1232
1233
    /**
1234
     * Set productions.
1235
     *
1236
     * @param string $productions
1237
     *
1238
     * @return User
1239
     */
1240
    public function setProductions($productions)
1241
    {
1242
        $this->productions = $productions;
1243
1244
        return $this;
1245
    }
1246
1247
    /**
1248
     * Get productions.
1249
     *
1250
     * @return string
1251
     */
1252
    public function getProductions()
1253
    {
1254
        return $this->productions;
1255
    }
1256
1257
    /**
1258
     * Set language.
1259
     *
1260
     * @param string $language
1261
     *
1262
     * @return User
1263
     */
1264
    public function setLanguage($language)
1265
    {
1266
        $this->language = $language;
1267
1268
        return $this;
1269
    }
1270
1271
    /**
1272
     * Get language.
1273
     *
1274
     * @return string
1275
     */
1276
    public function getLanguage()
1277
    {
1278
        return $this->language;
1279
    }
1280
1281
    /**
1282
     * Set registrationDate.
1283
     *
1284
     * @param \DateTime $registrationDate
1285
     *
1286
     * @return User
1287
     */
1288
    public function setRegistrationDate($registrationDate)
1289
    {
1290
        $this->registrationDate = $registrationDate;
1291
1292
        return $this;
1293
    }
1294
1295
    /**
1296
     * Get registrationDate.
1297
     *
1298
     * @return \DateTime
1299
     */
1300
    public function getRegistrationDate()
1301
    {
1302
        return $this->registrationDate;
1303
    }
1304
1305
    /**
1306
     * Set expirationDate.
1307
     *
1308
     * @param \DateTime $expirationDate
1309
     *
1310
     * @return User
1311
     */
1312
    public function setExpirationDate($expirationDate)
1313
    {
1314
        $this->expirationDate = $expirationDate;
1315
1316
        return $this;
1317
    }
1318
1319
    /**
1320
     * Get expirationDate.
1321
     *
1322
     * @return \DateTime
1323
     */
1324
    public function getExpirationDate()
1325
    {
1326
        return $this->expirationDate;
1327
    }
1328
1329
    /**
1330
     * Set active.
1331
     *
1332
     * @param bool $active
1333
     *
1334
     * @return User
1335
     */
1336
    public function setActive($active)
1337
    {
1338
        $this->active = $active;
1339
1340
        return $this;
1341
    }
1342
1343
    /**
1344
     * Get active.
1345
     *
1346
     * @return bool
1347
     */
1348
    public function getActive()
1349
    {
1350
        return $this->active;
1351
    }
1352
1353
    /**
1354
     * Set openid.
1355
     *
1356
     * @param string $openid
1357
     *
1358
     * @return User
1359
     */
1360
    public function setOpenid($openid)
1361
    {
1362
        $this->openid = $openid;
1363
1364
        return $this;
1365
    }
1366
1367
    /**
1368
     * Get openid.
1369
     *
1370
     * @return string
1371
     */
1372
    public function getOpenid()
1373
    {
1374
        return $this->openid;
1375
    }
1376
1377
    /**
1378
     * Set theme.
1379
     *
1380
     * @param string $theme
1381
     *
1382
     * @return User
1383
     */
1384
    public function setTheme($theme)
1385
    {
1386
        $this->theme = $theme;
1387
1388
        return $this;
1389
    }
1390
1391
    /**
1392
     * Get theme.
1393
     *
1394
     * @return string
1395
     */
1396
    public function getTheme()
1397
    {
1398
        return $this->theme;
1399
    }
1400
1401
    /**
1402
     * Set hrDeptId.
1403
     *
1404
     * @param int $hrDeptId
1405
     *
1406
     * @return User
1407
     */
1408
    public function setHrDeptId($hrDeptId)
1409
    {
1410
        $this->hrDeptId = $hrDeptId;
1411
1412
        return $this;
1413
    }
1414
1415
    /**
1416
     * Get hrDeptId.
1417
     *
1418
     * @return int
1419
     */
1420
    public function getHrDeptId()
1421
    {
1422
        return $this->hrDeptId;
1423
    }
1424
1425
    /**
1426
     * @return \DateTime
1427
     */
1428
    public function getMemberSince()
1429
    {
1430
        return $this->registrationDate;
1431
    }
1432
1433
    /**
1434
     * @return bool
1435
     */
1436
    public function isOnline()
1437
    {
1438
        return false;
1439
    }
1440
1441
    /**
1442
     * @return int
1443
     */
1444
    public function getIdentifier()
1445
    {
1446
        return $this->getId();
1447
    }
1448
1449
    /**
1450
     * @return string
1451
     */
1452
    public function getSlug()
1453
    {
1454
        return $this->getUsername();
1455
    }
1456
1457
    /**
1458
     * @param string $slug
1459
     *
1460
     * @return User
1461
     */
1462
    public function setSlug($slug)
1463
    {
1464
        return $this->setUsername($slug);
1465
    }
1466
1467
    /**
1468
     * Set lastLogin.
1469
     *
1470
     * @param \DateTime $lastLogin
1471
     *
1472
     * @return User
1473
     */
1474
    public function setLastLogin(\DateTime $lastLogin = null)
1475
    {
1476
        $this->lastLogin = $lastLogin;
1477
1478
        return $this;
1479
    }
1480
1481
    /**
1482
     * Get lastLogin.
1483
     *
1484
     * @return \DateTime
1485
     */
1486
    public function getLastLogin()
1487
    {
1488
        return $this->lastLogin;
1489
    }
1490
1491
    /**
1492
     * Get sessionCourseSubscription.
1493
     *
1494
     * @return ArrayCollection
1495
     */
1496
    public function getSessionCourseSubscriptions()
1497
    {
1498
        return $this->sessionCourseSubscriptions;
1499
    }
1500
1501
    /**
1502
     * @param $value
1503
     * @param string[][] $value
1504
     *
1505
     * @return $this
1506
     */
1507
    public function setSessionCourseSubscriptions(array $value)
1508
    {
1509
        $this->sessionCourseSubscriptions = $value;
1510
1511
        return $this;
1512
    }
1513
1514
    /**
1515
     * @return string
1516
     */
1517
    public function getConfirmationToken()
1518
    {
1519
        return $this->confirmationToken;
1520
    }
1521
1522
    /**
1523
     * @param string $confirmationToken
1524
     *
1525
     * @return User
1526
     */
1527
    public function setConfirmationToken($confirmationToken)
1528
    {
1529
        $this->confirmationToken = $confirmationToken;
1530
1531
        return $this;
1532
    }
1533
1534
    /**
1535
     * @return \DateTime
1536
     */
1537
    public function getPasswordRequestedAt()
1538
    {
1539
        return $this->passwordRequestedAt;
1540
    }
1541
1542
    /**
1543
     * @return bool
1544
     */
1545
    /*public function isPasswordRequestNonExpired($ttl)
1546
    {
1547
        return $this->getPasswordRequestedAt() instanceof \DateTime &&
1548
            $this->getPasswordRequestedAt()->getTimestamp() + $ttl > time();
1549
    }*/
1550
1551
    public function getUsername(): string
1552
    {
1553
        return (string) $this->username;
1554
    }
1555
1556
    public function getPlainPassword(): ?string
1557
    {
1558
        return $this->plainPassword;
1559
    }
1560
1561
    public function setPlainPassword(string $password): void
1562
    {
1563
        $this->plainPassword = $password;
1564
1565
        // forces the object to look "dirty" to Doctrine. Avoids
1566
        // Doctrine *not* saving this entity, if only plainPassword changes
1567
        $this->password = null;
1568
    }
1569
1570
    /**
1571
     * Returns the expiration date.
1572
     *
1573
     * @return \DateTime|null
1574
     */
1575
    public function getExpiresAt()
1576
    {
1577
        return $this->expiresAt;
1578
    }
1579
1580
    /**
1581
     * Returns the credentials expiration date.
1582
     *
1583
     * @return \DateTime
1584
     */
1585
    public function getCredentialsExpireAt()
1586
    {
1587
        return $this->credentialsExpireAt;
1588
    }
1589
1590
    /**
1591
     * Sets the credentials expiration date.
1592
     *
1593
     * @return User
1594
     */
1595
    public function setCredentialsExpireAt(\DateTime $date = null)
1596
    {
1597
        $this->credentialsExpireAt = $date;
1598
1599
        return $this;
1600
    }
1601
1602
    public function addGroup($group)
1603
    {
1604
        if (!$this->getGroups()->contains($group)) {
1605
            $this->getGroups()->add($group);
1606
        }
1607
1608
        return $this;
1609
    }
1610
1611
    /**
1612
     * Sets the user groups.
1613
     *
1614
     * @param array $groups
1615
     *
1616
     * @return User
1617
     */
1618
    public function setGroups($groups)
1619
    {
1620
        foreach ($groups as $group) {
1621
            $this->addGroup($group);
1622
        }
1623
1624
        return $this;
1625
    }
1626
1627
    /**
1628
     * @return string
1629
     */
1630
    public function getFullname()
1631
    {
1632
        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...
1633
    }
1634
1635
    public function getGroups()
1636
    {
1637
        return $this->groups;
1638
    }
1639
1640
    /**
1641
     * Returns the user roles.
1642
     *
1643
     * @return array The roles
1644
     */
1645
    public function getRoles()
1646
    {
1647
        $roles = $this->roles;
1648
1649
        foreach ($this->getGroups() as $group) {
1650
            $roles = array_merge($roles, $group->getRoles());
1651
        }
1652
1653
        // we need to make sure to have at least one role
1654
        $roles[] = 'ROLE_USER';
1655
1656
        return array_unique($roles);
1657
    }
1658
1659
    public function isAccountNonExpired()
1660
    {
1661
        /*if (true === $this->expired) {
1662
            return false;
1663
        }
1664
1665
        if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
1666
            return false;
1667
        }*/
1668
1669
        return true;
1670
    }
1671
1672
    public function isAccountNonLocked()
1673
    {
1674
        return true;
1675
        //return !$this->locked;
1676
    }
1677
1678
    public function isCredentialsNonExpired()
1679
    {
1680
        /*if (true === $this->credentialsExpired) {
1681
            return false;
1682
        }
1683
1684
        if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
1685
            return false;
1686
        }*/
1687
1688
        return true;
1689
    }
1690
1691
    /**
1692
     * @return bool
1693
     */
1694
    public function getCredentialsExpired()
1695
    {
1696
        return $this->credentialsExpired;
1697
    }
1698
1699
    /**
1700
     * @param bool $boolean
1701
     *
1702
     * @return User
1703
     */
1704
    public function setCredentialsExpired($boolean)
1705
    {
1706
        $this->credentialsExpired = $boolean;
1707
1708
        return $this;
1709
    }
1710
1711
    /**
1712
     * @param $boolean
1713
     *
1714
     * @return $this|BaseUser
1715
     */
1716
    public function setEnabled($boolean)
1717
    {
1718
        $this->enabled = (bool) $boolean;
1719
1720
        return $this;
1721
    }
1722
1723
    /**
1724
     * @return bool
1725
     */
1726
    public function getExpired()
1727
    {
1728
        return $this->expired;
1729
    }
1730
1731
    /**
1732
     * Sets this user to expired.
1733
     *
1734
     * @param bool $boolean
1735
     *
1736
     * @return User
1737
     */
1738
    public function setExpired($boolean)
1739
    {
1740
        $this->expired = (bool) $boolean;
1741
1742
        return $this;
1743
    }
1744
1745
    /**
1746
     * @return User
1747
     */
1748
    public function setExpiresAt(\DateTime $date)
1749
    {
1750
        $this->expiresAt = $date;
1751
1752
        return $this;
1753
    }
1754
1755
    public function getLocked(): bool
1756
    {
1757
        return $this->locked;
1758
    }
1759
1760
    /**
1761
     * @param $boolean
1762
     *
1763
     * @return $this
1764
     */
1765
    public function setLocked($boolean)
1766
    {
1767
        $this->locked = $boolean;
1768
1769
        return $this;
1770
    }
1771
1772
    /**
1773
     * @return $this
1774
     */
1775
    public function setRoles(array $roles)
1776
    {
1777
        $this->roles = [];
1778
1779
        foreach ($roles as $role) {
1780
            $this->addRole($role);
1781
        }
1782
1783
        return $this;
1784
    }
1785
1786
    /**
1787
     * Get achievedSkills.
1788
     *
1789
     * @return ArrayCollection
1790
     */
1791
    public function getAchievedSkills()
1792
    {
1793
        return $this->achievedSkills;
1794
    }
1795
1796
    /**
1797
     * @param $value
1798
     * @param string[] $value
1799
     *
1800
     * @return $this
1801
     */
1802
    public function setAchievedSkills(array $value)
1803
    {
1804
        $this->achievedSkills = $value;
1805
1806
        return $this;
1807
    }
1808
1809
    /**
1810
     * Check if the user has the skill.
1811
     *
1812
     * @param Skill $skill The skill
1813
     *
1814
     * @return bool
1815
     */
1816
    public function hasSkill(Skill $skill)
1817
    {
1818
        $achievedSkills = $this->getAchievedSkills();
1819
1820
        foreach ($achievedSkills as $userSkill) {
1821
            if ($userSkill->getSkill()->getId() !== $skill->getId()) {
1822
                continue;
1823
            }
1824
1825
            return true;
1826
        }
1827
    }
1828
1829
    /**
1830
     * @return bool
1831
     */
1832
    public function isProfileCompleted()
1833
    {
1834
        return $this->profileCompleted;
1835
    }
1836
1837
    /**
1838
     * @return User
1839
     */
1840
    public function setProfileCompleted($profileCompleted)
1841
    {
1842
        $this->profileCompleted = $profileCompleted;
1843
1844
        return $this;
1845
    }
1846
1847
    /**
1848
     * Sets the AccessUrl for the current user in memory.
1849
     *
1850
     * @return $this
1851
     */
1852
    public function setCurrentUrl(AccessUrl $url)
1853
    {
1854
        $urlList = $this->getPortals();
1855
        /** @var AccessUrlRelUser $item */
1856
        foreach ($urlList as $item) {
1857
            if ($item->getUrl()->getId() === $url->getId()) {
1858
                $this->currentUrl = $url;
1859
1860
                break;
1861
            }
1862
        }
1863
1864
        return $this;
1865
    }
1866
1867
    /**
1868
     * @return AccessUrl
1869
     */
1870
    public function getCurrentUrl()
1871
    {
1872
        return $this->currentUrl;
1873
    }
1874
1875
    /**
1876
     * Get sessionAsGeneralCoach.
1877
     *
1878
     * @return ArrayCollection
1879
     */
1880
    public function getSessionAsGeneralCoach()
1881
    {
1882
        return $this->sessionAsGeneralCoach;
1883
    }
1884
1885
    /**
1886
     * Get sessionAsGeneralCoach.
1887
     *
1888
     * @param ArrayCollection $value
1889
     *
1890
     * @return $this
1891
     */
1892
    public function setSessionAsGeneralCoach($value)
1893
    {
1894
        $this->sessionAsGeneralCoach = $value;
1895
1896
        return $this;
1897
    }
1898
1899
    public function getCommentedUserSkills()
1900
    {
1901
        return $this->commentedUserSkills;
1902
    }
1903
1904
    /**
1905
     * @return User
1906
     */
1907
    public function setCommentedUserSkills(array $commentedUserSkills)
1908
    {
1909
        $this->commentedUserSkills = $commentedUserSkills;
1910
1911
        return $this;
1912
    }
1913
1914
    /**
1915
     * @return bool
1916
     */
1917
    public function isEqualTo(UserInterface $user)
1918
    {
1919
        if ($this->password !== $user->getPassword()) {
1920
            return false;
1921
        }
1922
1923
        if ($this->salt !== $user->getSalt()) {
1924
            return false;
1925
        }
1926
1927
        if ($this->username !== $user->getUsername()) {
1928
            return false;
1929
        }
1930
1931
        return true;
1932
    }
1933
1934
    /**
1935
     * Get sentMessages.
1936
     *
1937
     * @return ArrayCollection
1938
     */
1939
    public function getSentMessages()
1940
    {
1941
        return $this->sentMessages;
1942
    }
1943
1944
    /**
1945
     * Get receivedMessages.
1946
     *
1947
     * @return ArrayCollection
1948
     */
1949
    public function getReceivedMessages()
1950
    {
1951
        return $this->receivedMessages;
1952
    }
1953
1954
    /**
1955
     * @param int $lastId Optional. The ID of the last received message
1956
     */
1957
    public function getUnreadReceivedMessages($lastId = 0): ArrayCollection
1958
    {
1959
        $criteria = Criteria::create();
1960
        $criteria->where(
1961
            Criteria::expr()->eq('msgStatus', MESSAGE_STATUS_UNREAD)
1962
        );
1963
1964
        if ($lastId > 0) {
1965
            $criteria->andWhere(
1966
                Criteria::expr()->gt('id', (int) $lastId)
1967
            );
1968
        }
1969
1970
        $criteria->orderBy(['sendDate' => Criteria::DESC]);
1971
1972
        return $this->receivedMessages->matching($criteria);
1973
    }
1974
1975
    public function getCourseGroupsAsMember(): Collection
1976
    {
1977
        return $this->courseGroupsAsMember;
1978
    }
1979
1980
    public function getCourseGroupsAsTutor(): Collection
1981
    {
1982
        return $this->courseGroupsAsTutor;
1983
    }
1984
1985
    public function getCourseGroupsAsMemberFromCourse(Course $course): ArrayCollection
1986
    {
1987
        $criteria = Criteria::create();
1988
        $criteria->where(
1989
            Criteria::expr()->eq('cId', $course)
1990
        );
1991
1992
        return $this->courseGroupsAsMember->matching($criteria);
1993
    }
1994
1995
    public function getFirstname()
1996
    {
1997
    }
1998
1999
    public function getLastname()
2000
    {
2001
    }
2002
2003
    public function eraseCredentials()
2004
    {
2005
        $this->plainPassword = null;
2006
    }
2007
2008
    public function hasRole($role)
2009
    {
2010
        return in_array(strtoupper($role), $this->getRoles(), true);
2011
    }
2012
2013
    public function isSuperAdmin()
2014
    {
2015
        return $this->hasRole('ROLE_SUPER_ADMIN');
2016
    }
2017
2018
    public function isUser(UserInterface $user = null)
2019
    {
2020
        return null !== $user && $this->getId() === $user->getId();
2021
    }
2022
2023
    public function removeRole($role)
2024
    {
2025
        if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
2026
            unset($this->roles[$key]);
2027
            $this->roles = array_values($this->roles);
2028
        }
2029
2030
        return $this;
2031
    }
2032
2033
    public function getUsernameCanonical()
2034
    {
2035
        return $this->usernameCanonical;
2036
    }
2037
2038
    public function getEmailCanonical()
2039
    {
2040
        return $this->emailCanonical;
2041
    }
2042
2043
    /**
2044
     * @param string $timezone
2045
     *
2046
     * @return User
2047
     */
2048
    public function setTimezone($timezone)
2049
    {
2050
        $this->timezone = $timezone;
2051
2052
        return $this;
2053
    }
2054
2055
    /**
2056
     * @return string
2057
     */
2058
    public function getTimezone()
2059
    {
2060
        return $this->timezone;
2061
    }
2062
2063
    /**
2064
     * @param string $locale
2065
     *
2066
     * @return User
2067
     */
2068
    public function setLocale($locale)
2069
    {
2070
        $this->locale = $locale;
2071
2072
        return $this;
2073
    }
2074
2075
    /**
2076
     * @return string
2077
     */
2078
    public function getLocale()
2079
    {
2080
        return $this->locale;
2081
    }
2082
2083
    /**
2084
     * @return string
2085
     */
2086
    public function getApiToken()
2087
    {
2088
        return $this->apiToken;
2089
    }
2090
2091
    /**
2092
     * @param string $apiToken
2093
     *
2094
     * @return User
2095
     */
2096
    public function setApiToken($apiToken)
2097
    {
2098
        $this->apiToken = $apiToken;
2099
2100
        return $this;
2101
    }
2102
2103
    /**
2104
     * @return string
2105
     */
2106
    public function getWebsite(): string
2107
    {
2108
        return $this->website;
2109
    }
2110
2111
    /**
2112
     * @param string $website
2113
     *
2114
     * @return User
2115
     */
2116
    public function setWebsite(string $website): User
2117
    {
2118
        $this->website = $website;
2119
2120
        return $this;
2121
    }
2122
2123
    /**
2124
     * @return string
2125
     */
2126
    public function getBiography(): string
2127
    {
2128
        return $this->biography;
2129
    }
2130
2131
    /**
2132
     * @param string $biography
2133
     *
2134
     * @return User
2135
     */
2136
    public function setBiography(string $biography): User
2137
    {
2138
        $this->biography = $biography;
2139
2140
        return $this;
2141
    }
2142
2143
    public function getCourseGroupsAsTutorFromCourse(Course $course): ArrayCollection
2144
    {
2145
        $criteria = Criteria::create();
2146
        $criteria->where(
2147
            Criteria::expr()->eq('cId', $course->getId())
2148
        );
2149
2150
        return $this->courseGroupsAsTutor->matching($criteria);
2151
    }
2152
}
2153