Completed
Push — master ( 815120...7a7e0c )
by Julito
46:08
created

User::setFacebookAccessToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
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\UsergroupRelUser;
11
use Chamilo\CoreBundle\Entity\Skill;
12
use Doctrine\Common\Collections\ArrayCollection;
13
use Doctrine\ORM\Event\LifecycleEventArgs;
14
use Doctrine\ORM\Mapping as ORM;
15
//use Sonata\UserBundle\Entity\BaseUser as BaseUser;
16
use Sonata\UserBundle\Model\User as BaseUser;
17
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
18
use Symfony\Component\HttpFoundation\File\File;
19
//use Symfony\Component\Security\Core\User\UserInterface;
20
use Symfony\Component\Validator\Constraints as Assert;
21
use Symfony\Component\Validator\Mapping\ClassMetadata;
22
use FOS\UserBundle\Model\UserInterface;
23
use FOS\UserBundle\Model\GroupInterface;
24
use Chamilo\ThemeBundle\Model\UserInterface as ThemeUser;
25
26
//use Chamilo\CoreBundle\Component\Auth;
27
//use FOS\MessageBundle\Model\ParticipantInterface;
28
//use Chamilo\ThemeBundle\Model\UserInterface as ThemeUser;
29
//use Vich\UploaderBundle\Mapping\Annotation as Vich;
30
//use Application\Sonata\MediaBundle\Entity\Media;
31
//use Chamilo\UserBundle\Model\UserInterface as UserInterfaceModel;
32
33
//use Sylius\Component\Attribute\Model\AttributeValueInterface as BaseAttributeValueInterface;
34
//use Sylius\Component\Variation\Model\OptionInterface as BaseOptionInterface;
35
//use Sylius\Component\Variation\Model\VariantInterface as BaseVariantInterface;
36
37
/**
38
 *
39
 * @ORM\HasLifecycleCallbacks
40
 * @ORM\Table(
41
 *  name="user",
42
 *  indexes={
43
 *      @ORM\Index(name="idx_user_uid", columns={"user_id"}),
44
 *      @ORM\Index(name="status", columns={"status"})
45
 *  }
46
 * )
47
 * @UniqueEntity("username")
48
 * @ORM\Entity(repositoryClass="Chamilo\UserBundle\Entity\Repository\UserRepository")
49
 *
50
 */
