Passed
Push — master ( a41561...55654e )
by Julito
12:02
created

User::setPictureUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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

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

1512
        $extraFieldValue->/** @scrutinizer ignore-call */ 
1513
                          setUser($this);

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...
1513
        $this->extraFields[] = $extraFieldValue;
1514
        //}
1515
1516
        return $this;
1517
    }
1518
1519
    /**
1520
     * {@inheritdoc}
1521
     */
1522
    public function removeExtraField(ExtraFieldValues $attribute)
1523
    {
1524
        //if ($this->hasExtraField($attribute)) {
1525
        //$this->extraFields->removeElement($attribute);
1526
        //$attribute->setUser($this);
1527
        //}
1528
1529
        return $this;
1530
    }
1531
1532
    /**
1533
     * {@inheritdoc}
1534
     */
1535
    /*public function hasExtraField($attribute)
1536
    {
1537
        if (!$this->extraFields) {
1538
            return false;
1539
        }
1540
        return $this->extraFields->contains($attribute);
1541
    }*/
1542
1543
    /**
1544
     * {@inheritdoc}
1545
     */
1546
    public function hasExtraFieldByName($attributeName)
1547
    {
1548
        foreach ($this->extraFields as $attribute) {
1549
            if ($attribute->getName() === $attributeName) {
1550
                return true;
1551
            }
1552
        }
1553
1554
        return false;
1555
    }
1556
1557
    /**
1558
     * {@inheritdoc}
1559
     */
1560
    public function getExtraFieldByName($attributeName)
1561
    {
1562
        foreach ($this->extraFields as $attribute) {
1563
            if ($attribute->getName() === $attributeName) {
1564
                return $attribute;
1565
            }
1566
        }
1567
1568
        return null;
1569
    }
1570
1571
    /**
1572
     * Get sessionCourseSubscription.
1573
     *
1574
     * @return ArrayCollection
1575
     */
1576
    public function getSessionCourseSubscriptions()
1577
    {
1578
        return $this->sessionCourseSubscriptions;
1579
    }
1580
1581
    public function setSessionCourseSubscriptions($value)
1582
    {
1583
        $this->sessionCourseSubscriptions = $value;
1584
1585
        return $this;
1586
    }
1587
1588
    /**
1589
     * @return string
1590
     */
1591
    public function getConfirmationToken()
1592
    {
1593
        return $this->confirmationToken;
1594
    }
1595
1596
    /**
1597
     * @param string $confirmationToken
1598
     *
1599
     * @return User
1600
     */
1601
    public function setConfirmationToken($confirmationToken)
1602
    {
1603
        $this->confirmationToken = $confirmationToken;
0 ignored issues
show
Bug Best Practice introduced by
The property confirmationToken does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1604
1605
        return $this;
1606
    }
1607
1608
    /**
1609
     * @return \DateTime
1610
     */
1611
    public function getPasswordRequestedAt()
1612
    {
1613
        return $this->passwordRequestedAt;
1614
    }
1615
1616
    /**
1617
     * @param int $ttl
1618
     *
1619
     * @return bool
1620
     */
1621
    /*public function isPasswordRequestNonExpired($ttl)
1622
    {
1623
        return $this->getPasswordRequestedAt() instanceof \DateTime &&
1624
            $this->getPasswordRequestedAt()->getTimestamp() + $ttl > time();
1625
    }*/
1626
1627
    public function getUsername()
1628
    {
1629
        return $this->username;
1630
    }
1631
1632
    /**
1633
     * Returns the expiration date.
1634
     *
1635
     * @return \DateTime|null
1636
     */
1637
    public function getExpiresAt()
1638
    {
1639
        return $this->expiresAt;
1640
    }
1641
1642
    /**
1643
     * Returns the credentials expiration date.
1644
     *
1645
     * @return \DateTime
1646
     */
1647
    public function getCredentialsExpireAt()
1648
    {
1649
        return $this->credentialsExpireAt;
1650
    }
1651
1652
    /**
1653
     * Sets the credentials expiration date.
1654
     *
1655
     * @param \DateTime|null $date
1656
     *
1657
     * @return User
1658
     */
1659
    public function setCredentialsExpireAt(\DateTime $date = null)
