Completed
Pull Request — 1.11.x (#1163)
by José
224:28 queued 183:17
created

User::getSlug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
/**
6
 * User Entity
7
 *
8
 * @package chamilo.User
9
 */
10
11
namespace Chamilo\UserBundle\Entity;
12
13
use Chamilo\CoreBundle\Entity\ExtraFieldValues;
14
use Chamilo\CoreBundle\Entity\UsergroupRelUser;
15
use Doctrine\Common\Collections\ArrayCollection;
16
use Doctrine\ORM\Event\LifecycleEventArgs;
17
use Doctrine\ORM\Mapping as ORM;
18
//use Sonata\UserBundle\Entity\BaseUser as BaseUser;
19
use Sonata\UserBundle\Model\User as BaseUser;
20
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
21
use Symfony\Component\HttpFoundation\File\File;
22
//use Symfony\Component\Security\Core\User\UserInterface;
23
use Symfony\Component\Validator\Constraints as Assert;
24
use Symfony\Component\Validator\Mapping\ClassMetadata;
25
use FOS\UserBundle\Model\UserInterface;
26
use FOS\UserBundle\Model\GroupInterface;
27
28
//use Chamilo\CoreBundle\Component\Auth;
29
//use FOS\MessageBundle\Model\ParticipantInterface;
30
//use Chamilo\ThemeBundle\Model\UserInterface as ThemeUser;
31
//use Vich\UploaderBundle\Mapping\Annotation as Vich;
32
//use Application\Sonata\MediaBundle\Entity\Media;
33
//use Chamilo\UserBundle\Model\UserInterface as UserInterfaceModel;
34
35
//use Sylius\Component\Attribute\Model\AttributeValueInterface as BaseAttributeValueInterface;
36
//use Sylius\Component\Variation\Model\OptionInterface as BaseOptionInterface;
37
//use Sylius\Component\Variation\Model\VariantInterface as BaseVariantInterface;
38
39
/**
40
 *
41
 * @ORM\HasLifecycleCallbacks
42
 * @ORM\Table(
43
 *  name="user",
44
 *  indexes={
45
 *      @ORM\Index(name="idx_user_uid", columns={"user_id"}),
46
 *      @ORM\Index(name="status", columns={"status"})
47
 *  }
48
 * )
49
 * @UniqueEntity("username")
50
 * @ORM\Entity(repositoryClass="Chamilo\UserBundle\Entity\Repository\UserRepository")
51
 *
52
 */
53
class User implements UserInterface //implements ParticipantInterface, ThemeUser
54
{
55
    const COURSE_MANAGER = 1;
56
    const TEACHER = 1;
57
    const SESSION_ADMIN = 3;
58
    const DRH = 4;
59
    const STUDENT = 5;
60
    const ANONYMOUS = 6;
61
62
    /**
63
     * @var integer
64
     *
65
     * @ORM\Column(name="id", type="integer")
66
     * @ORM\Id
67
     * @ORM\GeneratedValue(strategy="AUTO")
68
     */
69
    protected $id;
70
71
    /**
72
     * @var integer
73
     *
74
     * @ORM\Column(name="user_id", type="integer", nullable=true)
75
     */
76
    protected $userId;
77
78
    /**
79
     * @var string
80
     *
81
     * @ORM\Column(name="username", type="string", length=100, nullable=false, unique=true)
82
     */
83
    protected $username;
84
85
    /**
86
     * @var string
87
     *
88
     * @ORM\Column(name="username_canonical", type="string", length=100, nullable=false, unique=true)
89
     */
90
    protected $usernameCanonical;
91
92
    /**
93
     * @var string
94
     * @ORM\Column(name="email_canonical", type="string", length=100, nullable=false, unique=true)
95
     */
96
    protected $emailCanonical;
97
98
    /**
99
     * @var string
100
     *
101
     * @ORM\Column(name="email", type="string", length=100, nullable=false, unique=false)
102
     */
103
    protected $email;
104
105
    /**
106
     * @var boolean
107
     * @ORM\Column(name="locked", type="boolean")
108
     */
109
    protected $locked;
110
111
    /**
112
     * @var boolean
113
     * @ORM\Column(name="enabled", type="boolean")
114
     */
115
    protected $enabled;
116
117
    /**
118
     * @var boolean
119
     * @ORM\Column(name="expired", type="boolean")
120
     */
121
    protected $expired;
122
123
    /**
124
     * @var boolean
125
     * @ORM\Column(name="credentials_expired", type="boolean")
126
     */
127
    protected $credentialsExpired;
128
129
    /**
130
     * @var \DateTime
131
     * @ORM\Column(name="credentials_expire_at", type="datetime", nullable=true, unique=false)
132
     */
133
    protected $credentialsExpireAt;
134
135
    /**
136
     * @var \DateTime
137
     * @ORM\Column(name="expires_at", type="datetime", nullable=true, unique=false)
138
     */
139
    protected $expiresAt;
140
141
    /**
142
     * @var string
143
     *
144
     * @ORM\Column(name="lastname", type="string", length=60, nullable=true, unique=false)
145
     */
146
    protected $lastname;
147
148
    /**
149
     * @var string
150
     *
151
     * @ORM\Column(name="firstname", type="string", length=60, nullable=true, unique=false)
152
     */
153
    protected $firstname;
154
155
    /**
156
     * @var string
157
     *
158
     * @ORM\Column(name="password", type="string", length=255, nullable=false, unique=false)
159
     */
160
    protected $password;
161
162
    /**
163
     * @var string
164
     *
165
     * @ORM\Column(name="auth_source", type="string", length=50, nullable=true, unique=false)
166
     */
167
    private $authSource;
168
169
    /**
170
     * @var boolean
171
     *
172
     * @ORM\Column(name="status", type="integer", nullable=false)
173
     */
174
    private $status;
175
176
    /**
177
     * @var string
178
     *
179
     * @ORM\Column(name="official_code", type="string", length=40, nullable=true, unique=false)
180
     */
181
    private $officialCode;
182
183
    /**
184
     * @var string
185
     *
186
     * @ORM\Column(name="phone", type="string", length=30, nullable=true, unique=false)
187
     */
188
    protected $phone;
189
190
    /**
191
     * Vich\UploadableField(mapping="user_image", fileNameProperty="picture_uri")
192
     *
193
     * note This is not a mapped field of entity metadata, just a simple property.
194
     *
195
     * @var File $imageFile
196
     */
197
    protected $imageFile;
198
199
    /**
200
     * @var string
201
     * @ORM\Column(name="picture_uri", type="string", length=250, nullable=true, unique=false)
202
     */
203
    private $pictureUri;
204
205
    /**
206
     * ORM\ManyToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Media", cascade={"all"} )
207
     * @ORM\JoinColumn(name="picture_uri", referencedColumnName="id")
208
     */
209
    //protected $pictureUri;
210
211
    /**
212
     * @var integer
213
     *
214
     * @ORM\Column(name="creator_id", type="integer", nullable=true, unique=false)
215
     */
216
    private $creatorId;
217
218
    /**
219
     * @var string
220
     *
221
     * @ORM\Column(name="competences", type="text", nullable=true, unique=false)
222
     */
223
    private $competences;
224
225
    /**
226
     * @var string
227
     *
228
     * @ORM\Column(name="diplomas", type="text", nullable=true, unique=false)
229
     */
230
    private $diplomas;
231
232
    /**
233
     * @var string
234
     *
235
     * @ORM\Column(name="openarea", type="text", nullable=true, unique=false)
236
     */
237
    private $openarea;
238
239
    /**
240
     * @var string
241
     *
242
     * @ORM\Column(name="teach", type="text", nullable=true, unique=false)
243
     */
244
    private $teach;
245
246
    /**
247
     * @var string
248
     *
249
     * @ORM\Column(name="productions", type="string", length=250, nullable=true, unique=false)
250
     */
251
    private $productions;
252
253
    /**
254
     * @var integer
255
     *
256
     * @ORM\Column(name="chatcall_user_id", type="integer", nullable=true, unique=false)
257
     */
258
    private $chatcallUserId;
259
260
    /**
261
     * @var \DateTime
262
     *
263
     * @ORM\Column(name="chatcall_date", type="datetime", nullable=true, unique=false)
264
     */
265
    private $chatcallDate;
266
267
    /**
268
     * @var string
269
     *
270
     * @ORM\Column(name="chatcall_text", type="string", length=50, nullable=true, unique=false)
271
     */
272
    private $chatcallText;
273
274
    /**
275
     * @var string
276
     *
277
     * @ORM\Column(name="language", type="string", length=40, nullable=true, unique=false)
278
     */
279
    private $language;
280
281
    /**
282
     * @var \DateTime
283
     *
284
     * @ORM\Column(name="registration_date", type="datetime", nullable=false, unique=false)
285
     */
286
    private $registrationDate;
287
288
    /**
289
     * @var \DateTime
290
     *
291
     * @ORM\Column(name="expiration_date", type="datetime", nullable=true, unique=false)
292
     */
293
    private $expirationDate;
294
295
    /**
296
     * @var boolean
297
     *
298
     * @ORM\Column(name="active", type="boolean", nullable=false, unique=false)
299
     */
300
    private $active;
301
302
    /**
303
     * @var string
304
     *
305
     * @ORM\Column(name="openid", type="string", length=255, nullable=true, unique=false)
306
     */
307
    private $openid;
308
309
    /**
310
     * @var string
311
     *
312
     * @ORM\Column(name="theme", type="string", length=255, nullable=true, unique=false)
313
     */
314
    private $theme;
315
316
    /**
317
     * @var integer
318
     *
319
     * @ORM\Column(name="hr_dept_id", type="smallint", nullable=true, unique=false)
320
     */
321
    private $hrDeptId;
322
323
    /**
324
     * @ORM\Column(type="string", length=255)
325
     */
326
    protected $salt;
327
328
    /**
329
     * @var \DateTime
330
     *
331
     * @ORM\Column(name="last_login", type="datetime", nullable=true, unique=false)
332
     */
333
    protected $lastLogin;
334
335
    /**
336
     * @var \DateTime
337
     * @ORM\Column(name="created_at", type="datetime", nullable=true, unique=false)
338
     */
339
    protected $createdAt;
340
341
    /**
342
     * @var \DateTime
343
     * @ORM\Column(name="updated_at", type="datetime", nullable=true, unique=false)
344
     */
345
    protected $updatedAt;
346
347
    /**
348
     * Random string sent to the user email address in order to verify it
349
     *
350
     * @var string
351
     * @ORM\Column(name="confirmation_token", type="string", length=255, nullable=true)
352
     */
353
    protected $confirmationToken;
354
355
    /**
356
     * @var \DateTime
357
     *
358
     * @ORM\Column(name="password_requested_at", type="datetime", nullable=true, unique=false)
359
     */
360
    protected $passwordRequestedAt;
361
362
363
364
    /**
365
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CourseRelUser", mappedBy="user")
366
     **/
367
    protected $courses;
368
369
    /**
370
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CItemProperty", mappedBy="user")
371
     **/
372
    //protected $items;
373
374
    /**
375
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\UsergroupRelUser", mappedBy="user")
376
     **/
377
    protected $classes;
378
379
    /**
380
     * ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CDropboxPost", mappedBy="user")
381
     **/
382
    protected $dropBoxReceivedFiles;
383
384
    /**
385
     * ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CDropboxFile", mappedBy="userSent")
386
     **/
387
    protected $dropBoxSentFiles;
388
389
    /**
390
     * @ORM\Column(type="array")
391
     */
392
    protected $roles;
393
394
    /**
395
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\JuryMembers", mappedBy="user")
396
     **/
397
    //protected $jurySubscriptions;
398
399
    /**
400
     * @ORM\ManyToMany(targetEntity="Chamilo\UserBundle\Entity\Group")
401
     * @ORM\JoinTable(name="fos_user_user_group",
402
     *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
403
     *      inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
404
     * )
405
     */
406
    protected $groups;
407
408
409
    //private $isActive;
410
411
    /**
412
     * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CurriculumItemRelUser", mappedBy="user")
413
     **/
414
    protected $curriculumItems;
415
416
    /*
417
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelUser", mappedBy="user")
418
     *
419
     */
420
    protected $portals;
421
422
    /**
423
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Session", mappedBy="generalCoach")
424
     **/
425
    protected $sessionAsGeneralCoach;
426
427
    /**
428
     * @var ArrayCollection
429
     * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\UserFieldValues", mappedBy="user", orphanRemoval=true, cascade={"persist"})
430
     **/
431
    protected $extraFields;
432
433
    /**
434
     * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", mappedBy="creator")
435
     **/
436
    protected $resourceNodes;
437
438
    /**
439
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SessionRelCourseRelUser", mappedBy="user", cascade={"persist"})
440
     **/
441
    protected $sessionCourseSubscriptions;
442
443
    /**
444
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SkillRelUser", mappedBy="user", cascade={"persist"})
445
     */
446
    protected $achievedSkills;
447
448
    /**
449
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SkillRelUserComment", mappedBy="feedbackGiver")
450
     */
451
    protected $commentedUserSkills;
452
453
    /**
454
     * Constructor
455
     */
456
    public function __construct()
457
    {
458
        $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...
459
460
        $this->salt = sha1(uniqid(null, true));
461
        $this->isActive = true;
462
        $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...
463
        $this->registrationDate = new \DateTime();
464
        $this->authSource = 'platform';
465
        $this->courses = new ArrayCollection();
466
        $this->items = new ArrayCollection();
467
        $this->classes = new ArrayCollection();
468
        $this->curriculumItems = new ArrayCollection();
469
        $this->portals = new ArrayCollection();
470
        $this->dropBoxSentFiles = new ArrayCollection();
471
        $this->dropBoxReceivedFiles = new ArrayCollection();
472
        $this->chatcallUserId = 0;
473
        //$this->extraFields = new ArrayCollection();
474
        //$this->userId = 0;
475
        //$this->createdAt = new \DateTime();
476
        //$this->updatedAt = new \DateTime();
477
478
        $this->enabled = false;
479
        $this->locked = false;
480
        $this->expired = false;
481
        $this->roles = array();
482
        $this->credentialsExpired = false;
483
    }
484
485
    /**
486
     * @return string
487
     */
488
    public function __toString()
489
    {
490
        return $this->getUsername();
491
    }
492
493
    /**
494
     * Updates the id with the user_id
495
     *  @ORM\PostPersist()
496
     */
497
    public function postPersist(LifecycleEventArgs $args)
498
    {
499
        //parent::postPersist();
500
        // Updates the user_id field
501
        $user = $args->getEntity();
502
        $this->setUserId($user->getId());
503
        /*$em = $args->getEntityManager();
504
        $em->persist($user);
505
        $em->flush();*/
506
    }
507
508
    /**
509
     * @param int $userId
510
     */
511
    public function setId($userId)
512
    {
513
        $this->id = $userId;
514
    }
515
516
    /**
517
     * @param int $userId
518
     */
519
    public function setUserId($userId)
520
    {
521
        if (!empty($userId)) {
522
            $this->userId = $userId;
523
        }
524
    }
525
526
    /**
527
     * @return int
528
     */
529
    public function getId()
530
    {
531
        return $this->id;
532
    }
533
534
    /**
535
     * @return string
536
     */
537
    public function getEncoderName()
538
    {
539
        return "legacy_encoder";
540
    }
541
542
    /**
543
     * @return ArrayCollection
544
     */
545
    public function getDropBoxSentFiles()
546
    {
547
        return $this->dropBoxSentFiles;
548
    }
549
550
    /**
551
     * @return ArrayCollection
552
     */
553
    public function getDropBoxReceivedFiles()
554
    {
555
        return $this->dropBoxReceivedFiles;
556
    }
557
558
    /**
559
     * @return ArrayCollection
560
     */
561
    public function getCourses()
562
    {
563
        return $this->courses;
564
    }
565
566
    /**
567
     * @return array
568
     */
569 View Code Duplication
    public static function getPasswordConstraints()
570
    {
571
        return
572
            array(
573
                new Assert\Length(array('min' => 5)),
574
                // Alpha numeric + "_" or "-"
575
                new Assert\Regex(array(
576
                        'pattern' => '/^[a-z\-_0-9]+$/i',
577
                        'htmlPattern' => '/^[a-z\-_0-9]+$/i')
578
                ),
579
                // Min 3 letters - not needed
580
                /*new Assert\Regex(array(
581
                    'pattern' => '/[a-z]{3}/i',
582
                    'htmlPattern' => '/[a-z]{3}/i')
583
                ),*/
584
                // Min 2 numbers
585
                new Assert\Regex(array(
586
                        'pattern' => '/[0-9]{2}/',
587
                        'htmlPattern' => '/[0-9]{2}/')
588
                ),
589
            )
590
            ;
591
    }
592
593
    /**
594
     * @param ClassMetadata $metadata
595
     */
596
    public static function loadValidatorMetadata(ClassMetadata $metadata)
597
    {
598
        //$metadata->addPropertyConstraint('firstname', new Assert\NotBlank());
599
        //$metadata->addPropertyConstraint('lastname', new Assert\NotBlank());
600
        //$metadata->addPropertyConstraint('email', new Assert\Email());
601
        /*
602
        $metadata->addPropertyConstraint('password',
603
            new Assert\Collection(self::getPasswordConstraints())
604
        );*/
605
606
        /*$metadata->addConstraint(new UniqueEntity(array(
607
            'fields'  => 'username',
608
            'message' => 'This value is already used.',
609
        )));*/
610
611
        /*$metadata->addPropertyConstraint(
612
            'username',
613
            new Assert\Length(array(
614
                'min'        => 2,
615
                'max'        => 50,
616
                '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.',
617
                '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.',
618
            ))
619
        );*/
620
    }
621
622
    /**
623
     * @inheritDoc
624
     */
625
    public function isEqualTo(UserInterface $user)
626
    {
627
        if (!$user instanceof User) {
628
            return false;
629
        }
630
631
        /*if ($this->password !== $user->getPassword()) {
632
            return false;
633
        }*/
634
635
        /*if ($this->getSalt() !== $user->getSalt()) {
636
            return false;
637
        }*/
638
639
        /*if ($this->username !== $user->getUsername()) {
640
            return false;
641
        }*/
642
643
        return true;
644
    }
645
646
    /**
647
     * @return ArrayCollection
648
     */
649
    public function getPortals()
650
    {
651
        return $this->portals;
652
    }
653
654
    /**
655
     * @param $portal
656
     */
657
    public function setPortal($portal)
658
    {
659
        $this->portals->add($portal);
660
    }
661
662
    /**
663
     * @return ArrayCollection
664
     */
665
    public function getCurriculumItems()
666
    {
667
        return $this->curriculumItems;
668
    }
669
670
    /**
671
     * @param $items
672
     */
673
    public function setCurriculumItems($items)
674
    {
675
        $this->curriculumItems = $items;
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
    /**
696
     * @inheritDoc
697
     */
698
    public function isEnabled()
699
    {
700
        return $this->getActive() == 1;
701
    }
702
703
    /**
704
     *
705
     * @return ArrayCollection
706
     */
707
    /*public function getRolesObj()
708
    {
709
        return $this->roles;
710
    }*/
711
712
    /**
713
     * Set salt
714
     *
715
     * @param string $salt
716
     *
717
     * @return User
718
     */
719
    public function setSalt($salt)
720
    {
721
        $this->salt = $salt;
722
723
        return $this;
724
    }
725
726
    /**
727
     * Get salt
728
     *
729
     * @return string
730
     */
731
    public function getSalt()
732
    {
733
        return $this->salt;
734
    }
735
736
    /**
737
     * @return ArrayCollection
738
     */
739
    public function getClasses()
740
    {
741
        return $this->classes;
742
    }
743
744
    /**
745
     *
746
     */
747
    public function getLps()
748
    {
749
        //return $this->lps;
750
        /*$criteria = Criteria::create()
751
            ->where(Criteria::expr()->eq("id", "666"))
752
            //->orderBy(array("username" => "ASC"))
753
            //->setFirstResult(0)
754
            //->setMaxResults(20)
755
        ;
756
        $lps = $this->lps->matching($criteria);*/
757
        /*return $this->lps->filter(
758
            function($entry) use ($idsToFilter) {
759
                return $entry->getId() == 1;
760
        });*/
761
    }
762
763
    /**
764
     * Return Complete Name with the Username
765
     *
766
     * @return string
767
     */
768
    public function getCompleteNameWithUsername()
769
    {
770
        return api_get_person_name($this->firstname, $this->lastname).' ('.$this->username.')';
771
    }
772
773
    /**
774
     * @todo don't use api_get_person_name
775
     * @return string
776
     */
777
    public function getCompleteName()
778
    {
779
        return api_get_person_name($this->firstname, $this->lastname);
780
    }
781
782
    /**
783
     * Returns the list of classes for the user
784
     * @return string
785
     */
786 View Code Duplication
    public function getCompleteNameWithClasses()
787
    {
788
        $classSubscription = $this->getClasses();
789
        $classList = array();
790
        /** @var UsergroupRelUser $subscription */
791
        foreach ($classSubscription as $subscription) {
792
            $class = $subscription->getUsergroup();
793
            $classList[] = $class->getName();
794
        }
795
        $classString = !empty($classList) ? ' ['.implode(', ', $classList).']' : null;
796
797
        return $this->getCompleteName().$classString;
798
    }
799
800
    /**
801
     * Get userId
802
     *
803
     * @return integer
804
     */
805
    public function getUserId()
806
    {
807
        return $this->userId;
808
    }
809
810
    /**
811
     * Set lastname
812
     *
813
     * @param string $lastname
814
     *
815
     * @return User
816
     */
817
    public function setLastname($lastname)
818
    {
819
        $this->lastname = $lastname;
820
821
        return $this;
822
    }
823
824
825
    /**
826
     * Set firstname
827
     *
828
     * @param string $firstname
829
     *
830
     * @return User
831
     */
832
    public function setFirstname($firstname)
833
    {
834
        $this->firstname = $firstname;
835
836
        return $this;
837
    }
838
839
    /**
840
     * Set password
841
     *
842
     * @param string $password
843
     * @return User
844
     */
845
    public function setPassword($password)
846
    {
847
        $this->password = $password;
848
849
        return $this;
850
    }
851
852
    /**
853
     * Get password
854
     *
855
     * @return string
856
     */
857
    public function getPassword()
858
    {
859
        return $this->password;
860
    }
861
862
    /**
863
     * Set authSource
864
     *
865
     * @param string $authSource
866
     * @return User
867
     */
868
    public function setAuthSource($authSource)
869
    {
870
        $this->authSource = $authSource;
871
872
        return $this;
873
    }
874
875
    /**
876
     * Get authSource
877
     *
878
     * @return string
879
     */
880
    public function getAuthSource()
881
    {
882
        return $this->authSource;
883
    }
884
885
    /**
886
     * Set email
887
     *
888
     * @param string $email
889
     * @return User
890
     */
891
    public function setEmail($email)
892
    {
893
        $this->email = $email;
894
895
        return $this;
896
    }
897
898
    /**
899
     * Get email
900
     *
901
     * @return string
902
     */
903
    public function getEmail()
904
    {
905
        return $this->email;
906
    }
907
908
    /**
909
     * Set status
910
     *
911
     * @param int $status
912
     *
913
     * @return User
914
     */
915
    public function setStatus($status)
916
    {
917
        $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...
918
919
        return $this;
920
    }
921
922
    /**
923
     * Get status
924
     *
925
     * @return boolean
926
     */
927
    public function getStatus()
928
    {
929
        return $this->status;
930
    }
931
932
    /**
933
     * Set officialCode
934
     *
935
     * @param string $officialCode
936
     * @return User
937
     */
938
    public function setOfficialCode($officialCode)
939
    {
940
        $this->officialCode = $officialCode;
941
942
        return $this;
943
    }
944
945
    /**
946
     * Get officialCode
947
     *
948
     * @return string
949
     */
950
    public function getOfficialCode()
951
    {
952
        return $this->officialCode;
953
    }
954
955
    /**
956
     * Set phone
957
     *
958
     * @param string $phone
959
     * @return User
960
     */
961
    public function setPhone($phone)
962
    {
963
        $this->phone = $phone;
964
965
        return $this;
966
    }
967
968
    /**
969
     * Get phone
970
     *
971
     * @return string
972
     */
973
    public function getPhone()
974
    {
975
        return $this->phone;
976
    }
977
978
    /**
979
     * Set pictureUri
980
     *
981
     * @param string $pictureUri
982
     * @return User
983
     */
984
    public function setPictureUri($pictureUri)
985
    {
986
        $this->pictureUri = $pictureUri;
987
988
        return $this;
989
    }
990
991
    /**
992
     * Get pictureUri
993
     *
994
     * @return Media
995
     */
996
    public function getPictureUri()
997
    {
998
        return $this->pictureUri;
999
    }
1000
1001
    /**
1002
     * Set creatorId
1003
     *
1004
     * @param integer $creatorId
1005
     * @return User
1006
     */
1007
    public function setCreatorId($creatorId)
1008
    {
1009
        $this->creatorId = $creatorId;
1010
1011
        return $this;
1012
    }
1013
1014
    /**
1015
     * Get creatorId
1016
     *
1017
     * @return integer
1018
     */
1019
    public function getCreatorId()
1020
    {
1021
        return $this->creatorId;
1022
    }
1023
1024
    /**
1025
     * Set competences
1026
     *
1027
     * @param string $competences
1028
     * @return User
1029
     */
1030
    public function setCompetences($competences)
1031
    {
1032
        $this->competences = $competences;
1033
1034
        return $this;
1035
    }
1036
1037
    /**
1038
     * Get competences
1039
     *
1040
     * @return string
1041
     */
1042
    public function getCompetences()
1043
    {
1044
        return $this->competences;
1045
    }
1046
1047
    /**
1048
     * Set diplomas
1049
     *
1050
     * @param string $diplomas
1051
     * @return User
1052
     */
1053
    public function setDiplomas($diplomas)
1054
    {
1055
        $this->diplomas = $diplomas;
1056
1057
        return $this;
1058
    }
1059
1060
    /**
1061
     * Get diplomas
1062
     *
1063
     * @return string
1064
     */
1065
    public function getDiplomas()
1066
    {
1067
        return $this->diplomas;
1068
    }
1069
1070
    /**
1071
     * Set openarea
1072
     *
1073
     * @param string $openarea
1074
     * @return User
1075
     */
1076
    public function setOpenarea($openarea)
1077
    {
1078
        $this->openarea = $openarea;
1079
1080
        return $this;
1081
    }
1082
1083
    /**
1084
     * Get openarea
1085
     *
1086
     * @return string
1087
     */
1088
    public function getOpenarea()
1089
    {
1090
        return $this->openarea;
1091
    }
1092
1093
    /**
1094
     * Set teach
1095
     *
1096
     * @param string $teach
1097
     * @return User
1098
     */
1099
    public function setTeach($teach)
1100
    {
1101
        $this->teach = $teach;
1102
1103
        return $this;
1104
    }
1105
1106
    /**
1107
     * Get teach
1108
     *
1109
     * @return string
1110
     */
1111
    public function getTeach()
1112
    {
1113
        return $this->teach;
1114
    }
1115
1116
    /**
1117
     * Set productions
1118
     *
1119
     * @param string $productions
1120
     * @return User
1121
     */
1122
    public function setProductions($productions)
1123
    {
1124
        $this->productions = $productions;
1125
1126
        return $this;
1127
    }
1128
1129
    /**
1130
     * Get productions
1131
     *
1132
     * @return string
1133
     */
1134
    public function getProductions()
1135
    {
1136
        return $this->productions;
1137
    }
1138
1139
    /**
1140
     * Set chatcallUserId
1141
     *
1142
     * @param integer $chatcallUserId
1143
     * @return User
1144
     */
1145
    public function setChatcallUserId($chatcallUserId)
1146
    {
1147
        $this->chatcallUserId = $chatcallUserId;
1148
1149
        return $this;
1150
    }
1151
1152
    /**
1153
     * Get chatcallUserId
1154
     *
1155
     * @return integer
1156
     */
1157
    public function getChatcallUserId()
1158
    {
1159
        return $this->chatcallUserId;
1160
    }
1161
1162
    /**
1163
     * Set chatcallDate
1164
     *
1165
     * @param \DateTime $chatcallDate
1166
     * @return User
1167
     */
1168
    public function setChatcallDate($chatcallDate)
1169
    {
1170
        $this->chatcallDate = $chatcallDate;
1171
1172
        return $this;
1173
    }
1174
1175
    /**
1176
     * Get chatcallDate
1177
     *
1178
     * @return \DateTime
1179
     */
1180
    public function getChatcallDate()
1181
    {
1182
        return $this->chatcallDate;
1183
    }
1184
1185
    /**
1186
     * Set chatcallText
1187
     *
1188
     * @param string $chatcallText
1189
     * @return User
1190
     */
1191
    public function setChatcallText($chatcallText)
1192
    {
1193
        $this->chatcallText = $chatcallText;
1194
1195
        return $this;
1196
    }
1197
1198
    /**
1199
     * Get chatcallText
1200
     *
1201
     * @return string
1202
     */
1203
    public function getChatcallText()
1204
    {
1205
        return $this->chatcallText;
1206
    }
1207
1208
    /**
1209
     * Set language
1210
     *
1211
     * @param string $language
1212
     * @return User
1213
     */
1214
    public function setLanguage($language)
1215
    {
1216
        $this->language = $language;
1217
1218
        return $this;
1219
    }
1220
1221
    /**
1222
     * Get language
1223
     *
1224
     * @return string
1225
     */
1226
    public function getLanguage()
1227
    {
1228
        return $this->language;
1229
    }
1230
1231
    /**
1232
     * Set registrationDate
1233
     *
1234
     * @param \DateTime $registrationDate
1235
     * @return User
1236
     */
1237
    public function setRegistrationDate($registrationDate)
1238
    {
1239
        $this->registrationDate = $registrationDate;
1240
1241
        return $this;
1242
    }
1243
1244
    /**
1245
     * Get registrationDate
1246
     *
1247
     * @return \DateTime
1248
     */
1249
    public function getRegistrationDate()
1250
    {
1251
        return $this->registrationDate;
1252
    }
1253
1254
    /**
1255
     * Set expirationDate
1256
     *
1257
     * @param \DateTime $expirationDate
1258
     *
1259
     * @return User
1260
     */
1261
    public function setExpirationDate($expirationDate)
1262
    {
1263
        $this->expirationDate = $expirationDate;
1264
1265
        return $this;
1266
    }
1267
1268
    /**
1269
     * Get expirationDate
1270
     *
1271
     * @return \DateTime
1272
     */
1273
    public function getExpirationDate()
1274
    {
1275
        return $this->expirationDate;
1276
    }
1277
1278
    /**
1279
     * Set active
1280
     *
1281
     * @param boolean $active
1282
     * @return User
1283
     */
1284
    public function setActive($active)
1285
    {
1286
        $this->active = $active;
1287
1288
        return $this;
1289
    }
1290
1291
    /**
1292
     * Get active
1293
     *
1294
     * @return boolean
1295
     */
1296
    public function getActive()
1297
    {
1298
        return $this->active;
1299
    }
1300
1301
    /**
1302
     * Set openid
1303
     *
1304
     * @param string $openid
1305
     * @return User
1306
     */
1307
    public function setOpenid($openid)
1308
    {
1309
        $this->openid = $openid;
1310
1311
        return $this;
1312
    }
1313
1314
    /**
1315
     * Get openid
1316
     *
1317
     * @return string
1318
     */
1319
    public function getOpenid()
1320
    {
1321
        return $this->openid;
1322
    }
1323
1324
    /**
1325
     * Set theme
1326
     *
1327
     * @param string $theme
1328
     * @return User
1329
     */
1330
    public function setTheme($theme)
1331
    {
1332
        $this->theme = $theme;
1333
1334
        return $this;
1335
    }
1336
1337
    /**
1338
     * Get theme
1339
     *
1340
     * @return string
1341
     */
1342
    public function getTheme()
1343
    {
1344
        return $this->theme;
1345
    }
1346
1347
    /**
1348
     * Set hrDeptId
1349
     *
1350
     * @param integer $hrDeptId
1351
     * @return User
1352
     */
1353
    public function setHrDeptId($hrDeptId)
1354
    {
1355
        $this->hrDeptId = $hrDeptId;
1356
1357
        return $this;
1358
    }
1359
1360
    /**
1361
     * Get hrDeptId
1362
     *
1363
     * @return integer
1364
     */
1365
    public function getHrDeptId()
1366
    {
1367
        return $this->hrDeptId;
1368
    }
1369
1370
    /**
1371
     * @return Media
1372
     */
1373
    public function getAvatar()
1374
    {
1375
        return $this->getPictureUri();
1376
    }
1377
1378
    /**
1379
     * @return \DateTime
1380
     */
1381
    public function getMemberSince()
1382
    {
1383
        return $this->registrationDate;
1384
    }
1385
1386
    /**
1387
     * @return bool
1388
     */
1389
    public function isOnline()
1390
    {
1391
        return false;
1392
    }
1393
1394
    /**
1395
     * @return int
1396
     */
1397
    public function getIdentifier()
1398
    {
1399
        return $this->getId();
1400
    }
1401
1402
    /**
1403
     * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
1404
     * of 'UploadedFile' is injected into this setter to trigger the  update. If this
1405
     * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
1406
     * must be able to accept an instance of 'File' as the bundle will inject one here
1407
     * during Doctrine hydration.
1408
     *
1409
     * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
1410
     */
1411
    public function setImageFile(File $image)
1412
    {
1413
        $this->imageFile = $image;
1414
1415
        if ($image) {
1416
            // It is required that at least one field changes if you are using doctrine
1417
            // otherwise the event listeners won't be called and the file is lost
1418
            $this->updatedAt = new \DateTime('now');
1419
        }
1420
    }
1421
1422
    /**
1423
     * @return File
1424
     */
1425
    public function getImageFile()
1426
    {
1427
        return $this->imageFile;
1428
    }
1429
1430
    /**
1431
     * @param string $imageName
1432
     */
1433
    public function setImageName($imageName)
1434
    {
1435
        $this->imageName = $imageName;
1436
    }
1437
1438
    /**
1439
     * @return string
1440
     */
1441
    public function getImageName()
1442
    {
1443
        return $this->imageName;
1444
    }
1445
1446
    /**
1447
     * @return string
1448
     */
1449
    public function getSlug()
1450
    {
1451
        return $this->getUsername();
1452
    }
1453
1454
    /**
1455
     * @param $slug
1456
     * @return User
1457
     */
1458
    public function setSlug($slug)
1459
    {
1460
        return $this->setUsername($slug);
1461
    }
1462
1463
    /**
1464
     * Set lastLogin
1465
     *
1466
     * @param \DateTime $lastLogin
1467
     *
1468
     * @return User
1469
     */
1470
    public function setLastLogin(\DateTime $lastLogin)
1471
    {
1472
        $this->lastLogin = $lastLogin;
1473
1474
        return $this;
1475
    }
1476
1477
    /**
1478
     * Get lastLogin
1479
     *
1480
     * @return \DateTime
1481
     */
1482
    public function getLastLogin()
1483
    {
1484
        return $this->lastLogin;
1485
    }
1486
1487
    /**
1488
     * {@inheritdoc}
1489
     */
1490
    public function getExtraFields()
1491
    {
1492
        return $this->extraFields;
1493
    }
1494
1495
    /**
1496
     * {@inheritdoc}
1497
     */
1498
    public function setExtraFields($extraFields)
1499
    {
1500
        $this->extraFields = new ArrayCollection();
1501
        foreach ($extraFields as $extraField) {
1502
            $this->addExtraFields($extraField);
1503
        }
1504
1505
        return $this;
1506
    }
1507
1508
    /**
1509
     * {@inheritdoc}
1510
     */
1511
    /*public function addExtraFields(ExtraFieldValues $extraFieldValue)
1512
    {
1513
        $extraFieldValue->setUser($this);
1514
        $this->extraFields[] = $extraFieldValue;
1515
1516
        return $this;
1517
    }*/
1518
1519
    /**
1520
     * {@inheritdoc}
1521
     */
1522
    public function addExtraFields(ExtraFieldValues $extraFieldValue)
1523
    {
1524
        //if (!$this->hasExtraField($attribute)) {
1525
        $extraFieldValue->setUser($this);
1526
        $this->extraFields[] = $extraFieldValue;
1527
        //}
1528
1529
        return $this;
1530
    }
1531
1532
    /**
1533
     * {@inheritdoc}
1534
     */
1535
    public function removeExtraField(ExtraFieldValues $attribute)
1536
    {
1537
        //if ($this->hasExtraField($attribute)) {
1538
            //$this->extraFields->removeElement($attribute);
1539
            //$attribute->setUser($this);
1540
        //}
1541
1542
        return $this;
1543
    }
1544
1545
    /**
1546
     * {@inheritdoc}
1547
     */
1548
    /*public function hasExtraField($attribute)
1549
    {
1550
        if (!$this->extraFields) {
1551
            return false;
1552
        }
1553
        return $this->extraFields->contains($attribute);
1554
    }*/
1555
1556
    /**
1557
     * {@inheritdoc}
1558
     */
1559
    public function hasExtraFieldByName($attributeName)
1560
    {
1561
        foreach ($this->extraFields as $attribute) {
1562
            if ($attribute->getName() === $attributeName) {
1563
                return true;
1564
            }
1565
        }
1566
1567
        return false;
1568
    }
1569
1570
    /**
1571
     * {@inheritdoc}
1572
     */
1573
    public function getExtraFieldByName($attributeName)
1574
    {
1575
        foreach ($this->extraFields as $attribute) {
1576
            if ($attribute->getName() === $attributeName) {
1577
                return $attribute;
1578
            }
1579
        }
1580
1581
        return null;
1582
    }
1583
1584
    /**
1585
     * Get sessionCourseSubscription
1586
     * @return ArrayCollection
1587
     */
1588
    public function getSessionCourseSubscriptions()
1589
    {
1590
        return $this->sessionCourseSubscriptions;
1591
    }
1592
1593
    /**
1594
     * @return string
1595
     */
1596
    public function getConfirmationToken()
1597
    {
1598
        return $this->confirmationToken;
1599
    }
1600
1601
    /**
1602
     * @param string $confirmationToken
1603
     *
1604
     * @return User
1605
     */
1606
    public function setConfirmationToken($confirmationToken)
1607
    {
1608
        $this->confirmationToken = $confirmationToken;
1609
1610
        return $this;
1611
    }
1612
1613
    /**
1614
     * @return \DateTime
1615
     */
1616
    public function getPasswordRequestedAt()
1617
    {
1618
        return $this->passwordRequestedAt;
1619
    }
1620
1621
1622
    /**
1623
     * @param int $ttl
1624
     * @return bool
1625
     */
1626
    public function isPasswordRequestNonExpired($ttl)
1627
    {
1628
        return $this->getPasswordRequestedAt() instanceof \DateTime &&
1629
        $this->getPasswordRequestedAt()->getTimestamp() + $ttl > time();
1630
    }
1631
1632
    public function getUsername()
1633
    {
1634
        return $this->username;
1635
    }
1636
1637
    /**
1638
     * Returns the creation date.
1639
     *
1640
     * @return \DateTime|null
1641
     */
1642
    public function getCreatedAt()
1643
    {
1644
        return $this->createdAt;
1645
    }
1646
1647
    /**
1648
     * Sets the last update date.
1649
     *
1650
     * @param \DateTime|null $updatedAt
1651
     *
1652
     * @return User
1653
     */
1654
    public function setUpdatedAt(\DateTime $updatedAt = null)
1655
    {
1656
        $this->updatedAt = $updatedAt;
1657
1658
        return $this;
1659
    }
1660
1661
    /**
1662
     * Returns the last update date.
1663
     *
1664
     * @return \DateTime|null
1665
     */
1666
    public function getUpdatedAt()
1667
    {
1668
        return $this->updatedAt;
1669
    }
1670
1671
    /**
1672
     * Returns the expiration date.
1673
     *
1674
     * @return \DateTime|null
1675
     */
1676
    public function getExpiresAt()
1677
    {
1678
        return $this->expiresAt;
1679
    }
1680
1681
    /**
1682
     * Returns the credentials expiration date.
1683
     *
1684
     * @return \DateTime
1685
     */
1686
    public function getCredentialsExpireAt()
1687
    {
1688
        return $this->credentialsExpireAt;
1689
    }
1690
1691
    /**
1692
     * Sets the credentials expiration date.
1693
     *
1694
     * @param \DateTime|null $date
1695
     *
1696
     * @return User
1697
     */
1698
    public function setCredentialsExpireAt(\DateTime $date = null)
1699
    {
1700
        $this->credentialsExpireAt = $date;
1701
1702
        return $this;
1703
    }
1704
1705
    /**
1706
     * Sets the user groups.
1707
     *
1708
     * @param array $groups
1709
     *
1710
     * @return User
1711
     */
1712
    public function setGroups($groups)
1713
    {
1714
        foreach ($groups as $group) {
1715
            $this->addGroup($group);
1716
        }
1717
1718
        return $this;
1719
    }
1720
1721
    /**
1722
     * Sets the two-step verification code.
1723
     *
1724
     * @param string $twoStepVerificationCode
1725
     *
1726
     * @return User
1727
     */
1728
    public function setTwoStepVerificationCode($twoStepVerificationCode)
1729
    {
1730
        $this->twoStepVerificationCode = $twoStepVerificationCode;
1731
1732
        return $this;
1733
    }
1734
1735
    /**
1736
     * Returns the two-step verification code.
1737
     *
1738
     * @return string
1739
     */
1740
    public function getTwoStepVerificationCode()
1741
    {
1742
        return $this->twoStepVerificationCode;
1743
    }
1744
1745
    /**
1746
     * @param string $biography
1747
     *
1748
     * @return User
1749
     */
1750
    public function setBiography($biography)
1751
    {
1752
        $this->biography = $biography;
1753
1754
        return $this;
1755
    }
1756
1757
    /**
1758
     * @return string
1759
     */
1760
    public function getBiography()
1761
    {
1762
        return $this->biography;
1763
    }
1764
1765
    /**
1766
     * @param \DateTime $dateOfBirth
1767
     *
1768
     * @return User
1769
     */
1770
    public function setDateOfBirth($dateOfBirth)
1771
    {
1772
        $this->dateOfBirth = $dateOfBirth;
1773
1774
        return $this;
1775
    }
1776
1777
    /**
1778
     * @return \DateTime
1779
     */
1780
    public function getDateOfBirth()
1781
    {
1782
        return $this->dateOfBirth;
1783
    }
1784
1785
    /**
1786
     * @param string $facebookData
1787
     *
1788
     * @return User
1789
     */
1790
    public function setFacebookData($facebookData)
1791
    {
1792
        $this->facebookData = $facebookData;
1793
1794
        return $this;
1795
    }
1796
1797
    /**
1798
     * @return string
1799
     */
1800
    public function getFacebookData()
1801
    {
1802
        return $this->facebookData;
1803
    }
1804
1805
    /**
1806
     * @param string $facebookName
1807
     *
1808
     * @return User
1809
     */
1810
    public function setFacebookName($facebookName)
1811
    {
1812
        $this->facebookName = $facebookName;
1813
1814
        return $this;
1815
    }
1816
1817
    /**
1818
     * @return string
1819
     */
1820
    public function getFacebookName()
1821
    {
1822
        return $this->facebookName;
1823
    }
1824
1825
    /**
1826
     * @param string $facebookUid
1827
     *
1828
     * @return User
1829
     */
1830
    public function setFacebookUid($facebookUid)
1831
    {
1832
        $this->facebookUid = $facebookUid;
1833
1834
        return $this;
1835
    }
1836
1837
    /**
1838
     * @return string
1839
     */
1840
    public function getFacebookUid()
1841
    {
1842
        return $this->facebookUid;
1843
    }
1844
1845
    /**
1846
     * @return string
1847
     */
1848
    public function getFirstname()
1849
    {
1850
        return $this->firstname;
1851
    }
1852
1853
    /**
1854
     * @param string $gender
1855
     *
1856
     * @return User
1857
     */
1858
    public function setGender($gender)
1859
    {
1860
        $this->gender = $gender;
1861
1862
        return $this;
1863
    }
1864
1865
    /**
1866
     * @return string
1867
     */
1868
    public function getGender()
1869
    {
1870
        return $this->gender;
1871
    }
1872
1873
    /**
1874
     * @param string $gplusData
1875
     *
1876
     * @return User
1877
     */
1878
    public function setGplusData($gplusData)
1879
    {
1880
        $this->gplusData = $gplusData;
1881
1882
        return $this;
1883
    }
1884
1885
    /**
1886
     * @return string
1887
     */
1888
    public function getGplusData()
1889
    {
1890
        return $this->gplusData;
1891
    }
1892
1893
    /**
1894
     * @param string $gplusName
1895
     *
1896
     * @return User
1897
     */
1898
    public function setGplusName($gplusName)
1899
    {
1900
        $this->gplusName = $gplusName;
1901
1902
        return $this;
1903
    }
1904
1905
    /**
1906
     * @return string
1907
     */
1908
    public function getGplusName()
1909
    {
1910
        return $this->gplusName;
1911
    }
1912
1913
    /**
1914
     * @param string $gplusUid
1915
     *
1916
     * @return User
1917
     */
1918
    public function setGplusUid($gplusUid)
1919
    {
1920
        $this->gplusUid = $gplusUid;
1921
1922
        return $this;
1923
    }
1924
1925
    /**
1926
     * @return string
1927
     */
1928
    public function getGplusUid()
1929
    {
1930
        return $this->gplusUid;
1931
    }
1932
1933
1934
    /**
1935
     * @return string
1936
     */
1937
    public function getLastname()
1938
    {
1939
        return $this->lastname;
1940
    }
1941
1942
    /**
1943
     * @param string $locale
1944
     *
1945
     * @return User
1946
     */
1947
    public function setLocale($locale)
1948
    {
1949
        $this->locale = $locale;
1950
1951
        return $this;
1952
    }
1953
1954
    /**
1955
     * @return string
1956
     */
1957
    public function getLocale()
1958
    {
1959
        return $this->locale;
1960
    }
1961
1962
     /**
1963
     * @param string $timezone
1964
     *
1965
     * @return User
1966
     */
1967
    public function setTimezone($timezone)
1968
    {
1969
        $this->timezone = $timezone;
1970
1971
        return $this;
1972
    }
1973
1974
    /**
1975
     * @return string
1976
     */
1977
    public function getTimezone()
1978
    {
1979
        return $this->timezone;
1980
    }
1981
1982
    /**
1983
     * @param string $twitterData
1984
     *
1985
     * @return User
1986
     */
1987
    public function setTwitterData($twitterData)
1988
    {
1989
        $this->twitterData = $twitterData;
1990
1991
        return $this;
1992
    }
1993
1994
    /**
1995
     * @return string
1996
     */
1997
    public function getTwitterData()
1998
    {
1999
        return $this->twitterData;
2000
    }
2001
2002
    /**
2003
     * @param string $twitterName
2004
     *
2005
     * @return User
2006
     */
2007
    public function setTwitterName($twitterName)
2008
    {
2009
        $this->twitterName = $twitterName;
2010
2011
        return $this;
2012
    }
2013
2014
    /**
2015
     * @return string
2016
     */
2017
    public function getTwitterName()
2018
    {
2019
        return $this->twitterName;
2020
    }
2021
2022
    /**
2023
     * @param string $twitterUid
2024
     *
2025
     * @return User
2026
     */
2027
    public function setTwitterUid($twitterUid)
2028
    {
2029
        $this->twitterUid = $twitterUid;
2030
2031
        return $this;
2032
    }
2033
2034
    /**
2035
     * @return string
2036
     */
2037
    public function getTwitterUid()
2038
    {
2039
        return $this->twitterUid;
2040
    }
2041
2042
    /**
2043
     * @param string $website
2044
     *
2045
     * @return User
2046
     */
2047
    public function setWebsite($website)
2048
    {
2049
        $this->website = $website;
2050
2051
        return $this;
2052
    }
2053
2054
    /**
2055
     * @return string
2056
     */
2057
    public function getWebsite()
2058
    {
2059
        return $this->website;
2060
    }
2061
2062
    /**
2063
     * @param string $token
2064
     *
2065
     * @return User
2066
     */
2067
    public function setToken($token)
2068
    {
2069
        $this->token = $token;
2070
2071
        return $this;
2072
    }
2073
2074
    /**
2075
     * @return string
2076
     */
2077
    public function getToken()
2078
    {
2079
        return $this->token;
2080
    }
2081
2082
    /**
2083
     * @return string
2084
     */
2085
    public function getFullname()
2086
    {
2087
        return sprintf('%s %s', $this->getFirstname(), $this->getLastname());
2088
    }
2089
2090
    /**
2091
     * @return array
2092
     */
2093
    public function getRealRoles()
2094
    {
2095
        return $this->roles;
2096
    }
2097
2098
    /**
2099
     * @param array $roles
2100
     *
2101
     * @return User
2102
     */
2103
    public function setRealRoles(array $roles)
2104
    {
2105
        $this->setRoles($roles);
2106
2107
        return $this;
2108
    }
2109
2110
    /**
2111
     * Removes sensitive data from the user.
2112
     */
2113
    public function eraseCredentials()
2114
    {
2115
        $this->plainPassword = null;
2116
    }
2117
2118
2119
    public function getUsernameCanonical()
2120
    {
2121
        return $this->usernameCanonical;
2122
    }
2123
2124
2125
    public function getEmailCanonical()
2126
    {
2127
        return $this->emailCanonical;
2128
    }
2129
2130
    public function getPlainPassword()
2131
    {
2132
        if (isset($this->plainPassword)) {
2133
            return $this->plainPassword;
2134
        }
2135
    }
2136
2137
      /**
2138
     * Returns the user roles
2139
     *
2140
     * @return array The roles
2141
     */
2142 View Code Duplication
    public function getRoles()
2143
    {
2144
        $roles = $this->roles;
2145
2146
        foreach ($this->getGroups() as $group) {
2147
            $roles = array_merge($roles, $group->getRoles());
2148
        }
2149
2150
        // we need to make sure to have at least one role
2151
        $roles[] = static::ROLE_DEFAULT;
2152
2153
        return array_unique($roles);
2154
    }
2155
2156
    /**
2157
     * Never use this to check if this user has access to anything!
2158
     *
2159
     * Use the SecurityContext, or an implementation of AccessDecisionManager
2160
     * instead, e.g.
2161
     *
2162
     *         $securityContext->isGranted('ROLE_USER');
2163
     *
2164
     * @param string $role
2165
     *
2166
     * @return boolean
2167
     */
2168
    public function hasRole($role)
2169
    {
2170
        return in_array(strtoupper($role), $this->getRoles(), true);
2171
    }
2172
2173 View Code Duplication
    public function isAccountNonExpired()
2174
    {
2175
        if (true === $this->expired) {
2176
            return false;
2177
        }
2178
2179
        if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
2180
            return false;
2181
        }
2182
2183
        return true;
2184
    }
2185
2186
    public function isAccountNonLocked()
2187
    {
2188
        return !$this->locked;
2189
    }
2190
2191 View Code Duplication
    public function isCredentialsNonExpired()
2192
    {
2193
        if (true === $this->credentialsExpired) {
2194
            return false;
2195
        }
2196
2197
        if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
2198
            return false;
2199
        }
2200
2201
        return true;
2202
    }
2203
2204
    public function isCredentialsExpired()
2205
    {
2206
        return !$this->isCredentialsNonExpired();
2207
    }
2208
2209
    public function isExpired()
2210
    {
2211
        return !$this->isAccountNonExpired();
2212
    }
2213
2214
    public function isLocked()
2215
    {
2216
        return !$this->isAccountNonLocked();
2217
    }
2218
2219
    public function isSuperAdmin()
2220
    {
2221
        return $this->hasRole(static::ROLE_SUPER_ADMIN);
2222
    }
2223
2224
    public function isUser(UserInterface $user = null)
2225
    {
2226
        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\PageBundle\Entity\User, 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, 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...
2227
    }
2228
2229 View Code Duplication
    public function removeRole($role)
2230
    {
2231
        if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
2232
            unset($this->roles[$key]);
2233
            $this->roles = array_values($this->roles);
2234
        }
2235
2236
        return $this;
2237
    }