51
class User extends BaseUser implements ThemeUser
52
{
53
    const COURSE_MANAGER = 1;
54
    const TEACHER = 1;
55
    const SESSION_ADMIN = 3;
56
    const DRH = 4;
57
    const STUDENT = 5;
58
    const ANONYMOUS = 6;
59
60
    /**
61
     * @var integer
62
     *
63
     * @ORM\Column(name="id", type="integer")
64
     * @ORM\Id
65
     * @ORM\GeneratedValue(strategy="AUTO")
66
     */
67
    protected $id;
68
69
    /**
70
     * @var integer
71
     *
72
     * @ORM\Column(name="user_id", type="integer", nullable=true)
73
     */
74
    protected $userId;
75
76
    /**
77
     * @var string
78
     *
79
     * @ORM\Column(name="username", type="string", length=100, nullable=false, unique=true)
80
     */
81
    //protected $username;
82
83
    /**
84
     * @var string
85
     *
86
     * @ORM\Column(name="username_canonical", type="string", length=100, nullable=false)
87
     */
88
    //protected $usernameCanonical;
89
90
    /**
91
     * @var string
92
     * @ORM\Column(name="email_canonical", type="string", length=100, nullable=false, unique=false)
93
     */
94
    //protected $emailCanonical;
95
96
    /**
97
     * @var string
98
     *
99
     * @ORM\Column(name="email", type="string", length=100, nullable=false, unique=false)
100
     */
101
    //protected $email;
102
103
    /**
104
     * @var boolean
105
     * @ORM\Column(name="locked", type="boolean")
106
     */
107
    //protected $locked;
108
109
    /**
110
     * @var boolean
111
     * @ORM\Column(name="enabled", type="boolean")
112
     */
113
    //protected $enabled;
114
115
    /**
116
     * @var boolean
117
     * @ORM\Column(name="expired", type="boolean")
118
     */
119
    //protected $expired;
120
121
    /**
122
     * @var boolean
123
     * @ORM\Column(name="credentials_expired", type="boolean")
124
     */
125
    //protected $credentialsExpired;
126
127
    /**
128
     * @var \DateTime
129
     * @ORM\Column(name="credentials_expire_at", type="datetime", nullable=true, unique=false)
130
     */
131
    //protected $credentialsExpireAt;
132
133
    /**
134
     * @var \DateTime
135
     * @ORM\Column(name="expires_at", type="datetime", nullable=true, unique=false)
136
     */
137
    //protected $expiresAt;
138
139
    /**
140
     * @var string
141
     *
142
     * @ORM\Column(name="lastname", type="string", length=60, nullable=true, unique=false)
143
     */
144
    protected $lastname;
145
146
    /**
147
     * @var string
148
     *
149
     * @ORM\Column(name="firstname", type="string", length=60, nullable=true, unique=false)
150
     */
151
    protected $firstname;
152
153
    /**
154
     * @var string
155
     *
156
     * @ORM\Column(name="password", type="string", length=255, nullable=false, unique=false)
157
     */
158
    //protected $password;
159
160
    /**
161
     * @var string
162
     *
163
     * @ORM\Column(name="auth_source", type="string", length=50, nullable=true, unique=false)
164
     */
165
    private $authSource;
166
167
    /**
168
     * @var boolean
169
     *
170
     * @ORM\Column(name="status", type="integer", nullable=false)
171
     */
172
    private $status;
173
174
    /**
175
     * @var string
176
     *
177
     * @ORM\Column(name="official_code", type="string", length=40, nullable=true, unique=false)
178
     */
179
    private $officialCode;
180
181
    /**
182
     * @var string
183
     *
184
     * @ORM\Column(name="phone", type="string", length=30, nullable=true, unique=false)
185
     */
186
    protected $phone;
187
188
    /**
189
     * @var string
190
     *
191
     * @ORM\Column(name="address", type="string", length=250, nullable=true, unique=false)
192
     */
193
    protected $address;
194
195
    /**
196
     * Vich\UploadableField(mapping="user_image", fileNameProperty="picture_uri")
197
     *
198
     * note This is not a mapped field of entity metadata, just a simple property.
199
     *
200
     * @var File $imageFile
201
     */
202
    protected $imageFile;
203
204
    /**
205
     * @var string
206
     * @ORM\Column(name="picture_uri", type="string", length=250, nullable=true, unique=false)
207
     */
208
    private $pictureUri;
209
210
    /**
211
     * ORM\ManyToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Media", cascade={"all"} )
212
     * @ORM\JoinColumn(name="picture_uri", referencedColumnName="id")
213
     */
214
    //protected $pictureUri;
215
216
    /**
217
     * @var integer
218
     *
219
     * @ORM\Column(name="creator_id", type="integer", nullable=true, unique=false)
220
     */
221
    private $creatorId;
222
223
    /**
224
     * @var string
225
     *
226
     * @ORM\Column(name="competences", type="text", nullable=true, unique=false)
227
     */
228
    private $competences;
229
230
    /**
231
     * @var string
232
     *
233
     * @ORM\Column(name="diplomas", type="text", nullable=true, unique=false)
234
     */
235
    private $diplomas;
236
237
    /**
238
     * @var string
239
     *
240
     * @ORM\Column(name="openarea", type="text", nullable=true, unique=false)
241
     */
242
    private $openarea;
243
244
    /**
245
     * @var string
246
     *
247
     * @ORM\Column(name="teach", type="text", nullable=true, unique=false)
248
     */
249
    private $teach;
250
251
    /**
252
     * @var string
253
     *
254
     * @ORM\Column(name="productions", type="string", length=250, nullable=true, unique=false)
255
     */
256
    private $productions;
257
258
    /**
259
     * @var string
260
     *
261
     * @ORM\Column(name="language", type="string", length=40, nullable=true, unique=false)
262
     */
263
    private $language;
264
265
    /**
266
     * @var \DateTime
267
     *
268
     * @ORM\Column(name="registration_date", type="datetime", nullable=false, unique=false)
269
     */
270
    private $registrationDate;
271
272
    /**
273
     * @var \DateTime
274
     *
275
     * @ORM\Column(name="expiration_date", type="datetime", nullable=true, unique=false)
276
     */
277
    private $expirationDate;
278
279
    /**
280
     * @var boolean
281
     *
282
     * @ORM\Column(name="active", type="boolean", nullable=false, unique=false)
283
     */
284
    private $active;
285
286
    /**
287
     * @var string
288
     *
289
     * @ORM\Column(name="openid", type="string", length=255, nullable=true, unique=false)
290
     */
291
    private $openid;
292
293
    /**
294
     * @var string
295
     *
296
     * @ORM\Column(name="theme", type="string", length=255, nullable=true, unique=false)
297
     */
298
    private $theme;
299
300
    /**
301
     * @var integer
302
     *
303
     * @ORM\Column(name="hr_dept_id", type="smallint", nullable=true, unique=false)
304
     */
305
    private $hrDeptId;
306
307
    /**
308
     * @var AccessUrl
309
     **/
310
    protected $currentUrl;
311
312
    /**
313
     * @ORM\Column(type="string", length=255)
314
     */
315
    //protected $salt;
316
317
    /**
318
     * @var \DateTime
319
     *
320
     * @ORM\Column(name="last_login", type="datetime", nullable=true, unique=false)
321
     */
322
    //protected $lastLogin;
323
324
    /**
325
     * @ORM\Column(name="facebook_id", type="string", length=255, nullable=true)
326
     */
327
    protected $facebookId;
328
329
    /**
330
     * @ORM\Column(name="facebook_access_token", type="string", length=255, nullable=true)
331
     */
332
    protected $facebookAccessToken;
333
334
    /**
335
     * @ORM\Column(name="google_id", type="string", length=255, nullable=true)
336
     */
337
    protected $googleId;
338
339
    /**
340
     * @ORM\Column(name="google_access_token", type="string", length=255, nullable=true)
341
     */
342
    protected $googleAccessToken;
343
344
    /**
345
     * @ORM\Column(name="github_id", type="string", length=255, nullable=true)
346
     */
347
    protected $githubId;
348
349
    /**
350
     * @ORM\Column(name="github_access_token", type="string", length=255, nullable=true)
351
     */
352
    protected $githubAccessToken;
353
354
    /**
355
     * @var \DateTime
356
     * @ORM\Column(name="created_at", type="datetime", nullable=true, unique=false)
357
     */
358
    protected $createdAt;
359
360
    /**
361
     * @var \DateTime
362
     * @ORM\Column(name="updated_at", type="datetime", nullable=true, unique=false)
363
     */
364
    protected $updatedAt;
365
366
    /**
367
     * Random string sent to the user email address in order to verify it
368
     *
369
     * @var string
370
     * @ORM\Column(name="confirmation_token", type="string", length=255, nullable=true)
371
     */
372
    //protected $confirmationToken;
373
374
    /**
375
     * @var \DateTime
376
     *
377
     * @ORM\Column(name="password_requested_at", type="datetime", nullable=true, unique=false)
378
     */
379
    //protected $passwordRequestedAt;
380
381
    /**
382
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CourseRelUser", mappedBy="user")
383
     **/
384
    protected $courses;
385
386
    /**
387
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CItemProperty", mappedBy="user")
388
     **/
389
    //protected $items;
390
391
    /**
392
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\UsergroupRelUser", mappedBy="user")
393
     **/
394
    protected $classes;
395
396
    /**
397
     * ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CDropboxPost", mappedBy="user")
398
     **/
399
    protected $dropBoxReceivedFiles;
400
401
    /**
402
     * ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CDropboxFile", mappedBy="userSent")
403
     **/
404
    protected $dropBoxSentFiles;
405
406
    /**
407
     * @ORM\Column(type="array")
408
     */
409
    //protected $roles;
410
411
    /**
412
     * @var boolean
413
     *
414
     * @ORM\Column(name="profile_completed", type="boolean", nullable=true)
415
     */
416
    protected $profileCompleted;
417
418
    /**
419
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\JuryMembers", mappedBy="user")
420
     **/
421
    //protected $jurySubscriptions;
422
423
    /**
424
     * @ORM\ManyToMany(targetEntity="Chamilo\UserBundle\Entity\Group")
425
     * @ORM\JoinTable(name="fos_user_user_group",
426
     *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
427
     *      inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
428
     * )
429
     */
430
    protected $groups;
431
432
    //private $isActive;
433
434
    /**
435
     * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CurriculumItemRelUser", mappedBy="user")
436
     **/
437
    protected $curriculumItems;
438
439
    /*
440
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelUser", mappedBy="user")
441
     *
442
     */
443
    protected $portals;
444
445
    /**
446
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Session", mappedBy="generalCoach")
447
     **/
448
    protected $sessionAsGeneralCoach;
449
450
    /**
451
     * @var ArrayCollection
452
     * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\UserFieldValues", mappedBy="user", orphanRemoval=true, cascade={"persist"})
453
     **/
454
    protected $extraFields;
455
456
    /**
457
     * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", mappedBy="creator")
458
     **/
459
    protected $resourceNodes;
460
461
    /**
462
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SessionRelCourseRelUser", mappedBy="user", cascade={"persist"})
463
     **/
464
    protected $sessionCourseSubscriptions;
465
466
    /**
467
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SkillRelUser", mappedBy="user", cascade={"persist"})
468
     */
469
    protected $achievedSkills;
470
471
    /**
472
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SkillRelUserComment", mappedBy="feedbackGiver")
473
     */
474
    protected $commentedUserSkills;
475
476
    /**
477
     * Constructor
478
     */
479
    public function __construct()
480
    {
481
        $this->status = self::STUDENT;
0 ignored issues
show
Documentation Bug introduced by
The property $status was declared of type boolean, but self::STUDENT is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
482
        parent::__construct();
483
        $this->salt = sha1(uniqid(null, true));
484
        $this->active = 1;
0 ignored issues
show
Documentation Bug introduced by
The property $active was declared of type boolean, but 1 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
485
        $this->registrationDate = new \DateTime();
486
        $this->authSource = 'platform';
487
        $this->courses = new ArrayCollection();
488
        //$this->items = new ArrayCollection();
489
        $this->classes = new ArrayCollection();
490
        $this->curriculumItems = new ArrayCollection();
491
        $this->portals = new ArrayCollection();
492
        $this->dropBoxSentFiles = new ArrayCollection();
493
        $this->dropBoxReceivedFiles = new ArrayCollection();
494
        //$this->extraFields = new ArrayCollection();
495
        //$this->userId = 0;
496
        //$this->createdAt = new \DateTime();
497
        //$this->updatedAt = new \DateTime();
498
499
        $this->enabled = false;
500
        $this->locked = false;
501
        $this->expired = false;
502
        $this->roles = array();
503
        $this->credentialsExpired = false;
504
    }
505
506
    /**
507
     * @return string
508
     */
509
    public function __toString()
510
    {
511
        return $this->getCompleteName();
512
    }
513
514
    /**
515
     * Updates the id with the user_id
516
     *  @ORM\PostPersist()
517
     */
518
    public function postPersist(LifecycleEventArgs $args)
519
    {
520
        //parent::postPersist();
521
        // Updates the user_id field
522
        $user = $args->getEntity();
523
        $this->setUserId($user->getId());
524
        /*$em = $args->getEntityManager();
525
        $em->persist($user);
526
        $em->flush();*/
527
    }
528
529
    /**
530
     * @param int $userId
531
     */
532
    public function setId($userId)
533
    {
534
        $this->id = $userId;
535
    }
536
537
    /**
538
     * @param int $userId
539
     */
540
    public function setUserId($userId)
541
    {
542
        if (!empty($userId)) {
543
            $this->userId = $userId;
544
        }
545
    }
546
547
    /**
548
     * @return int
549
     */
550
    public function getId()
551
    {
552
        return $this->id;
553
    }
554
555
    /**
556
     * @return string
557
     */
558
    public function getEncoderName()
559
    {
560
        return "legacy_encoder";
561
    }
562
563
    /**
564
     * @return ArrayCollection
565
     */
566
    public function getDropBoxSentFiles()
567
    {
568
        return $this->dropBoxSentFiles;
569
    }
570
571
    /**
572
     * @return ArrayCollection
573
     */
574
    public function getDropBoxReceivedFiles()
575
    {
576
        return $this->dropBoxReceivedFiles;
577
    }
578
579
    /**
580
     * @return ArrayCollection
581
     */
582
    public function getCourses()
583
    {
584
        return $this->courses;
585
    }
586
587
    /**
588
     * @return array
589
     */
590
    public static function getPasswordConstraints()
591
    {
592
        return
593
            array(
594
                new Assert\Length(array('min' => 5)),
595
                // Alpha numeric + "_" or "-"
596
                new Assert\Regex(array(
597
                        'pattern' => '/^[a-z\-_0-9]+$/i',
598
                        'htmlPattern' => '/^[a-z\-_0-9]+$/i')
599
                ),
600
                // Min 3 letters - not needed
601
                /*new Assert\Regex(array(
602
                    'pattern' => '/[a-z]{3}/i',
603
                    'htmlPattern' => '/[a-z]{3}/i')
604
                ),*/
605
                // Min 2 numbers
606
                new Assert\Regex(array(
607
                        'pattern' => '/[0-9]{2}/',
608
                        'htmlPattern' => '/[0-9]{2}/')
609
                ),
610
            )
611
            ;
612
    }
613
614
    /**
615
     * @param ClassMetadata $metadata
616
     */
617
    public static function loadValidatorMetadata(ClassMetadata $metadata)
618
    {
619
        //$metadata->addPropertyConstraint('firstname', new Assert\NotBlank());
620
        //$metadata->addPropertyConstraint('lastname', new Assert\NotBlank());
621
        //$metadata->addPropertyConstraint('email', new Assert\Email());
622
        /*
623
        $metadata->addPropertyConstraint('password',
624
            new Assert\Collection(self::getPasswordConstraints())
625
        );*/
626
627
        /*$metadata->addConstraint(new UniqueEntity(array(
628
            'fields'  => 'username',
629
            'message' => 'This value is already used.',
630
        )));*/
631
632
        /*$metadata->addPropertyConstraint(
633
            'username',
634
            new Assert\Length(array(
635
                'min'        => 2,
636
                'max'        => 50,
637
                '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.',
638
                '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.',
639
            ))
640
        );*/
641
    }
642
643
    /**
644
     * @inheritDoc
645
     */
646
    public function isEqualTo(UserInterface $user)
647
    {
648
        if (!$user instanceof User) {
649
            return false;
650
        }
651
652
        /*if ($this->password !== $user->getPassword()) {
653
            return false;
654
        }*/
655
656
        /*if ($this->getSalt() !== $user->getSalt()) {
657
            return false;
658
        }*/
659
660
        /*if ($this->username !== $user->getUsername()) {
661
            return false;
662
        }*/
663
664
        return true;
665
    }
666
667
    /**
668
     * @return ArrayCollection
669
     */
670
    public function getPortals()
671
    {
672
        return $this->portals;
673
    }
674
675
    /**
676
     * @param $portal
677
     */
678
    public function setPortal($portal)
679
    {
680
        $this->portals->add($portal);
681
    }
682
683
    /**
684
     * @return ArrayCollection
685
     */
686
    public function getCurriculumItems()
687
    {
688
        return $this->curriculumItems;
689
    }
690
691
    /**
692
     * @param $items
693
     */
694
    public function setCurriculumItems($items)
695
    {
696
        $this->curriculumItems = $items;
697
    }
698
699
    /**
700
     * @return bool
701
     */
702
    public function getIsActive()
703
    {
704
        return $this->active == 1;
705
    }
706
707
    /**
708
     * @return bool
709
     */
710
    public function isActive()
711
    {
712
        return $this->getIsActive();
713
    }
714
715
    /**
716
     * @inheritDoc
717
     */
718
    public function isEnabled()
719
    {
720
        return $this->getActive() == 1;
721
    }
722
723
    /**
724
     *
725
     * @return ArrayCollection
726
     */
727
    /*public function getRolesObj()
728
    {
729
        return $this->roles;
730
    }*/
731
732
    /**
733
     * Set salt
734
     *
735
     * @param string $salt
736
     *
737
     * @return User
738
     */
739
    public function setSalt($salt)
740
    {
741
        $this->salt = $salt;
742
743
        return $this;
744
    }
745
746
    /**
747
     * Get salt
748
     *
749
     * @return string
750
     */
751
    public function getSalt()
752
    {
753
        return $this->salt;
754
    }
755
756
    /**
757
     * @return ArrayCollection
758
     */
759
    public function getClasses()
760
    {
761
        return $this->classes;
762
    }
763
764
    /**
765
     *
766
     */
767
    public function getLps()
768
    {
769
        //return $this->lps;
770
        /*$criteria = Criteria::create()
771
            ->where(Criteria::expr()->eq("id", "666"))
772
            //->orderBy(array("username" => "ASC"))
773
            //->setFirstResult(0)
774
            //->setMaxResults(20)
775
        ;
776
        $lps = $this->lps->matching($criteria);*/
777
        /*return $this->lps->filter(
778
            function($entry) use ($idsToFilter) {
779
                return $entry->getId() == 1;
780
        });*/
781
    }
782
783
    /**
784
     * Return Complete Name with the Username
785
     *
786
     * @return string
787
     */
788
    public function getCompleteNameWithUsername()
789
    {
790
        return api_get_person_name($this->firstname, $this->lastname).' ('.$this->username.')';
791
    }
792
793
    /**
794
     * @todo don't use api_get_person_name
795
     * @return string
796
     */
797
    public function getCompleteName()
798
    {
799
        return api_get_person_name($this->firstname, $this->lastname);
800
    }
801
802
    /**
803
     * Returns the list of classes for the user
804
     * @return string
805
     */
806
    public function getCompleteNameWithClasses()
807
    {
808
        $classSubscription = $this->getClasses();
809
        $classList = array();
810
        /** @var UsergroupRelUser $subscription */
811
        foreach ($classSubscription as $subscription) {
812
            $class = $subscription->getUsergroup();
813
            $classList[] = $class->getName();
814
        }
815
        $classString = !empty($classList) ? ' ['.implode(', ', $classList).']' : null;
816
817
        return $this->getCompleteName().$classString;
818
    }
819
820
    /**
821
     * Get userId
822
     *
823
     * @return integer
824
     */
825
    public function getUserId()
826
    {
827
        return $this->userId;
828
    }
829
830
    /**
831
     * Set lastname
832
     *
833
     * @param string $lastname
834
     *
835
     * @return User
836
     */
837
    public function setLastname($lastname)
838
    {
839
        $this->lastname = $lastname;
840
841
        return $this;
842
    }
843
844
    /**
845
     * Set firstname
846
     *
847
     * @param string $firstname
848
     *
849
     * @return User
850
     */
851
    public function setFirstname($firstname)
852
    {
853
        $this->firstname = $firstname;
854
855
        return $this;
856
    }
857
858
    /**
859
     * Set password
860
     *
861
     * @param string $password
862
     * @return User
863
     */
864
    public function setPassword($password)
865
    {
866
        $this->password = $password;
867
868
        return $this;
869
    }
870
871
    /**
872
     * Get password
873
     *
874
     * @return string
875
     */
876
    public function getPassword()
877
    {
878
        return $this->password;
879
    }
880
881
    /**
882
     * Set authSource
883
     *
884
     * @param string $authSource
885
     * @return User
886
     */
887
    public function setAuthSource($authSource)
888
    {
889
        $this->authSource = $authSource;
890
891
        return $this;
892
    }
893
894
    /**
895
     * Get authSource
896
     *
897
     * @return string
898
     */
899
    public function getAuthSource()
900
    {
901
        return $this->authSource;
902
    }
903
904
    /**
905
     * Set email
906
     *
907
     * @param string $email
908
     * @return User
909
     */
910
    public function setEmail($email)
911
    {
912
        $this->email = $email;
913
914
        return $this;
915
    }
916
917
    /**
918
     * Get email
919
     *
920
     * @return string
921
     */
922
    public function getEmail()
923
    {
924
        return $this->email;
925
    }
926
927
    /**
928
     * Set status
929
     *
930
     * @param int $status
931
     *
932
     * @return User
933
     */
934
    public function setStatus($status)
935
    {
936
        $this->status = $status;
0 ignored issues
show
Documentation Bug introduced by
The property $status was declared of type boolean, but $status is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
937
938
        return $this;
939
    }
940
941
    /**
942
     * Get status
943
     *
944
     * @return boolean
945
     */
946
    public function getStatus()
947
    {
948
        return $this->status;
949
    }
950
951
    /**
952
     * Set officialCode
953
     *
954
     * @param string $officialCode
955
     * @return User
956
     */
957
    public function setOfficialCode($officialCode)
958
    {
959
        $this->officialCode = $officialCode;
960
961
        return $this;
962
    }
963
964
    /**
965
     * Get officialCode
966
     *
967
     * @return string
968
     */
969
    public function getOfficialCode()
970
    {
971
        return $this->officialCode;
972
    }
973
974
    /**
975
     * Set phone
976
     *
977
     * @param string $phone
978
     * @return User
979
     */
980
    public function setPhone($phone)
981
    {
982
        $this->phone = $phone;
983
984
        return $this;
985
    }
986
987
    /**
988
     * Get phone
989
     *
990
     * @return string
991
     */
992
    public function getPhone()
993
    {
994
        return $this->phone;
995
    }
996
997
    /**
998
     * Set address
999
     *
1000
     * @param string $address
1001
     * @return User
1002
     */
1003
    public function setAddress($address)
1004
    {
1005
        $this->address = $address;
1006
1007
        return $this;
1008
    }
1009
1010
    /**
1011
     * Get address
1012
     *
1013
     * @return string
1014
     */
1015
    public function getAddress()
1016
    {
1017
        return $this->address;
1018
    }
1019
1020
    /**
1021
     * Set pictureUri
1022
     *
1023
     * @param string $pictureUri
1024
     * @return User
1025
     */
1026
    public function setPictureUri($pictureUri)
1027
    {
1028
        $this->pictureUri = $pictureUri;
1029
1030
        return $this;
1031
    }
1032
1033
    /**
1034
     * Get pictureUri
1035
     *
1036
     * @return Media
1037
     */
1038
    public function getPictureUri()
1039
    {
1040
        return $this->pictureUri;
1041
    }
1042
1043
    /**
1044
     * Set creatorId
1045
     *
1046
     * @param integer $creatorId
1047
     * @return User
1048
     */
1049
    public function setCreatorId($creatorId)
1050
    {
1051
        $this->creatorId = $creatorId;
1052
1053
        return $this;
1054
    }
1055
1056
    /**
1057
     * Get creatorId
1058
     *
1059
     * @return integer
1060
     */
1061
    public function getCreatorId()
1062
    {
1063
        return $this->creatorId;
1064
    }
1065
1066
    /**
1067
     * Set competences
1068
     *
1069
     * @param string $competences
1070
     * @return User
1071
     */
1072
    public function setCompetences($competences)
1073
    {
1074
        $this->competences = $competences;
1075
1076
        return $this;
1077
    }
1078
1079
    /**
1080
     * Get competences
1081
     *
1082
     * @return string
1083
     */
1084
    public function getCompetences()
1085
    {
1086
        return $this->competences;
1087
    }
1088
1089
    /**
1090
     * Set diplomas
1091
     *
1092
     * @param string $diplomas
1093
     * @return User
1094
     */
1095
    public function setDiplomas($diplomas)
1096
    {
1097
        $this->diplomas = $diplomas;
1098
1099
        return $this;
1100
    }
1101
1102
    /**
1103
     * Get diplomas
1104
     *
1105
     * @return string
1106
     */
1107
    public function getDiplomas()
1108
    {
1109
        return $this->diplomas;
1110
    }
1111
1112
    /**
1113
     * Set openarea
1114
     *
1115
     * @param string $openarea
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
     * @return User
1140
     */
1141
    public function setTeach($teach)
1142
    {
1143
        $this->teach = $teach;
1144
1145
        return $this;
1146
    }
1147
1148
    /**
1149
     * Get teach
1150
     *
1151
     * @return string
1152
     */
1153
    public function getTeach()
1154
    {
1155
        return $this->teach;
1156
    }
1157
1158
    /**
1159
     * Set productions
1160
     *
1161
     * @param string $productions
1162
     * @return User
1163
     */
1164
    public function setProductions($productions)
1165
    {
1166
        $this->productions = $productions;
1167
1168
        return $this;
1169
    }
1170
1171
    /**
1172
     * Get productions
1173
     *
1174
     * @return string
1175
     */
1176
    public function getProductions()
1177
    {
1178
        return $this->productions;
1179
    }
1180
1181
    /**
1182
     * Set language
1183
     *
1184
     * @param string $language
1185
     * @return User
1186
     */
1187
    public function setLanguage($language)
1188
    {
1189
        $this->language = $language;
1190
1191
        return $this;
1192
    }
1193
1194
    /**
1195
     * Get language
1196
     *
1197
     * @return string
1198
     */
1199
    public function getLanguage()
1200
    {
1201
        return $this->language;
1202
    }
1203
1204
    /**
1205
     * Set registrationDate
1206
     *
1207
     * @param \DateTime $registrationDate
1208
     * @return User
1209
     */
1210
    public function setRegistrationDate($registrationDate)
1211
    {
1212
        $this->registrationDate = $registrationDate;
1213
1214
        return $this;
1215
    }
1216
1217
    /**
1218
     * Get registrationDate
1219
     *
1220
     * @return \DateTime
1221
     */
1222
    public function getRegistrationDate()
1223
    {
1224
        return $this->registrationDate;
1225
    }
1226
1227
    /**
1228
     * Set expirationDate
1229
     *
1230
     * @param \DateTime $expirationDate
1231
     *
1232
     * @return User
1233
     */
1234
    public function setExpirationDate($expirationDate)
1235
    {
1236
        $this->expirationDate = $expirationDate;
1237
1238
        return $this;
1239
    }
1240
1241
    /**
1242
     * Get expirationDate
1243
     *
1244
     * @return \DateTime
1245
     */
1246
    public function getExpirationDate()
1247
    {
1248
        return $this->expirationDate;
1249
    }
1250
1251
    /**
1252
     * Set active
1253
     *
1254
     * @param boolean $active
1255
     * @return User
1256
     */
1257
    public function setActive($active)
1258
    {
1259
        $this->active = $active;
1260
1261
        return $this;
1262
    }
1263
1264
    /**
1265
     * Get active
1266
     *
1267
     * @return boolean
1268
     */
1269
    public function getActive()
1270
    {
1271
        return $this->active;
1272
    }
1273
1274
    /**
1275
     * Set openid
1276
     *
1277
     * @param string $openid
1278
     * @return User
1279
     */
1280
    public function setOpenid($openid)
1281
    {
1282
        $this->openid = $openid;
1283
1284
        return $this;
1285
    }
1286
1287
    /**
1288
     * Get openid
1289
     *
1290
     * @return string
1291
     */
1292
    public function getOpenid()
1293
    {
1294
        return $this->openid;
1295
    }
1296
1297
    /**
1298
     * Set theme
1299
     *
1300
     * @param string $theme
1301
     * @return User
1302
     */
1303
    public function setTheme($theme)
1304
    {
1305
        $this->theme = $theme;
1306
1307
        return $this;
1308
    }
1309
1310
    /**
1311
     * Get theme
1312
     *
1313
     * @return string
1314
     */
1315
    public function getTheme()
1316
    {
1317
        return $this->theme;
1318
    }
1319
1320
    /**
1321
     * Set hrDeptId
1322
     *
1323
     * @param integer $hrDeptId
1324
     * @return User
1325
     */
1326
    public function setHrDeptId($hrDeptId)
1327
    {
1328
        $this->hrDeptId = $hrDeptId;
1329
1330
        return $this;
1331
    }
1332
1333
    /**
1334
     * Get hrDeptId
1335
     *
1336
     * @return integer
1337
     */
1338
    public function getHrDeptId()
1339
    {
1340
        return $this->hrDeptId;
1341
    }
1342
1343
    /**
1344
     * @return string
1345
     */
1346
    public function getAvatar()
1347
    {
1348
        return $this->getPictureUri();
1349
    }
1350
1351
    /**
1352
     * @return string
1353
     */
1354
    public function getAvatarOrAnonymous($size = 22)
1355
    {
1356
        $avatar = $this->getAvatar();
1357
1358
        if (empty($avatar)) {
1359
            return "img/icons/$size/unknown.png";
1360
        }
1361
1362
        return $avatar;
1363
    }
1364
1365
    /**
1366
     * @return \DateTime
1367
     */
1368
    public function getMemberSince()
1369
    {
1370
        return $this->registrationDate;
1371
    }
1372
1373
    /**
1374
     * @return bool
1375
     */
1376
    public function isOnline()
1377
    {
1378
        return false;
1379
    }
1380
1381
    /**
1382
     * @return int
1383
     */
1384
    public function getIdentifier()
1385
    {
1386
        return $this->getId();
1387
    }
1388
1389
    /**
1390
     * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
1391
     * of 'UploadedFile' is injected into this setter to trigger the  update. If this
1392
     * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
1393
     * must be able to accept an instance of 'File' as the bundle will inject one here
1394
     * during Doctrine hydration.
1395
     *
1396
     * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
1397
     */
1398
    public function setImageFile(File $image)
1399
    {
1400
        $this->imageFile = $image;
1401
1402
        if ($image) {
1403
            // It is required that at least one field changes if you are using doctrine
1404
            // otherwise the event listeners won't be called and the file is lost
1405
            $this->updatedAt = new \DateTime('now');
1406
        }
1407
    }
1408
1409
    /**
1410
     * @return File
1411
     */
1412
    public function getImageFile()
1413
    {
1414
        return $this->imageFile;
1415
    }
1416
1417
    /**
1418
     * @param string $imageName
1419
     */
1420
    public function setImageName($imageName)
1421
    {
1422
        $this->imageName = $imageName;
1423
    }
1424
1425
    /**
1426
     * @return string
1427
     */
1428
    public function getImageName()
1429
    {
1430
        return $this->imageName;
1431
    }
1432
1433
    /**
1434
     * @return string
1435
     */
1436
    public function getSlug()
1437
    {
1438
        return $this->getUsername();
1439
    }
1440
1441
    /**
1442
     * @param $slug
1443
     * @return User
1444
     */
1445
    public function setSlug($slug)
1446
    {
1447
        return $this->setUsername($slug);
1448
    }
1449
1450
    /**
1451
     * Set lastLogin
1452
     *
1453
     * @param \DateTime $lastLogin
1454
     *
1455
     * @return User
1456
     */
1457
    public function setLastLogin(\DateTime $lastLogin)
1458
    {
1459
        $this->lastLogin = $lastLogin;
1460
1461
        return $this;
1462
    }
1463
1464
    /**
1465
     * Get lastLogin
1466
     *
1467
     * @return \DateTime
1468
     */
1469
    public function getLastLogin()
1470
    {
1471
        return $this->lastLogin;
1472
    }
1473
1474
    /**
1475
     * {@inheritdoc}
1476
     */
1477
    public function getExtraFields()
1478
    {
1479
        return $this->extraFields;
1480
    }
1481
1482
    /**
1483
     * {@inheritdoc}
1484
     */
1485
    public function setExtraFields($extraFields)
1486
    {
1487
        $this->extraFields = new ArrayCollection();
1488
        foreach ($extraFields as $extraField) {
1489
            $this->addExtraFields($extraField);
1490
        }
1491
1492
        return $this;
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);
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
     * @return ArrayCollection
1574
     */
1575
    public function getSessionCourseSubscriptions()
1576
    {
1577
        return $this->sessionCourseSubscriptions;
1578
    }
1579
1580
    /**
1581
     * @return string
1582
     */
1583
    public function getConfirmationToken()
1584
    {
1585
        return $this->confirmationToken;
1586
    }
1587
1588
    /**
1589
     * @param string $confirmationToken
1590
     *
1591
     * @return User
1592
     */
1593
    public function setConfirmationToken($confirmationToken)
1594
    {
1595
        $this->confirmationToken = $confirmationToken;
1596
1597
        return $this;
1598
    }
1599
1600
    /**
1601
     * @return \DateTime
1602
     */
1603
    public function getPasswordRequestedAt()
1604
    {
1605
        return $this->passwordRequestedAt;
1606
    }
1607
1608
1609
    /**
1610
     * @param int $ttl
1611
     * @return bool
1612
     */
1613
    public function isPasswordRequestNonExpired($ttl)
1614
    {
1615
        return $this->getPasswordRequestedAt() instanceof \DateTime &&
1616
        $this->getPasswordRequestedAt()->getTimestamp() + $ttl > time();
1617
    }
1618
1619
    public function getUsername()
1620
    {
1621
        return $this->username;
1622
    }
1623
1624
    /**
1625
     * Returns the creation date.
1626
     *
1627
     * @return \DateTime|null
1628
     */
1629
    public function getCreatedAt()
1630
    {
1631
        return $this->createdAt;
1632
    }
1633
1634
    /**
1635
     * Sets the last update date.
1636
     *
1637
     * @param \DateTime|null $updatedAt
1638
     *
1639
     * @return User
1640
     */
1641
    public function setUpdatedAt(\DateTime $updatedAt = null)
1642
    {
1643
        $this->updatedAt = $updatedAt;
1644
1645
        return $this;
1646
    }
1647
1648
    /**
1649
     * Returns the last update date.
1650
     *
1651
     * @return \DateTime|null
1652
     */
1653
    public function getUpdatedAt()
1654
    {
1655
        return $this->updatedAt;
1656
    }
1657
1658
    /**
1659
     * Returns the expiration date.
1660
     *
1661
     * @return \DateTime|null
1662
     */
1663
    public function getExpiresAt()
1664
    {
1665
        return $this->expiresAt;
1666
    }
1667
1668
    /**
1669
     * Returns the credentials expiration date.
1670
     *
1671
     * @return \DateTime
1672
     */
1673
    public function getCredentialsExpireAt()
1674
    {
1675
        return $this->credentialsExpireAt;
1676
    }
1677
1678
    /**
1679
     * Sets the credentials expiration date.
1680
     *
1681
     * @param \DateTime|null $date
1682
     *
1683
     * @return User
1684
     */
1685
    public function setCredentialsExpireAt(\DateTime $date = null)
1686
    {
1687
        $this->credentialsExpireAt = $date;
1688
1689
        return $this;
1690
    }
1691
1692
    /**
1693
     * Sets the user groups.
1694
     *
1695
     * @param array $groups
1696
     *
1697
     * @return User
1698
     */
1699
    public function setGroups($groups)
1700
    {
1701
        foreach ($groups as $group) {
1702
            $this->addGroup($group);
1703
        }
1704
1705
        return $this;
1706
    }
1707
1708
    /**
1709
     * Sets the two-step verification code.
1710
     *
1711
     * @param string $twoStepVerificationCode
1712
     *
1713
     * @return User
1714
     */
1715
    public function setTwoStepVerificationCode($twoStepVerificationCode)
1716
    {
1717
        $this->twoStepVerificationCode = $twoStepVerificationCode;
1718
1719
        return $this;
1720
    }
1721
1722
    /**
1723
     * Returns the two-step verification code.
1724
     *
1725
     * @return string
1726
     */
1727
    public function getTwoStepVerificationCode()
1728
    {
1729
        return $this->twoStepVerificationCode;
1730
    }
1731
1732
    /**
1733
     * @param string $biography
1734
     *
1735
     * @return User
1736
     */
1737
    public function setBiography($biography)
1738
    {
1739
        $this->biography = $biography;
1740
1741
        return $this;
1742
    }
1743
1744
    /**
1745
     * @return string
1746
     */
1747
    public function getBiography()
1748
    {
1749
        return $this->biography;
1750
    }
1751
1752
    /**
1753
     * @param \DateTime $dateOfBirth
1754
     *
1755
     * @return User
1756
     */
1757
    public function setDateOfBirth($dateOfBirth)
1758
    {
1759
        $this->dateOfBirth = $dateOfBirth;
1760
1761
        return $this;
1762
    }
1763
1764
    /**
1765
     * @return \DateTime
1766
     */
1767
    public function getDateOfBirth()
1768
    {
1769
        return $this->dateOfBirth;
1770
    }
1771
1772
    /**
1773
     * @param string $facebookData
1774
     *
1775
     * @return User
1776
     */
1777
    public function setFacebookData($facebookData)
1778
    {
1779
        $this->facebookData = $facebookData;
1780
1781
        return $this;
1782
    }
1783
1784
    /**
1785
     * @return string
1786
     */
1787
    public function getFacebookData()
1788
    {
1789
        return $this->facebookData;
1790
    }
1791
1792
    /**
1793
     * @param string $facebookName
1794
     *
1795
     * @return User
1796
     */
1797
    public function setFacebookName($facebookName)
1798
    {
1799
        $this->facebookName = $facebookName;
1800
1801
        return $this;
1802
    }
1803
1804
    /**
1805
     * @return string
1806
     */
1807
    public function getFacebookName()
1808
    {
1809
        return $this->facebookName;
1810
    }
1811
1812
    /**
1813
     * @param string $facebookUid
1814
     *
1815
     * @return User
1816
     */
1817
    public function setFacebookUid($facebookUid)
1818
    {
1819
        $this->facebookUid = $facebookUid;
1820
1821
        return $this;
1822
    }
1823
1824
    /**
1825
     * @return string
1826
     */
1827
    public function getFacebookUid()
1828
    {
1829
        return $this->facebookUid;
1830
    }
1831
1832
    /**
1833
     * @return string
1834
     */
1835
    public function getFirstname()
1836
    {
1837
        return $this->firstname;
1838
    }
1839
1840
    /**
1841
     * @param string $gender
1842
     *
1843
     * @return User
1844
     */
1845
    public function setGender($gender)
1846
    {
1847
        $this->gender = $gender;
1848
1849
        return $this;
1850
    }
1851
1852
    /**
1853
     * @return string
1854
     */
1855
    public function getGender()
1856
    {
1857
        return $this->gender;
1858
    }
1859
1860
    /**
1861
     * @param string $gplusData
1862
     *
1863
     * @return User
1864
     */
1865
    public function setGplusData($gplusData)
1866
    {
1867
        $this->gplusData = $gplusData;
1868
1869
        return $this;
1870
    }
1871
1872
    /**
1873
     * @return string
1874
     */
1875
    public function getGplusData()
1876
    {
1877
        return $this->gplusData;
1878
    }
1879
1880
    /**
1881
     * @param string $gplusName
1882
     *
1883
     * @return User
1884
     */
1885
    public function setGplusName($gplusName)
1886
    {
1887
        $this->gplusName = $gplusName;
1888
1889
        return $this;
1890
    }
1891
1892
    /**
1893
     * @return string
1894
     */
1895
    public function getGplusName()
1896
    {
1897
        return $this->gplusName;
1898
    }
1899
1900
    /**
1901
     * @param string $gplusUid
1902
     *
1903
     * @return User
1904
     */
1905
    public function setGplusUid($gplusUid)
1906
    {
1907
        $this->gplusUid = $gplusUid;
1908
1909
        return $this;
1910
    }
1911
1912
    /**
1913
     * @return string
1914
     */
1915
    public function getGplusUid()
1916
    {
1917
        return $this->gplusUid;
1918
    }
1919
1920
    /**
1921
     * @return string
1922
     */
1923
    public function getLastname()
1924
    {
1925
        return $this->lastname;
1926
    }
1927
1928
    /**
1929
     * @param string $locale
1930
     *
1931
     * @return User
1932
     */
1933
    public function setLocale($locale)
1934
    {
1935
        $this->locale = $locale;
1936
1937
        return $this;
1938
    }
1939
1940
    /**
1941
     * @return string
1942
     */
1943
    public function getLocale()
1944
    {
1945
        return $this->locale;
1946
    }
1947
1948
     /**
1949
     * @param string $timezone
1950
     *
1951
     * @return User
1952
     */
1953
    public function setTimezone($timezone)
1954
    {
1955
        $this->timezone = $timezone;
1956
1957
        return $this;
1958
    }
1959
1960
    /**
1961
     * @return string
1962
     */
1963
    public function getTimezone()
1964
    {
1965
        return $this->timezone;
1966
    }
1967
1968
    /**
1969
     * @param string $twitterData
1970
     *
1971
     * @return User
1972
     */
1973
    public function setTwitterData($twitterData)
1974
    {
1975
        $this->twitterData = $twitterData;
1976
1977
        return $this;
1978
    }
1979
1980
    /**
1981
     * @return string
1982
     */
1983
    public function getTwitterData()
1984
    {
1985
        return $this->twitterData;
1986
    }
1987
1988
    /**
1989
     * @param string $twitterName
1990
     *
1991
     * @return User
1992
     */
1993
    public function setTwitterName($twitterName)
1994
    {
1995
        $this->twitterName = $twitterName;
1996
1997
        return $this;
1998
    }
1999
2000
    /**
2001
     * @return string
2002
     */
2003
    public function getTwitterName()
2004
    {
2005
        return $this->twitterName;
2006
    }
2007
2008
    /**
2009
     * @param string $twitterUid
2010
     *
2011
     * @return User
2012
     */
2013
    public function setTwitterUid($twitterUid)
2014
    {
2015
        $this->twitterUid = $twitterUid;
2016
2017
        return $this;
2018
    }
2019
2020
    /**
2021
     * @return string
2022
     */
2023
    public function getTwitterUid()
2024
    {
2025
        return $this->twitterUid;
2026
    }
2027
2028
    /**
2029
     * @param string $website
2030
     *
2031
     * @return User
2032
     */
2033
    public function setWebsite($website)
2034
    {
2035
        $this->website = $website;
2036
2037
        return $this;
2038
    }
2039
2040
    /**
2041
     * @return string
2042
     */
2043
    public function getWebsite()
2044
    {
2045
        return $this->website;
2046
    }
2047
2048
    /**
2049
     * @param string $token
2050
     *
2051
     * @return User
2052
     */
2053
    public function setToken($token)
2054
    {
2055
        $this->token = $token;
2056
2057
        return $this;
2058
    }
2059
2060
    /**
2061
     * @return string
2062
     */
2063
    public function getToken()
2064
    {
2065
        return $this->token;
2066
    }
2067
2068
    /**
2069
     * @return string
2070
     */
2071
    public function getFullname()
2072
    {
2073
        return sprintf('%s %s', $this->getFirstname(), $this->getLastname());
2074
    }
2075
2076
    /**
2077
     * @return array
2078
     */
2079
    public function getRealRoles()
2080
    {
2081
        return $this->roles;
2082
    }
2083
2084
    /**
2085
     * @param array $roles
2086
     *
2087
     * @return User
2088
     */
2089
    public function setRealRoles(array $roles)
2090
    {
2091
        $this->setRoles($roles);
2092
2093
        return $this;
2094
    }
2095
2096
    /**
2097
     * Removes sensitive data from the user.
2098
     */
2099
    public function eraseCredentials()
2100
    {
2101
        $this->plainPassword = null;
2102
    }
2103
2104
    /**
2105
     * @return string
2106
     */
2107
    public function getUsernameCanonical()
2108
    {
2109
        return $this->usernameCanonical;
2110
    }
2111
2112
    /**
2113
     * @return string
2114
     */
2115
    public function getEmailCanonical()
2116
    {
2117
        return $this->emailCanonical;
2118
    }
2119
2120
    /**
2121
     * @return mixed
2122
     */
2123
    public function getPlainPassword()
2124
    {
2125
        if (isset($this->plainPassword)) {
2126
            return $this->plainPassword;
2127
        }
2128
    }
2129
2130
      /**
2131
     * Returns the user roles
2132
     *
2133
     * @return array The roles
2134
     */
2135
    public function getRoles()
2136
    {
2137
        $roles = $this->roles;
2138
2139
        foreach ($this->getGroups() as $group) {
2140
            $roles = array_merge($roles, $group->getRoles());
2141
        }
2142
2143
        // we need to make sure to have at least one role
2144
        $roles[] = static::ROLE_DEFAULT;
2145
2146
        return array_unique($roles);
2147
    }
2148
2149
    /**
2150
     * Never use this to check if this user has access to anything!
2151
     *
2152
     * Use the SecurityContext, or an implementation of AccessDecisionManager
2153
     * instead, e.g.
2154
     *
2155
     *         $securityContext->isGranted('ROLE_USER');
2156
     *
2157
     * @param string $role
2158
     *
2159
     * @return boolean
2160
     */
2161
    public function hasRole($role)
2162
    {
2163
        return in_array(strtoupper($role), $this->getRoles(), true);
2164
    }
2165
2166
    public function isAccountNonExpired()
2167
    {
2168
        if (true === $this->expired) {
2169
            return false;
2170
        }
2171
2172
        if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
2173
            return false;
2174
        }
2175
2176
        return true;
2177
    }
