Passed
Push — 1.11.x ( 106594...56cdc0 )
by Angel Fernando Quiroz
08:52
created

src/Chamilo/UserBundle/Entity/User.php (1 issue)

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