2238
2239
    public function setUsername($username)
2240
    {
2241
        $this->username = $username;
2242
2243
        return $this;
2244
    }
2245
2246
    public function setUsernameCanonical($usernameCanonical)
2247
    {
2248
        $this->usernameCanonical = $usernameCanonical;
2249
2250
        return $this;
2251
    }
2252
2253
2254
    /**
2255
     * @param boolean $boolean
2256
     *
2257
     * @return User
2258
     */
2259
    public function setCredentialsExpired($boolean)
2260
    {
2261
        $this->credentialsExpired = $boolean;
2262
2263
        return $this;
2264
    }
2265
2266
    public function setEmailCanonical($emailCanonical)
2267
    {
2268
        $this->emailCanonical = $emailCanonical;
2269
2270
        return $this;
2271
    }
2272
2273
    public function setEnabled($boolean)
2274
    {
2275
        $this->enabled = (Boolean) $boolean;
2276
2277
        return $this;
2278
    }
2279
2280
    /**
2281
     * Sets this user to expired.
2282
     *
2283
     * @param Boolean $boolean
2284
     *
2285
     * @return User
2286
     */
2287
    public function setExpired($boolean)
2288
    {
2289
        $this->expired = (Boolean) $boolean;
2290
2291
        return $this;
2292
    }