2178
2179
    public function isAccountNonLocked()
2180
    {
2181
        return !$this->locked;
2182
    }
2183
2184
    public function isCredentialsNonExpired()
2185
    {
2186
        if (true === $this->credentialsExpired) {
2187
            return false;
2188
        }
2189
2190
        if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
2191
            return false;
2192
        }
2193
2194
        return true;
2195
    }
2196
2197
    public function isCredentialsExpired()
2198
    {
2199
        return !$this->isCredentialsNonExpired();
2200
    }
2201
2202
    public function isExpired()
2203
    {
2204
        return !$this->isAccountNonExpired();
2205
    }
2206
2207
    public function isLocked()
2208
    {
2209
        return !$this->isAccountNonLocked();
2210
    }
2211
2212
    public function isSuperAdmin()
2213
    {
2214
        return $this->hasRole(static::ROLE_SUPER_ADMIN);
2215
    }
2216
2217
    public function isUser(UserInterface $user = null)
2218
    {
2219
        return null !== $user && $this->getId() === $user->getId();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface FOS\UserBundle\Model\UserInterface as the method getId() does only exist in the following implementations of said interface: Chamilo\UserBundle\Entity\User, FOS\UserBundle\Document\User, FOS\UserBundle\Entity\User, FOS\UserBundle\Model\User, FOS\UserBundle\Tests\Doctrine\DummyUser, FOS\UserBundle\Tests\TestUser, HWI\Bundle\OAuthBundle\Tests\Fixtures\FOSUser, Sonata\UserBundle\Document\BaseUser, Sonata\UserBundle\Entity\BaseUser, Sonata\UserBundle\Model\User.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
2220
    }
