Test Setup Failed
Push — master ( f71949...6c6bd7 )
by Julito
55:21
created

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