2293
2294
    /**
2295
     * @param \DateTime $date
2296
     *
2297
     * @return User
2298
     */
2299
    public function setExpiresAt(\DateTime $date)
2300
    {
2301
        $this->expiresAt = $date;
2302
2303
        return $this;
2304
    }
2305
2306 View Code Duplication
    public function setSuperAdmin($boolean)
2307
    {
2308
        if (true === $boolean) {
2309
            $this->addRole(static::ROLE_SUPER_ADMIN);
2310
        } else {
2311
            $this->removeRole(static::ROLE_SUPER_ADMIN);
2312
        }
2313
2314
        return $this;
2315
    }
2316
2317
    public function setPlainPassword($password)
2318
    {
2319
        $this->plainPassword = $password;
2320
2321
        return $this;
2322
    }
2323
2324
    public function setLocked($boolean)
2325
    {
2326
        $this->locked = $boolean;
2327
2328
        return $this;
2329
    }
2330
2331
    public function setPasswordRequestedAt(\DateTime $date = null)
2332
    {
2333
        $this->passwordRequestedAt = $date;
2334
2335
        return $this;
2336
    }
2337
2338
2339
    public function setRoles(array $roles)
2340
    {
2341
        $this->roles = array();
2342
2343
        foreach ($roles as $role) {
2344
            $this->addRole($role);
2345
        }
2346
2347
        return $this;
2348
    }