2221
2222
    public function removeRole($role)
2223
    {
2224
        if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
2225
            unset($this->roles[$key]);
2226
            $this->roles = array_values($this->roles);
2227
        }
2228
2229
        return $this;
2230
    }
2231
2232
    public function setUsername($username)
2233
    {
2234
        $this->username = $username;
2235
2236
        return $this;
2237
    }
2238
2239
    public function setUsernameCanonical($usernameCanonical)
2240
    {
2241
        $this->usernameCanonical = $usernameCanonical;
2242
2243
        return $this;
2244
    }
2245
2246
    /**
2247
     * @param boolean $boolean
2248
     *
2249
     * @return User
2250
     */
2251
    public function setCredentialsExpired($boolean)
2252
    {
2253
        $this->credentialsExpired = $boolean;
2254
2255
        return $this;
2256
    }
2257
2258
    public function setEmailCanonical($emailCanonical)
2259
    {
2260
        $this->emailCanonical = $emailCanonical;
2261
2262
        return $this;
2263
    }
2264
2265
    public function setEnabled($boolean)
2266
    {
2267
        $this->enabled = (Boolean) $boolean;
2268
2269
        return $this;
2270
    }
2271
2272
    /**
2273
     * Sets this user to expired.
2274
     *
2275
     * @param Boolean $boolean
2276
     *
2277
     * @return User
2278
     */