1660
    {
1661
        $this->credentialsExpireAt = $date;
1662
1663
        return $this;
1664
    }
1665
1666
    /**
1667
     * Sets the user groups.
1668
     *
1669
     * @param array $groups
1670
     *
1671
     * @return User
1672
     */
1673
    public function setGroups($groups)
1674
    {
1675
        foreach ($groups as $group) {
1676
            $this->addGroup($group);
1677
        }
1678
1679
        return $this;
1680
    }
1681
1682
    /**
1683
     * @return string
1684
     */
1685
    public function getFullname()
1686
    {
1687
        return sprintf('%s %s', $this->getFirstname(), $this->getLastname());
1688
    }
1689
1690
    /**
1691
     * Returns the user roles.
1692
     *
1693
     * @return array The roles
1694
     */
1695
    public function getRoles()
1696
    {
1697
        $roles = $this->roles;
1698
1699
        foreach ($this->getGroups() as $group) {
1700
            $roles = array_merge($roles, $group->getRoles());
1701
        }
1702
1703
        // we need to make sure to have at least one role
1704
        $roles[] = static::ROLE_DEFAULT;
1705
1706
        return array_unique($roles);
1707
    }
1708
1709
    public function isAccountNonExpired()
1710
    {
1711
        /*if (true === $this->expired) {
1712
            return false;
1713
        }
1714
1715
        if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
1716
            return false;
1717
        }*/
1718
1719
        return true;
1720
    }
1721
1722
    public function isAccountNonLocked()
1723
    {
1724
        return true;
1725
        //return !$this->locked;
1726
    }
1727
1728
    public function isCredentialsNonExpired()
1729
    {
1730
        /*if (true === $this->credentialsExpired) {
1731
            return false;
1732
        }
1733
1734
        if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
1735
            return false;
1736
        }*/
1737
1738
        return true;
1739
    }
1740
1741
    /**
1742
     * @return bool
1743
     */
1744
    public function getCredentialsExpired()
1745
    {
1746
        return $this->credentialsExpired;
1747
    }
1748
1749
    /**
1750
     * @param bool $boolean
1751
     *
1752
     * @return User
1753
     */
1754
    public function setCredentialsExpired($boolean)
1755
    {
1756
        $this->credentialsExpired = $boolean;
1757
1758
        return $this;
1759
    }
1760
1761
    /**
1762
     * @param $boolean
1763
     *
1764
     * @return $this|BaseUser
1765
     */
1766
    public function setEnabled($boolean)
1767
    {
1768
        $this->enabled = (bool) $boolean;
0 ignored issues
show
Bug Best Practice introduced by
The property enabled does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1769
1770
        return $this;
1771
    }
1772
1773
    /**
1774
     * @return bool
1775
     */
1776
    public function getExpired()
1777
    {
1778
        return $this->expired;
1779
    }
1780
1781
    /**
1782
     * Sets this user to expired.
1783
     *
1784
     * @param bool $boolean
1785
     *
1786
     * @return User
1787
     */
1788
    public function setExpired($boolean)
1789
    {
1790
        $this->expired = (bool) $boolean;
1791
1792
        return $this;
1793
    }
1794
1795
    /**
1796
     * @param \DateTime $date
1797
     *
1798
     * @return User
1799
     */
1800
    public function setExpiresAt(\DateTime $date)
1801
    {
1802
        $this->expiresAt = $date;
1803
1804
        return $this;
1805
    }
1806
1807
    /**
1808
     * @return bool
1809
     */
1810
    public function getLocked(): bool
1811
    {
1812
        return $this->locked;
1813
    }
1814
1815
    /**
1816
     * @param $boolean
1817
     *
1818
     * @return $this
1819
     */
1820
    public function setLocked($boolean)
1821
    {
1822
        $this->locked = $boolean;
1823
1824
        return $this;
1825
    }
1826
1827
    public function setRoles(array $roles)
1828
    {
1829
        $this->roles = [];
0 ignored issues
show
Bug Best Practice introduced by
The property roles does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1830
1831
        foreach ($roles as $role) {
1832
            $this->addRole($role);
1833
        }
1834
1835
        return $this;
1836
    }
1837
1838
    /**
1839
     * Get achievedSkills.
1840
     *
1841
     * @return ArrayCollection
1842
     */