2349
2350
    /**
2351
     * Gets the groups granted to the user.
2352
     *
2353
     * @return Collection
2354
     */
2355
    public function getGroups()
2356
    {
2357
        return $this->groups ?: $this->groups = new ArrayCollection();
2358
    }
2359
2360
    public function getGroupNames()
2361
    {
2362
        $names = array();
2363
        foreach ($this->getGroups() as $group) {
2364
            $names[] = $group->getName();
2365
        }
2366
2367
        return $names;
2368
    }
2369
2370
    public function hasGroup($name)
2371
    {
2372
        return in_array($name, $this->getGroupNames());
2373
    }
2374
2375
    public function addGroup(GroupInterface $group)
2376
    {
2377
        if (!$this->getGroups()->contains($group)) {
2378
            $this->getGroups()->add($group);
2379
        }
2380
2381
        return $this;
2382
    }
2383
2384
    public function removeGroup(GroupInterface $group)
2385
    {
2386
        if ($this->getGroups()->contains($group)) {
2387
            $this->getGroups()->removeElement($group);
2388
        }
2389
2390
        return $this;
2391
    }
2392
2393 View Code Duplication
    public function addRole($role)
2394
    {
2395
        $role = strtoupper($role);
2396
        if ($role === static::ROLE_DEFAULT) {
2397
            return $this;
2398
        }
2399
2400
        if (!in_array($role, $this->roles, true)) {
2401
            $this->roles[] = $role;
2402
        }
2403
2404
        return $this;
2405
    }