2279
    public function setExpired($boolean)
2280
    {
2281
        $this->expired = (Boolean) $boolean;
2282
2283
        return $this;
2284
    }
2285
2286
    /**
2287
     * @param \DateTime $date
2288
     *
2289
     * @return User
2290
     */
2291
    public function setExpiresAt(\DateTime $date = null)
2292
    {
2293
        $this->expiresAt = $date;
2294
2295
        return $this;
2296
    }
2297
2298
    public function setSuperAdmin($boolean)
2299
    {
2300
        if (true === $boolean) {
2301
            $this->addRole(static::ROLE_SUPER_ADMIN);
2302
        } else {
2303
            $this->removeRole(static::ROLE_SUPER_ADMIN);
2304
        }
2305
2306
        return $this;
2307
    }
2308
2309
    public function setPlainPassword($password)
2310
    {
2311
        $this->plainPassword = $password;
2312
2313
        return $this;
2314
    }
2315
2316
    public function setLocked($boolean)
2317
    {
2318
        $this->locked = $boolean;
2319
2320
        return $this;
2321
    }
2322
2323
    public function setPasswordRequestedAt(\DateTime $date = null)
2324
    {
2325
        $this->passwordRequestedAt = $date;
2326
2327
        return $this;
2328
    }
2329
2330
2331
    public function setRoles(array $roles)