1843
    public function getAchievedSkills()
1844
    {
1845
        return $this->achievedSkills;
1846
    }
1847
1848
    /**
1849
     * @param $value
1850
     *
1851
     * @return $this
1852
     */
1853
    public function setAchievedSkills($value)
1854
    {
1855
        $this->achievedSkills = $value;
1856
1857
        return $this;
1858
    }
1859
1860
    /**
1861
     * Check if the user has the skill.
1862
     *
1863
     * @param Skill $skill The skill
1864
     *
1865
     * @return bool
1866
     */
1867
    public function hasSkill(Skill $skill)
1868
    {
1869
        $achievedSkills = $this->getAchievedSkills();
1870
1871
        foreach ($achievedSkills as $userSkill) {
1872
            if ($userSkill->getSkill()->getId() !== $skill->getId()) {
1873
                continue;
1874
            }
1875
1876
            return true;
1877
        }
1878
    }
1879
1880
    /**
1881
     * @return bool
1882
     */
1883
    public function isProfileCompleted()
1884
    {
1885
        return $this->profileCompleted;
1886
    }
1887
1888
    /**
1889
     * @param mixed $profileCompleted
1890
     *
1891
     * @return User
1892
     */
1893
    public function setProfileCompleted($profileCompleted)
1894
    {
1895
        $this->profileCompleted = $profileCompleted;
1896
1897
        return $this;
1898
    }
1899
1900
    /**
1901
     * Sets the AccessUrl for the current user in memory.
1902
     *
1903
     * @param AccessUrl $url
1904
     *
1905
     * @return $this
1906
     */
1907
    public function setCurrentUrl(AccessUrl $url)
1908
    {
1909
        $urlList = $this->getPortals();
1910
        /** @var AccessUrlRelUser $item */
1911
        foreach ($urlList as $item) {
1912
            if ($item->getPortal()->getId() == $url->getId()) {
1913
                $this->currentUrl = $url;
1914
                break;
1915
            }
1916
        }
1917
1918
        return $this;
1919
    }
1920
1921
    /**
1922
     * @return AccessUrl
1923
     */
1924
    public function getCurrentUrl()
1925
    {
1926
        return $this->currentUrl;
1927
    }
1928
1929
    /**
1930
     * Get sessionAsGeneralCoach.
1931
     *
1932
     * @return ArrayCollection
1933
     */
1934
    public function getSessionAsGeneralCoach()
1935
    {
1936
        return $this->sessionAsGeneralCoach;
1937
    }
1938
1939
    /**
1940
     * Get sessionAsGeneralCoach.
1941
     *
1942
     * @param ArrayCollection $value
1943
     *
1944
     * @return $this
1945
     */
1946
    public function setSessionAsGeneralCoach($value)
1947
    {
1948
        $this->sessionAsGeneralCoach = $value;
1949
1950
        return $this;
1951
    }
1952
1953
    /**
1954
     * @return mixed
1955
     */
1956
    public function getCommentedUserSkills()
1957
    {
1958
        return $this->commentedUserSkills;
1959
    }
1960
1961
    /**
1962
     * @param mixed $commentedUserSkills
1963
     *
1964
     * @return User
1965
     */
1966
    public function setCommentedUserSkills($commentedUserSkills)
1967
    {
1968
        $this->commentedUserSkills = $commentedUserSkills;
1969
1970
        return $this;
1971
    }
1972
1973
    /**
1974
     * @param UserInterface $user
1975
     *
1976
     * @return bool
1977
     */
1978
    public function isEqualTo(UserInterface $user)
1979
    {
1980
        if ($this->password !== $user->getPassword()) {
1981
            return false;
1982
        }
1983
1984
        if ($this->salt !== $user->getSalt()) {
1985
            return false;
1986
        }
1987
1988
        if ($this->username !== $user->getUsername()) {
1989
            return false;
1990
        }
1991
1992
        return true;
1993
    }
1994
1995
    /**
1996
     * @return string
1997
     */
1998
    public function getPictureLegacy(): string
1999
    {
2000
        $id = $this->id;
2001
2002
        return 'users/'.substr((string) $id, 0, 1).'/'.$id.'/'.'small_'.$this->getPictureUri();
2003
    }
2004
2005
2006
}
2007