2406
2407
    /**
2408
     * Serializes the user.
2409
     *
2410
     * The serialized data have to contain the fields used by the equals method and the username.
2411
     *
2412
     * @return string
2413
     */
2414 View Code Duplication
    public function serialize()
2415
    {
2416
        return serialize(array(
2417
            $this->password,
2418
            $this->salt,
2419
            $this->usernameCanonical,
2420
            $this->username,
2421
            $this->expired,
2422
            $this->locked,
2423
            $this->credentialsExpired,
2424
            $this->enabled,
2425
            $this->id,
2426
        ));
2427
    }
2428
2429
    /**
2430
     * Unserializes the user.
2431
     *
2432
     * @param string $serialized
2433
     */
2434 View Code Duplication
    public function unserialize($serialized)
2435
    {
2436
        $data = unserialize($serialized);
2437
        // add a few extra elements in the array to ensure that we have enough keys when unserializing
2438
        // older data which does not include all properties.
2439
        $data = array_merge($data, array_fill(0, 2, null));
2440
2441
        list(
2442
            $this->password,
2443
            $this->salt,
2444
            $this->usernameCanonical,
2445
            $this->username,
2446
            $this->expired,
2447
            $this->locked,
2448
            $this->credentialsExpired,
2449
            $this->enabled,
2450
            $this->id
2451
            ) = $data;
2452
    }
2453
2454
    /**
2455
     * Get achievedSkills
2456
     * @return ArrayCollection
2457
     */
2458
    public function getAchievedSkills()
2459
    {
2460
        return $this->achievedSkills;
2461
    }
2462
2463
    /**
2464
     * Check if the user has the skill
2465
     * @param \Chamilo\CoreBundle\Entity\Skill $skill The skill
2466
     * @return boolean
2467
     */
2468
    public function hasSkill(\Chamilo\CoreBundle\Entity\Skill $skill)
2469
    {
2470
        $achievedSkills = $this->getAchievedSkills();
2471
2472
        foreach ($achievedSkills as $userSkill) {
2473
            if ($userSkill->getSkill()->getId() !== $skill->getId()) {
2474
                continue;
2475
            }
2476
            return true;
2477
        }
2478
    }
2479
}
2480