2332
    {
2333
        $this->roles = array();
2334
2335
        foreach ($roles as $role) {
2336
            $this->addRole($role);
2337
        }
2338
2339
        return $this;
2340
    }
2341
2342
    /**
2343
     * Gets the groups granted to the user.
2344
     *
2345
     * @return Collection
2346
     */
2347
    public function getGroups()
2348
    {
2349
        return $this->groups ?: $this->groups = new ArrayCollection();
2350
    }
2351
2352
    public function getGroupNames()
2353
    {
2354
        $names = array();
2355
        foreach ($this->getGroups() as $group) {
2356
            $names[] = $group->getName();
2357
        }
2358
2359
        return $names;
2360
    }
2361
2362
    public function hasGroup($name)
2363
    {
2364
        return in_array($name, $this->getGroupNames());
2365
    }
2366
2367
    public function addGroup(GroupInterface $group)
2368
    {
2369
        if (!$this->getGroups()->contains($group)) {
2370
            $this->getGroups()->add($group);
2371
        }
2372
2373
        return $this;
2374
    }
2375
2376
    public function removeGroup(GroupInterface $group)
2377
    {
2378
        if ($this->getGroups()->contains($group)) {
2379
            $this->getGroups()->removeElement($group);
2380
        }
2381
2382
        return $this;
2383
    }
2384
2385
    public function addRole($role)
2386
    {
2387
        $role = strtoupper($role);
2388
        if ($role === static::ROLE_DEFAULT) {
2389
            return $this;
2390
        }
2391
2392
        if (!in_array($role, $this->roles, true)) {
2393
            $this->roles[] = $role;
2394
        }
2395
2396
        return $this;
2397
    }
2398
2399
    /**
2400
     * Serializes the user.
2401
     *
2402
     * The serialized data have to contain the fields used by the equals method and the username.
2403
     *
2404
     * @return string
2405
     */
2406
    public function serialize()
2407
    {
2408
        return serialize(array(
2409
            $this->password,
2410
            $this->salt,
2411
            $this->usernameCanonical,
2412
            $this->username,
2413
            $this->expired,
2414
            $this->locked,
2415
            $this->credentialsExpired,
2416
            $this->enabled,
2417
            $this->id,
2418
        ));
2419
    }
2420
2421
    /**
2422
     * Unserializes the user.
2423
     *
2424
     * @param string $serialized
2425
     */
2426
    public function unserialize($serialized)
2427
    {
2428
        $data = unserialize($serialized);
2429
        // add a few extra elements in the array to ensure that we have enough keys when unserializing
2430
        // older data which does not include all properties.
2431
        $data = array_merge($data, array_fill(0, 2, null));
2432
2433
        list(
2434
            $this->password,
2435
            $this->salt,
2436
            $this->usernameCanonical,
2437
            $this->username,
2438
            $this->expired,
2439
            $this->locked,
2440
            $this->credentialsExpired,
2441
            $this->enabled,
2442
            $this->id
2443
            ) = $data;
2444
    }
2445
2446
    /**
2447
     * Get achievedSkills
2448
     * @return ArrayCollection
2449
     */
2450
    public function getAchievedSkills()
2451
    {
2452
        return $this->achievedSkills;
2453
    }
2454
2455
    /**
2456
     * Check if the user has the skill
2457
     * @param Skill $skill The skill
2458
     * @return boolean
2459
     */
2460
    public function hasSkill(Skill $skill)
2461
    {
2462
        $achievedSkills = $this->getAchievedSkills();
2463
2464
        foreach ($achievedSkills as $userSkill) {
2465
            if ($userSkill->getSkill()->getId() !== $skill->getId()) {
2466
                continue;
2467
            }
2468
            return true;
2469
        }
2470
    }
2471
2472
    /**
2473
     * @return bool
2474
     */
2475
    public function isProfileCompleted()
2476
    {
2477
        return $this->profileCompleted;
2478
    }
2479
2480
    /**
2481
     * @param mixed $profileCompleted
2482
     * @return User
2483
     */
2484
    public function setProfileCompleted($profileCompleted)
2485
    {
2486
        $this->profileCompleted = $profileCompleted;
2487
2488
        return $this;
2489
    }
2490
2491
2492
    /**
2493
     * Sets the AccessUrl for the current user in memory
2494
     * @param AccessUrl $url
2495
     *
2496
     * @return $this
2497
     */
2498 View Code Duplication
    public function setCurrentUrl(AccessUrl $url)
2499
    {
2500
        $urlList = $this->getPortals();
2501
        /** @var AccessUrlRelUser $item */
2502
        foreach ($urlList as $item) {
2503
            if ($item->getPortal()->getId() == $url->getId()) {
2504
                $this->currentUrl = $url;
2505
                break;
2506
            }
2507
        }
2508
2509
        return $this;
2510
    }
2511
2512
    /**
2513
     * @return AccessUrl
2514
     */
2515
    public function getCurrentUrl()
2516
    {
2517
        return $this->currentUrl;
2518
    }
2519
2520
    /**
2521
     * @return mixed
2522
     */
2523
    public function getFacebookId()
2524
    {
2525
        return $this->facebookId;
2526
    }
2527
2528
    /**
2529
     * @param mixed $facebookId
2530
     */
2531
    public function setFacebookId($facebookId)
2532
    {
2533
        $this->facebookId = $facebookId;
2534
    }
2535
2536
    /**
2537
     * @return mixed
2538
     */
2539
    public function getFacebookAccessToken()
2540
    {
2541
        return $this->facebookAccessToken;
2542
    }
2543
2544
    /**
2545
     * @param mixed $facebookAccessToken
2546
     */
2547
    public function setFacebookAccessToken($facebookAccessToken)
2548
    {
2549
        $this->facebookAccessToken = $facebookAccessToken;
2550
    }
2551
2552
    /**
2553
     * @return mixed
2554
     */
2555
    public function getGoogleId()
2556
    {
2557
        return $this->googleId;
2558
    }
2559
2560
    /**
2561
     * @param mixed $googleId
2562
     */
2563
    public function setGoogleId($googleId)
2564
    {
2565
        $this->googleId = $googleId;
2566
    }
2567
2568
    /**
2569
     * @return mixed
2570
     */
2571
    public function getGoogleAccessToken()
2572
    {
2573
        return $this->googleAccessToken;
2574
    }
2575
2576
    /**
2577
     * @param mixed $googleAccessToken
2578
     */
2579
    public function setGoogleAccessToken($googleAccessToken)
2580
    {
2581
        $this->googleAccessToken = $googleAccessToken;
2582
    }
2583
2584
    /**
2585
     * @return mixed
2586
     */
2587
    public function getGithubId()
2588
    {
2589
        return $this->githubId;
2590
    }
2591
2592
    /**
2593
     * @param mixed $githubId
2594
     */
2595
    public function setGithubId($githubId)
2596
    {
2597
        $this->githubId = $githubId;
2598
    }
2599
2600
    /**
2601
     * @return mixed
2602
     */
2603
    public function getGithubAccessToken()
2604
    {
2605
        return $this->githubAccessToken;
2606
    }
2607
2608
    /**
2609
     * @param mixed $githubAccessToken
2610
     */
2611
    public function setGithubAccessToken($githubAccessToken)
2612
    {
2613
        $this->githubAccessToken = $githubAccessToken;
2614
    }
2615
2616
2617
2618
}
2619