Completed
Push — master ( 0fb228...bf9357 )
by Julito
13:22
created

User::getResourceNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nop 0
dl 0
loc 3
rs 10
nc 1
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\UserBundle\Entity;
5
6
use Chamilo\CoreBundle\Entity\AccessUrl;
7
use Chamilo\CoreBundle\Entity\AccessUrlRelUser;
8
use Chamilo\CoreBundle\Entity\Course;
9
use Chamilo\CoreBundle\Entity\Resource\AbstractResource;
10
use Chamilo\CoreBundle\Entity\Resource\ResourceNode;
11
use Chamilo\CoreBundle\Entity\Skill;
12
use Chamilo\CoreBundle\Entity\UsergroupRelUser;
13
use Chamilo\ThemeBundle\Model\UserInterface as ThemeUser;
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Doctrine\Common\Collections\Criteria;
17
use Doctrine\ORM\Event\LifecycleEventArgs;
18
use Doctrine\ORM\Mapping as ORM;
19
use Sonata\UserBundle\Entity\BaseUser;
20
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
21
use Symfony\Component\Security\Core\User\EquatableInterface;
22
use Symfony\Component\Security\Core\User\UserInterface;
23
use Symfony\Component\Validator\Constraints as Assert;
24
use Symfony\Component\Validator\Mapping\ClassMetadata;
25
26
/**
27
 * @ORM\HasLifecycleCallbacks
28
 * @ORM\Table(
29
 *  name="user",
30
 *  indexes={
31
 *      @ORM\Index(name="idx_user_uid", columns={"user_id"}),
32
 *      @ORM\Index(name="status", columns={"status"})
33
 *  }
34
 * )
35
 * @UniqueEntity("username")
36
 *
37
 * @ORM\Entity()
38
 *
39
 * @ORM\AttributeOverrides({
40
 *     @ORM\AttributeOverride(name="username",
41
 *         column=@ORM\Column(
42
 *             name="username",
43
 *             type="string",
44
 *             length=100,
45
 *             unique=true
46
 *         )
47
 *     ),
48
 *      @ORM\AttributeOverride(name="email",
49
 *         column=@ORM\Column(
50
 *             name="email",
51
 *             type="string",
52
 *             length=100,
53
 *             unique=false
54
 *         )
55
 *     ),
56
 *     @ORM\AttributeOverride(name="emailCanonical",
57
 *         column=@ORM\Column(
58
 *             name="email_canonical",
59
 *             type="string",
60
 *             length=100,
61
 *             unique=false
62
 *         )
63
 *     ),
64
 *     @ORM\AttributeOverride(name="usernameCanonical",
65
 *         column=@ORM\Column(
66
 *             name="username_canonical",
67
 *             type="string",
68
 *             length=180,
69
 *             unique=false
70
 *         )
71
 *     )
72
 * })
73
 */
74
class User extends BaseUser implements ThemeUser, EquatableInterface //implements ParticipantInterface, ThemeUser
75
{
76
    public const COURSE_MANAGER = 1;
77
    public const TEACHER = 1;
78
    public const SESSION_ADMIN = 3;
79
    public const DRH = 4;
80
    public const STUDENT = 5;
81
    public const ANONYMOUS = 6;
82
83
    /**
84
     * @var int
85
     *
86
     * @ORM\Column(name="id", type="integer")
87
     * @ORM\Id
88
     * @ORM\GeneratedValue(strategy="AUTO")
89
     */
90
    protected $id;
91
92
    /**
93
     * @var int
94
     *
95
     * @ORM\Column(name="user_id", type="integer", nullable=true)
96
     */
97
    protected $userId;
98
99
    /**
100
     * @var string
101
     *
102
     * @ORM\Column(name="username", type="string", length=100, nullable=false, unique=true)
103
     */
104
    //protected $username;
105
106
    /**
107
     * @var string
108
     *
109
     * @ORM\Column(name="username_canonical", type="string", length=100, nullable=false)
110
     */
111
    //protected $usernameCanonical;
112
113
    /**
114
     * @var string
115
     * @ORM\Column(name="email_canonical", type="string", length=100, nullable=false, unique=false)
116
     */
117
    //protected $emailCanonical;
118
119
    /**
120
     * @var string
121
     *
122
     * @ORM\Column(name="email", type="string", length=100, nullable=false, unique=false)
123
     */
124
    //protected $email;
125
126
    /**
127
     * @var bool
128
     *
129
     * @ORM\Column(name="locked", type="boolean")
130
     */
131
    protected $locked;
132
133
    /**
134
     * @var bool
135
     *
136
     * @ORM\Column(name="enabled", type="boolean")
137
     */
138
    //protected $enabled;
139
140
    /**
141
     * @var bool
142
     *
143
     * @ORM\Column(name="expired", type="boolean")
144
     */
145
    protected $expired;
146
147
    /**
148
     * @var bool
149
     *
150
     * @ORM\Column(name="credentials_expired", type="boolean")
151
     */
152
    protected $credentialsExpired;
153
154
    /**
155
     * @var \DateTime
156
     *
157
     * @ORM\Column(name="credentials_expire_at", type="datetime", nullable=true, unique=false)
158
     */
159
    protected $credentialsExpireAt;
160
161
    /**
162
     * @var \DateTime
163
     *
164
     * @ORM\Column(name="expires_at", type="datetime", nullable=true, unique=false)
165
     */
166
    protected $expiresAt;
167
168
    /**
169
     * @var string
170
     *
171
     * @ORM\Column(name="phone", type="string", length=30, nullable=true, unique=false)
172
     */
173
    //protected $phone;
174
175
    /**
176
     * @var string
177
     *
178
     * @ORM\Column(name="address", type="string", length=250, nullable=true, unique=false)
179
     */
180
    protected $address;
181
182
    /**
183
     * @var AccessUrl
184
     */
185
    protected $currentUrl;
186
187
    /**
188
     * @ORM\Column(type="string", length=255)
189
     */
190
    //protected $salt;
191
192
    /**
193
     * @var \DateTime
194
     *
195
     * @ORM\Column(name="last_login", type="datetime", nullable=true, unique=false)
196
     */
197
    //protected $lastLogin;
198
199
    /**
200
     * Random string sent to the user email address in order to verify it.
201
     *
202
     * @var string
203
     * @ORM\Column(name="confirmation_token", type="string", length=255, nullable=true)
204
     */
205
    //protected $confirmationToken;
206
207
    /**
208
     * @var \DateTime
209
     *
210
     * @ORM\Column(name="password_requested_at", type="datetime", nullable=true, unique=false)
211
     */
212
    //protected $passwordRequestedAt;
213
214
    /**
215
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CourseRelUser", mappedBy="user", orphanRemoval=true)
216
     */
217
    protected $courses;
218
219
    /**
220
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CItemProperty", mappedBy="user")
221
     */
222
    //protected $items;
223
224
    /**
225
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\UsergroupRelUser", mappedBy="user")
226
     */
227
    protected $classes;
228
229
    /**
230
     * ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CDropboxPost", mappedBy="user").
231
     */
232
    protected $dropBoxReceivedFiles;
233
234
    /**
235
     * ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CDropboxFile", mappedBy="userSent").
236
     */
237
    protected $dropBoxSentFiles;
238
239
    /**
240
     * @ORM\Column(type="array")
241
     */
242
    //protected $roles;
243
244
    /**
245
     * @var bool
246
     *
247
     * @ORM\Column(name="profile_completed", type="boolean", nullable=true)
248
     */
249
    protected $profileCompleted;
250
251
    /**
252
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\JuryMembers", mappedBy="user")
253
     */
254
    //protected $jurySubscriptions;
255
256
    /**
257
     * @ORM\ManyToMany(targetEntity="Chamilo\UserBundle\Entity\Group", inversedBy="users")
258
     * @ORM\JoinTable(name="fos_user_user_group",
259
     *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
260
     *      inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
261
     * )
262
     */
263
    protected $groups;
264
265
    //private $isActive;
266
267
    /**
268
     * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CurriculumItemRelUser", mappedBy="user").
269
     */
270
    protected $curriculumItems;
271
272
    /**
273
     * @ORM\OneToMany(
274
     *     targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelUser",
275
     *     mappedBy="user",
276
     *     cascade={"persist", "remove"},
277
     *     orphanRemoval=true
278
     * )
279
     */
280
    protected $portals;
281
282
    /**
283
     * @var ArrayCollection
284
     *
285
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Session", mappedBy="generalCoach")
286
     */
287
    protected $sessionAsGeneralCoach;
288
289
    /**
290
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", mappedBy="creator").
291
     */
292
    protected $resourceNodes;
293
294
    /**
295
     * @ORM\OneToMany(
296
     *     targetEntity="Chamilo\CoreBundle\Entity\SessionRelCourseRelUser",
297
     *     mappedBy="user",
298
     *     cascade={"persist"},
299
     *     orphanRemoval=true
300
     * )
301
     */
302
    protected $sessionCourseSubscriptions;
303
304
    /**
305
     * @ORM\OneToMany(
306
     *     targetEntity="Chamilo\CoreBundle\Entity\SkillRelUser",
307
     *     mappedBy="user",
308
     *     cascade={"persist", "remove"},
309
     *     orphanRemoval=true
310
     * )
311
     */
312
    protected $achievedSkills;
313
314
    /**
315
     * @ORM\OneToMany(
316
     *     targetEntity="Chamilo\CoreBundle\Entity\SkillRelUserComment",
317
     *     mappedBy="feedbackGiver",
318
     *     cascade={"persist", "remove"},
319
     *     orphanRemoval=true
320
     * )
321
     */
322
    protected $commentedUserSkills;
323
324
    /**
325
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\GradebookCategory", mappedBy="user")
326
     */
327
    protected $gradeBookCategories;
328
329
    /**
330
     * @ORM\OneToMany(
331
     *     targetEntity="Chamilo\CoreBundle\Entity\SessionRelUser",
332
     *     mappedBy="user",
333
     *     cascade={"persist", "remove"},
334
     *     orphanRemoval=true
335
     * )
336
     */
337
    protected $sessions;
338
339
    /**
340
     * @var Collection
341
     *
342
     * @ORM\OneToMany(
343
     *     targetEntity="Chamilo\CourseBundle\Entity\CGroupRelUser",
344
     *     mappedBy="user",
345
     *     cascade={"persist", "remove"},
346
     *     orphanRemoval=true
347
     * )
348
     */
349
    protected $courseGroupsAsMember;
350
351
    /**
352
     * @var Collection
353
     *
354
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CGroupRelTutor", mappedBy="user", orphanRemoval=true)
355
     */
356
    protected $courseGroupsAsTutor;
357
358
    /**
359
     * @var string
360
     *
361
     * @ORM\Column(name="auth_source", type="string", length=50, nullable=true, unique=false)
362
     */
363
    protected $authSource;
364
365
    /**
366
     * @var int
367
     *
368
     * @ORM\Column(name="status", type="integer", nullable=false)
369
     */
370
    protected $status;
371
372
    /**
373
     * @var string
374
     *
375
     * @ORM\Column(name="official_code", type="string", length=40, nullable=true, unique=false)
376
     */
377
    protected $officialCode;
378
379
    /**
380
     * @var string
381
     *
382
     * @ORM\Column(name="picture_uri", type="string", length=250, nullable=true, unique=false)
383
     */
384
    protected $pictureUri;
385
386
    /**
387
     * @var int
388
     *
389
     * @ORM\Column(name="creator_id", type="integer", nullable=true, unique=false)
390
     */
391
    protected $creatorId;
392
393
    /**
394
     * @var string
395
     *
396
     * @ORM\Column(name="competences", type="text", nullable=true, unique=false)
397
     */
398
    protected $competences;
399
400
    /**
401
     * @var string
402
     *
403
     * @ORM\Column(name="diplomas", type="text", nullable=true, unique=false)
404
     */
405
    protected $diplomas;
406
407
    /**
408
     * @var string
409
     *
410
     * @ORM\Column(name="openarea", type="text", nullable=true, unique=false)
411
     */
412
    protected $openarea;
413
414
    /**
415
     * @var string
416
     *
417
     * @ORM\Column(name="teach", type="text", nullable=true, unique=false)
418
     */
419
    protected $teach;
420
421
    /**
422
     * @var string
423
     *
424
     * @ORM\Column(name="productions", type="string", length=250, nullable=true, unique=false)
425
     */
426
    protected $productions;
427
428
    /**
429
     * @var string
430
     *
431
     * @ORM\Column(name="language", type="string", length=40, nullable=true, unique=false)
432
     */
433
    protected $language;
434
435
    /**
436
     * @var \DateTime
437
     *
438
     * @ORM\Column(name="registration_date", type="datetime", nullable=false, unique=false)
439
     */
440
    protected $registrationDate;
441
442
    /**
443
     * @var \DateTime
444
     *
445
     * @ORM\Column(name="expiration_date", type="datetime", nullable=true, unique=false)
446
     */
447
    protected $expirationDate;
448
449
    /**
450
     * @var bool
451
     *
452
     * @ORM\Column(name="active", type="boolean", nullable=false, unique=false)
453
     */
454
    protected $active;
455
456
    /**
457
     * @var string
458
     *
459
     * @ORM\Column(name="openid", type="string", length=255, nullable=true, unique=false)
460
     */
461
    protected $openid;
462
463
    /**
464
     * @var string
465
     *
466
     * @ORM\Column(name="theme", type="string", length=255, nullable=true, unique=false)
467
     */
468
    protected $theme;
469
470
    /**
471
     * @var int
472
     *
473
     * @ORM\Column(name="hr_dept_id", type="smallint", nullable=true, unique=false)
474
     */
475
    protected $hrDeptId;
476
477
    /**
478
     * @var ArrayCollection
479
     *
480
     * @ORM\OneToMany(
481
     *     targetEntity="Chamilo\CoreBundle\Entity\Message",
482
     *     mappedBy="userSender",
483
     *     cascade={"persist", "remove"},
484
     *     orphanRemoval=true
485
     * )
486
     */
487
    protected $sentMessages;
488
489
    /**
490
     * @var ArrayCollection
491
     *
492
     * @ORM\OneToMany(
493
     *     targetEntity="Chamilo\CoreBundle\Entity\Message",
494
     *     mappedBy="userReceiver",
495
     *     cascade={"persist", "remove"},
496
     *     orphanRemoval=true
497
     * )
498
     */
499
    protected $receivedMessages;
500
501
    /**
502
     *
503
     * @ORM\OneToOne(
504
     *     targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", cascade={"remove"}, orphanRemoval=true
505
     * )
506
     * @ORM\JoinColumn(name="resource_node_id", referencedColumnName="id", onDelete="CASCADE")
507
     */
508
    public $resourceNode;
509
510
    /**
511
     * @return $this
512
     */
513
    public function setResourceNode(ResourceNode $resourceNode): self
514
    {
515
        $this->resourceNode = $resourceNode;
516
517
        return $this;
518
    }
519
520
    public function getResourceNode(): ResourceNode
521
    {
522
        return $this->resourceNode;
523
    }
524
525
    /**
526
     * Constructor.
527
     */
528
    public function __construct()
529
    {
530
        parent::__construct();
531
        $this->status = self::STUDENT;
532
        $this->salt = sha1(uniqid(null, true));
0 ignored issues
show
Bug Best Practice introduced by
The property salt does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
533
        $this->active = true;
534
        $this->registrationDate = new \DateTime();
535
        $this->authSource = 'platform';
536
        $this->courses = new ArrayCollection();
537
        //$this->items = new ArrayCollection();
538
        $this->classes = new ArrayCollection();
539
        $this->curriculumItems = new ArrayCollection();
540
        $this->portals = new ArrayCollection();
541
        $this->dropBoxSentFiles = new ArrayCollection();
542
        $this->dropBoxReceivedFiles = new ArrayCollection();
543
        //$this->extraFields = new ArrayCollection();
544
        //$this->userId = 0;
545
        //$this->createdAt = new \DateTime();
546
        //$this->updatedAt = new \DateTime();
547
548
        $this->enabled = false;
0 ignored issues
show
Bug Best Practice introduced by
The property enabled does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
549
        $this->locked = false;
550
        $this->expired = false;
551
        $this->roles = [];
0 ignored issues
show
Bug Best Practice introduced by
The property roles does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
552
        $this->credentialsExpired = false;
553
554
        $this->courseGroupsAsMember = new ArrayCollection();
555
        $this->courseGroupsAsTutor = new ArrayCollection();
556
    }
557
558
    /**
559
     * @return string
560
     */
561
    public function __toString()
562
    {
563
        return $this->getUsername();
564
    }
565
566
    /**
567
     * Updates the id with the user_id.
568
     *
569
     * @ORM\PostPersist()
570
     */
571
    public function postPersist(LifecycleEventArgs $args)
572
    {
573
        $user = $args->getEntity();
574
        $this->setUserId($user->getId());
575
    }
576
577
    /**
578
     * @param int $userId
579
     */
580
    public function setId($userId)
581
    {
582
        $this->id = $userId;
583
    }
584
585
    /**
586
     * @param int $userId
587
     */
588
    public function setUserId($userId)
589
    {
590
        if (!empty($userId)) {
591
            $this->userId = $userId;
592
        }
593
    }
594
595
    /**
596
     * @return int
597
     */
598
    public function getId()
599
    {
600
        return $this->id;
601
    }
602
603
    /**
604
     * @return ArrayCollection
605
     */
606
    public function getDropBoxSentFiles()
607
    {
608
        return $this->dropBoxSentFiles;
609
    }
610
611
    /**
612
     * @return ArrayCollection
613
     */
614
    public function getDropBoxReceivedFiles()
615
    {
616
        return $this->dropBoxReceivedFiles;
617
    }
618
619
    /**
620
     * @param ArrayCollection $value
621
     */
622
    public function setDropBoxSentFiles($value)
623
    {
624
        $this->dropBoxSentFiles = $value;
625
    }
626
627
    /**
628
     * @param ArrayCollection $value
629
     */
630
    public function setDropBoxReceivedFiles($value)
631
    {
632
        $this->dropBoxReceivedFiles = $value;
633
    }
634
635
    /**
636
     * @param ArrayCollection $courses
637
     */
638
    public function setCourses($courses)
639
    {
640
        $this->courses = $courses;
641
    }
642
643
    /**
644
     * @return ArrayCollection
645
     */
646
    public function getCourses()
647
    {
648
        return $this->courses;
649
    }
650
651
    /**
652
     * @return array
653
     */
654
    public static function getPasswordConstraints()
655
    {
656
        return
657
            [
658
                new Assert\Length(['min' => 5]),
659
                // Alpha numeric + "_" or "-"
660
                new Assert\Regex(
661
                    [
662
                        'pattern' => '/^[a-z\-_0-9]+$/i',
663
                        'htmlPattern' => '/^[a-z\-_0-9]+$/i', ]
664
                ),
665
                // Min 3 letters - not needed
666
                /*new Assert\Regex(array(
667
                    'pattern' => '/[a-z]{3}/i',
668
                    'htmlPattern' => '/[a-z]{3}/i')
669
                ),*/
670
                // Min 2 numbers
671
                new Assert\Regex(
672
                    [
673
                        'pattern' => '/[0-9]{2}/',
674
                        'htmlPattern' => '/[0-9]{2}/', ]
675
                ),
676
            ]
677
            ;
678
    }
679
680
    public static function loadValidatorMetadata(ClassMetadata $metadata)
681
    {
682
        //$metadata->addPropertyConstraint('firstname', new Assert\NotBlank());
683
        //$metadata->addPropertyConstraint('lastname', new Assert\NotBlank());
684
        //$metadata->addPropertyConstraint('email', new Assert\Email());
685
        /*
686
        $metadata->addPropertyConstraint('password',
687
            new Assert\Collection(self::getPasswordConstraints())
688
        );*/
689
690
        /*$metadata->addConstraint(new UniqueEntity(array(
691
            'fields'  => 'username',
692
            'message' => 'This value is already used.',
693
        )));*/
694
695
        /*$metadata->addPropertyConstraint(
696
            'username',
697
            new Assert\Length(array(
698
                'min'        => 2,
699
                'max'        => 50,
700
                '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.',
701
                '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.',
702
            ))
703
        );*/
704
    }
705
706
    /**
707
     * @return ArrayCollection
708
     */
709
    public function getPortals()
710
    {
711
        return $this->portals;
712
    }
713
714
    /**
715
     * @param $portal
716
     */
717
    public function setPortal($portal)
718
    {
719
        $this->portals->add($portal);
720
    }
721
722
    /**
723
     * @param $value
724
     */
725
    public function setPortals($value)
726
    {
727
        $this->portals = $value;
728
    }
729
730
    /**
731
     * @return ArrayCollection
732
     */
733
    public function getCurriculumItems()
734
    {
735
        return $this->curriculumItems;
736
    }
737
738
    /**
739
     * @param $items
740
     *
741
     * @return $this
742
     */
743
    public function setCurriculumItems($items)
744
    {
745
        $this->curriculumItems = $items;
746
747
        return $this;
748
    }
749
750
    /**
751
     * @return bool
752
     */
753
    public function getIsActive()
754
    {
755
        return $this->active == 1;
756
    }
757
758
    /**
759
     * @return bool
760
     */
761
    public function isActive()
762
    {
763
        return $this->getIsActive();
764
    }
765
766
    /**
767
     * {@inheritdoc}
768
     */
769
    public function isEnabled()
770
    {
771
        return $this->getActive() == 1;
772
    }
773
774
    /**
775
     * @return ArrayCollection
776
     */
777
    /*public function getRolesObj()
778
    {
779
        return $this->roles;
780
    }*/
781
782
    /**
783
     * Set salt.
784
     *
785
     * @param string $salt
786
     *
787
     * @return User
788
     */
789
    public function setSalt($salt)
790
    {
791
        $this->salt = $salt;
0 ignored issues
show
Bug Best Practice introduced by
The property salt does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
792
793
        return $this;
794
    }
795
796
    /**
797
     * Get salt.
798
     *
799
     * @return string
800
     */
801
    public function getSalt()
802
    {
803
        return $this->salt;
804
    }
805
806
    /**
807
     * @param ArrayCollection $classes
808
     *
809
     * @return $this
810
     */
811
    public function setClasses($classes)
812
    {
813
        $this->classes = $classes;
814
815
        return $this;
816
    }
817
818
    /**
819
     * @return ArrayCollection
820
     */
821
    public function getClasses()
822
    {
823
        return $this->classes;
824
    }
825
826
    public function getLps()
827
    {
828
        //return $this->lps;
829
        /*$criteria = Criteria::create()
830
            ->where(Criteria::expr()->eq("id", "666"))
831
            //->orderBy(array("username" => "ASC"))
832
            //->setFirstResult(0)
833
            //->setMaxResults(20)
834
        ;
835
        $lps = $this->lps->matching($criteria);*/
836
        /*return $this->lps->filter(
837
            function($entry) use ($idsToFilter) {
838
                return $entry->getId() == 1;
839
        });*/
840
    }
841
842
    /**
843
     * Returns the list of classes for the user.
844
     *
845
     * @return string
846
     */
847
    public function getCompleteNameWithClasses()
848
    {
849
        $classSubscription = $this->getClasses();
850
        $classList = [];
851
        /** @var UsergroupRelUser $subscription */
852
        foreach ($classSubscription as $subscription) {
853
            $class = $subscription->getUsergroup();
854
            $classList[] = $class->getName();
855
        }
856
        $classString = !empty($classList) ? ' ['.implode(', ', $classList).']' : null;
857
858
        return \UserManager::formatUserFullName($this).$classString;
859
    }
860
861
    /**
862
     * Get userId.
863
     *
864
     * @return int
865
     */
866
    public function getUserId()
867
    {
868
        return $this->userId;
869
    }
870
871
    /**
872
     * Set lastname.
873
     *
874
     * @param string $lastname
875
     *
876
     * @return User
877
     */
878
    public function setLastname($lastname)
879
    {
880
        $this->lastname = $lastname;
0 ignored issues
show
Bug Best Practice introduced by
The property lastname does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
881
882
        return $this;
883
    }
884
885
    /**
886
     * Set firstname.
887
     *
888
     * @param string $firstname
889
     *
890
     * @return User
891
     */
892
    public function setFirstname($firstname)
893
    {
894
        $this->firstname = $firstname;
0 ignored issues
show
Bug Best Practice introduced by
The property firstname does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
895
896
        return $this;
897
    }
898
899
    /**
900
     * Set password.
901
     *
902
     * @param string $password
903
     *
904
     * @return User
905
     */
906
    public function setPassword($password)
907
    {
908
        $this->password = $password;
0 ignored issues
show
Bug Best Practice introduced by
The property password does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
909
910
        return $this;
911
    }
912
913
    /**
914
     * Get password.
915
     *
916
     * @return string
917
     */
918
    public function getPassword()
919
    {
920
        return $this->password;
921
    }
922
923
    /**
924
     * Set authSource.
925
     *
926
     * @param string $authSource
927
     *
928
     * @return User
929
     */
930
    public function setAuthSource($authSource)
931
    {
932
        $this->authSource = $authSource;
933
934
        return $this;
935
    }
936
937
    /**
938
     * Get authSource.
939
     *
940
     * @return string
941
     */
942
    public function getAuthSource()
943
    {
944
        return $this->authSource;
945
    }
946
947
    /**
948
     * Set email.
949
     *
950
     * @param string $email
951
     *
952
     * @return User
953
     */
954
    public function setEmail($email)
955
    {
956
        $this->email = $email;
0 ignored issues
show
Bug Best Practice introduced by
The property email does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
957
958
        return $this;
959
    }
960
961
    /**
962
     * Get email.
963
     *
964
     * @return string
965
     */
966
    public function getEmail()
967
    {
968
        return $this->email;
969
    }
970
971
    /**
972
     * Set status.
973
     *
974
     * @param int $status
975
     *
976
     * @return User
977
     */
978
    public function setStatus($status)
979
    {
980
        $this->status = $status;
981
982
        return $this;
983
    }
984
985
    /**
986
     * Get status.
987
     *
988
     * @return int
989
     */
990
    public function getStatus()
991
    {
992
        return $this->status;
993
    }
994
995
    /**
996
     * Set officialCode.
997
     *
998
     * @param string $officialCode
999
     *
1000
     * @return User
1001
     */
1002
    public function setOfficialCode($officialCode)
1003
    {
1004
        $this->officialCode = $officialCode;
1005
1006
        return $this;
1007
    }
1008
1009
    /**
1010
     * Get officialCode.
1011
     *
1012
     * @return string
1013
     */
1014
    public function getOfficialCode()
1015
    {
1016
        return $this->officialCode;
1017
    }
1018
1019
    /**
1020
     * Set phone.
1021
     *
1022
     * @param string $phone
1023
     *
1024
     * @return User
1025
     */
1026
    public function setPhone($phone)
1027
    {
1028
        $this->phone = $phone;
0 ignored issues
show
Bug Best Practice introduced by
The property phone does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1029
1030
        return $this;
1031
    }
1032
1033
    /**
1034
     * Get phone.
1035
     *
1036
     * @return string
1037
     */
1038
    public function getPhone()
1039
    {
1040
        return $this->phone;
1041
    }
1042
1043
    /**
1044
     * Set address.
1045
     *
1046
     * @param string $address
1047
     *
1048
     * @return User
1049
     */
1050
    public function setAddress($address)
1051
    {
1052
        $this->address = $address;
1053
1054
        return $this;
1055
    }
1056
1057
    /**
1058
     * Get address.
1059
     *
1060
     * @return string
1061
     */
1062
    public function getAddress()
1063
    {
1064
        return $this->address;
1065
    }
1066
1067
    /**
1068
     * Set pictureUri.
1069
     *
1070
     * @param string $pictureUri
1071
     *
1072
     * @return User
1073
     */
1074
    public function setPictureUri($pictureUri)
1075
    {
1076
        $this->pictureUri = $pictureUri;
1077
1078
        return $this;
1079
    }
1080
1081
    /**
1082
     * Get pictureUri.
1083
     *
1084
     * @return string
1085
     */
1086
    public function getPictureUri()
1087
    {
1088
        return $this->pictureUri;
1089
    }
1090
1091
    /**
1092
     * Set creatorId.
1093
     *
1094
     * @param int $creatorId
1095
     *
1096
     * @return User
1097
     */
1098
    public function setCreatorId($creatorId)
1099
    {
1100
        $this->creatorId = $creatorId;
1101
1102
        return $this;
1103
    }
1104
1105
    /**
1106
     * Get creatorId.
1107
     *
1108
     * @return int
1109
     */
1110
    public function getCreatorId()
1111
    {
1112
        return $this->creatorId;
1113
    }
1114
1115
    /**
1116
     * Set competences.
1117
     *
1118
     * @param string $competences
1119
     *
1120
     * @return User
1121
     */
1122
    public function setCompetences($competences)
1123
    {
1124
        $this->competences = $competences;
1125
1126
        return $this;
1127
    }
1128
1129
    /**
1130
     * Get competences.
1131
     *
1132
     * @return string
1133
     */
1134
    public function getCompetences()
1135
    {
1136
        return $this->competences;
1137
    }
1138
1139
    /**
1140
     * Set diplomas.
1141
     *
1142
     * @param string $diplomas
1143
     *
1144
     * @return User
1145
     */
1146
    public function setDiplomas($diplomas)
1147
    {
1148
        $this->diplomas = $diplomas;
1149
1150
        return $this;
1151
    }
1152
1153
    /**
1154
     * Get diplomas.
1155
     *
1156
     * @return string
1157
     */
1158
    public function getDiplomas()
1159
    {
1160
        return $this->diplomas;
1161
    }
1162
1163
    /**
1164
     * Set openarea.
1165
     *
1166
     * @param string $openarea
1167
     *
1168
     * @return User
1169
     */
1170
    public function setOpenarea($openarea)
1171
    {
1172
        $this->openarea = $openarea;
1173
1174
        return $this;
1175
    }
1176
1177
    /**
1178
     * Get openarea.
1179
     *
1180
     * @return string
1181
     */
1182
    public function getOpenarea()
1183
    {
1184
        return $this->openarea;
1185
    }
1186
1187
    /**
1188
     * Set teach.
1189
     *
1190
     * @param string $teach
1191
     *
1192
     * @return User
1193
     */
1194
    public function setTeach($teach)
1195
    {
1196
        $this->teach = $teach;
1197
1198
        return $this;
1199
    }
1200
1201
    /**
1202
     * Get teach.
1203
     *
1204
     * @return string
1205
     */
1206
    public function getTeach()
1207
    {
1208
        return $this->teach;
1209
    }
1210
1211
    /**
1212
     * Set productions.
1213
     *
1214
     * @param string $productions
1215
     *
1216
     * @return User
1217
     */
1218
    public function setProductions($productions)
1219
    {
1220
        $this->productions = $productions;
1221
1222
        return $this;
1223
    }
1224
1225
    /**
1226
     * Get productions.
1227
     *
1228
     * @return string
1229
     */
1230
    public function getProductions()
1231
    {
1232
        return $this->productions;
1233
    }
1234
1235
    /**
1236
     * Set language.
1237
     *
1238
     * @param string $language
1239
     *
1240
     * @return User
1241
     */
1242
    public function setLanguage($language)
1243
    {
1244
        $this->language = $language;
1245
1246
        return $this;
1247
    }
1248
1249
    /**
1250
     * Get language.
1251
     *
1252
     * @return string
1253
     */
1254
    public function getLanguage()
1255
    {
1256
        return $this->language;
1257
    }
1258
1259
    /**
1260
     * Set registrationDate.
1261
     *
1262
     * @param \DateTime $registrationDate
1263
     *
1264
     * @return User
1265
     */
1266
    public function setRegistrationDate($registrationDate)
1267
    {
1268
        $this->registrationDate = $registrationDate;
1269
1270
        return $this;
1271
    }
1272
1273
    /**
1274
     * Get registrationDate.
1275
     *
1276
     * @return \DateTime
1277
     */
1278
    public function getRegistrationDate()
1279
    {
1280
        return $this->registrationDate;
1281
    }
1282
1283
    /**
1284
     * Set expirationDate.
1285
     *
1286
     * @param \DateTime $expirationDate
1287
     *
1288
     * @return User
1289
     */
1290
    public function setExpirationDate($expirationDate)
1291
    {
1292
        $this->expirationDate = $expirationDate;
1293
1294
        return $this;
1295
    }
1296
1297
    /**
1298
     * Get expirationDate.
1299
     *
1300
     * @return \DateTime
1301
     */
1302
    public function getExpirationDate()
1303
    {
1304
        return $this->expirationDate;
1305
    }
1306
1307
    /**
1308
     * Set active.
1309
     *
1310
     * @param bool $active
1311
     *
1312
     * @return User
1313
     */
1314
    public function setActive($active)
1315
    {
1316
        $this->active = $active;
1317
1318
        return $this;
1319
    }
1320
1321
    /**
1322
     * Get active.
1323
     *
1324
     * @return bool
1325
     */
1326
    public function getActive()
1327
    {
1328
        return $this->active;
1329
    }
1330
1331
    /**
1332
     * Set openid.
1333
     *
1334
     * @param string $openid
1335
     *
1336
     * @return User
1337
     */
1338
    public function setOpenid($openid)
1339
    {
1340
        $this->openid = $openid;
1341
1342
        return $this;
1343
    }
1344
1345
    /**
1346
     * Get openid.
1347
     *
1348
     * @return string
1349
     */
1350
    public function getOpenid()
1351
    {
1352
        return $this->openid;
1353
    }
1354
1355
    /**
1356
     * Set theme.
1357
     *
1358
     * @param string $theme
1359
     *
1360
     * @return User
1361
     */
1362
    public function setTheme($theme)
1363
    {
1364
        $this->theme = $theme;
1365
1366
        return $this;
1367
    }
1368
1369
    /**
1370
     * Get theme.
1371
     *
1372
     * @return string
1373
     */
1374
    public function getTheme()
1375
    {
1376
        return $this->theme;
1377
    }
1378
1379
    /**
1380
     * Set hrDeptId.
1381
     *
1382
     * @param int $hrDeptId
1383
     *
1384
     * @return User
1385
     */
1386
    public function setHrDeptId($hrDeptId)
1387
    {
1388
        $this->hrDeptId = $hrDeptId;
1389
1390
        return $this;
1391
    }
1392
1393
    /**
1394
     * Get hrDeptId.
1395
     *
1396
     * @return int
1397
     */
1398
    public function getHrDeptId()
1399
    {
1400
        return $this->hrDeptId;
1401
    }
1402
1403
    /**
1404
     * @return Media
1405
     */
1406
    public function getAvatar()
1407
    {
1408
        return $this->getPictureUri();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getPictureUri() returns the type string which is incompatible with the documented return type Chamilo\UserBundle\Entity\Media.
Loading history...
1409
    }
1410
1411
    /**
1412
     * @param int $size
1413
     *
1414
     * @return string
1415
     */
1416
    public function getAvatarOrAnonymous($size = 22)
1417
    {
1418
        $avatar = $this->getAvatar();
1419
1420
        if (empty($avatar)) {
1421
            return "img/icons/$size/unknown.png";
1422
        }
1423
1424
        return $avatar;
1425
    }
1426
1427
    /**
1428
     * @return \DateTime
1429
     */
1430
    public function getMemberSince()
1431
    {
1432
        return $this->registrationDate;
1433
    }
1434
1435
    /**
1436
     * @return bool
1437
     */
1438
    public function isOnline()
1439
    {
1440
        return false;
1441
    }
1442
1443
    /**
1444
     * @return int
1445
     */
1446
    public function getIdentifier()
1447
    {
1448
        return $this->getId();
1449
    }
1450
1451
    /**
1452
     * @return string
1453
     */
1454
    public function getSlug()
1455
    {
1456
        return $this->getUsername();
1457
    }
1458
1459
    /**
1460
     * @param $slug
1461
     *
1462
     * @return User
1463
     */
1464
    public function setSlug($slug)
1465
    {
1466
        return $this->setUsername($slug);
1467
    }
1468
1469
    /**
1470
     * Set lastLogin.
1471
     *
1472
     * @param \DateTime $lastLogin
1473
     *
1474
     * @return User
1475
     */
1476
    public function setLastLogin(\DateTime $lastLogin = null)
1477
    {
1478
        $this->lastLogin = $lastLogin;
0 ignored issues
show
Bug Best Practice introduced by
The property lastLogin does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1479
1480
        return $this;
1481
    }
1482
1483
    /**
1484
     * Get lastLogin.
1485
     *
1486
     * @return \DateTime
1487
     */
1488
    public function getLastLogin()
1489
    {
1490
        return $this->lastLogin;
1491
    }
1492
1493
    /**
1494
     * Get sessionCourseSubscription.
1495
     *
1496
     * @return ArrayCollection
1497
     */
1498
    public function getSessionCourseSubscriptions()
1499
    {
1500
        return $this->sessionCourseSubscriptions;
1501
    }
1502
1503
    /**
1504
     * @param $value
1505
     *
1506
     * @return $this
1507
     */
1508
    public function setSessionCourseSubscriptions($value)
1509
    {
1510
        $this->sessionCourseSubscriptions = $value;
1511
1512
        return $this;
1513
    }
1514
1515
    /**
1516
     * @return string
1517
     */
1518
    public function getConfirmationToken()
1519
    {
1520
        return $this->confirmationToken;
1521
    }
1522
1523
    /**
1524
     * @param string $confirmationToken
1525
     *
1526
     * @return User
1527
     */
1528
    public function setConfirmationToken($confirmationToken)
1529
    {
1530
        $this->confirmationToken = $confirmationToken;
0 ignored issues
show
Bug Best Practice introduced by
The property confirmationToken does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1531
1532
        return $this;
1533
    }
1534
1535
    /**
1536
     * @return \DateTime
1537
     */
1538
    public function getPasswordRequestedAt()
1539
    {
1540
        return $this->passwordRequestedAt;
1541
    }
1542
1543
    /**
1544
     * @param int $ttl
1545
     *
1546
     * @return bool
1547
     */
1548
    /*public function isPasswordRequestNonExpired($ttl)
1549
    {
1550
        return $this->getPasswordRequestedAt() instanceof \DateTime &&
1551
            $this->getPasswordRequestedAt()->getTimestamp() + $ttl > time();
1552
    }*/
1553
1554
    public function getUsername(): string
1555
    {
1556
        return (string) $this->username;
1557
    }
1558
1559
    /**
1560
     * Returns the expiration date.
1561
     *
1562
     * @return \DateTime|null
1563
     */
1564
    public function getExpiresAt()
1565
    {
1566
        return $this->expiresAt;
1567
    }
1568
1569
    /**
1570
     * Returns the credentials expiration date.
1571
     *
1572
     * @return \DateTime
1573
     */
1574
    public function getCredentialsExpireAt()
1575
    {
1576
        return $this->credentialsExpireAt;
1577
    }
1578
1579
    /**
1580
     * Sets the credentials expiration date.
1581
     *
1582
     * @return User
1583
     */
1584
    public function setCredentialsExpireAt(\DateTime $date = null)
1585
    {
1586
        $this->credentialsExpireAt = $date;
1587
1588
        return $this;
1589
    }
1590
1591
    /**
1592
     * Sets the user groups.
1593
     *
1594
     * @param array $groups
1595
     *
1596
     * @return User
1597
     */
1598
    public function setGroups($groups)
1599
    {
1600
        foreach ($groups as $group) {
1601
            $this->addGroup($group);
1602
        }
1603
1604
        return $this;
1605
    }
1606
1607
    /**
1608
     * @return string
1609
     */
1610
    public function getFullname()
1611
    {
1612
        return sprintf('%s %s', $this->getFirstname(), $this->getLastname());
1613
    }
1614
1615
    /**
1616
     * Returns the user roles.
1617
     *
1618
     * @return array The roles
1619
     */
1620
    public function getRoles()
1621
    {
1622
        $roles = $this->roles;
1623
1624
        foreach ($this->getGroups() as $group) {
1625
            $roles = array_merge($roles, $group->getRoles());
1626
        }
1627
1628
        // we need to make sure to have at least one role
1629
        $roles[] = static::ROLE_DEFAULT;
1630
1631
        return array_unique($roles);
1632
    }
1633
1634
    public function isAccountNonExpired()
1635
    {
1636
        /*if (true === $this->expired) {
1637
            return false;
1638
        }
1639
1640
        if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
1641
            return false;
1642
        }*/
1643
1644
        return true;
1645
    }
1646
1647
    public function isAccountNonLocked()
1648
    {
1649
        return true;
1650
        //return !$this->locked;
1651
    }
1652
1653
    public function isCredentialsNonExpired()
1654
    {
1655
        /*if (true === $this->credentialsExpired) {
1656
            return false;
1657
        }
1658
1659
        if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
1660
            return false;
1661
        }*/
1662
1663
        return true;
1664
    }
1665
1666
    /**
1667
     * @return bool
1668
     */
1669
    public function getCredentialsExpired()
1670
    {
1671
        return $this->credentialsExpired;
1672
    }
1673
1674
    /**
1675
     * @param bool $boolean
1676
     *
1677
     * @return User
1678
     */
1679
    public function setCredentialsExpired($boolean)
1680
    {
1681
        $this->credentialsExpired = $boolean;
1682
1683
        return $this;
1684
    }
1685
1686
    /**
1687
     * @param $boolean
1688
     *
1689
     * @return $this|BaseUser
1690
     */
1691
    public function setEnabled($boolean)
1692
    {
1693
        $this->enabled = (bool) $boolean;
0 ignored issues
show
Bug Best Practice introduced by
The property enabled does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1694
1695
        return $this;
1696
    }
1697
1698
    /**
1699
     * @return bool
1700
     */
1701
    public function getExpired()
1702
    {
1703
        return $this->expired;
1704
    }
1705
1706
    /**
1707
     * Sets this user to expired.
1708
     *
1709
     * @param bool $boolean
1710
     *
1711
     * @return User
1712
     */
1713
    public function setExpired($boolean)
1714
    {
1715
        $this->expired = (bool) $boolean;
1716
1717
        return $this;
1718
    }
1719
1720
    /**
1721
     * @return User
1722
     */
1723
    public function setExpiresAt(\DateTime $date)
1724
    {
1725
        $this->expiresAt = $date;
1726
1727
        return $this;
1728
    }
1729
1730
    public function getLocked(): bool
1731
    {
1732
        return $this->locked;
1733
    }
1734
1735
    /**
1736
     * @param $boolean
1737
     *
1738
     * @return $this
1739
     */
1740
    public function setLocked($boolean)
1741
    {
1742
        $this->locked = $boolean;
1743
1744
        return $this;
1745
    }
1746
1747
    /**
1748
     * @return $this
1749
     */
1750
    public function setRoles(array $roles)
1751
    {
1752
        $this->roles = [];
0 ignored issues
show
Bug Best Practice introduced by
The property roles does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1753
1754
        foreach ($roles as $role) {
1755
            $this->addRole($role);
1756
        }
1757
1758
        return $this;
1759
    }
1760
1761
    /**
1762
     * Get achievedSkills.
1763
     *
1764
     * @return ArrayCollection
1765
     */
1766
    public function getAchievedSkills()
1767
    {
1768
        return $this->achievedSkills;
1769
    }
1770
1771
    /**
1772
     * @param $value
1773
     *
1774
     * @return $this
1775
     */
1776
    public function setAchievedSkills($value)
1777
    {
1778
        $this->achievedSkills = $value;
1779
1780
        return $this;
1781
    }
1782
1783
    /**
1784
     * Check if the user has the skill.
1785
     *
1786
     * @param Skill $skill The skill
1787
     *
1788
     * @return bool
1789
     */
1790
    public function hasSkill(Skill $skill)
1791
    {
1792
        $achievedSkills = $this->getAchievedSkills();
1793
1794
        foreach ($achievedSkills as $userSkill) {
1795
            if ($userSkill->getSkill()->getId() !== $skill->getId()) {
1796
                continue;
1797
            }
1798
1799
            return true;
1800
        }
1801
    }
1802
1803
    /**
1804
     * @return bool
1805
     */
1806
    public function isProfileCompleted()
1807
    {
1808
        return $this->profileCompleted;
1809
    }
1810
1811
    /**
1812
     * @param mixed $profileCompleted
1813
     *
1814
     * @return User
1815
     */
1816
    public function setProfileCompleted($profileCompleted)
1817
    {
1818
        $this->profileCompleted = $profileCompleted;
1819
1820
        return $this;
1821
    }
1822
1823
    /**
1824
     * Sets the AccessUrl for the current user in memory.
1825
     *
1826
     * @return $this
1827
     */
1828
    public function setCurrentUrl(AccessUrl $url)
1829
    {
1830
        $urlList = $this->getPortals();
1831
        /** @var AccessUrlRelUser $item */
1832
        foreach ($urlList as $item) {
1833
            if ($item->getUrl()->getId() === $url->getId()) {
1834
                $this->currentUrl = $url;
1835
                break;
1836
            }
1837
        }
1838
1839
        return $this;
1840
    }
1841
1842
    /**
1843
     * @return AccessUrl
1844
     */
1845
    public function getCurrentUrl()
1846
    {
1847
        return $this->currentUrl;
1848
    }
1849
1850
    /**
1851
     * Get sessionAsGeneralCoach.
1852
     *
1853
     * @return ArrayCollection
1854
     */
1855
    public function getSessionAsGeneralCoach()
1856
    {
1857
        return $this->sessionAsGeneralCoach;
1858
    }
1859
1860
    /**
1861
     * Get sessionAsGeneralCoach.
1862
     *
1863
     * @param ArrayCollection $value
1864
     *
1865
     * @return $this
1866
     */
1867
    public function setSessionAsGeneralCoach($value)
1868
    {
1869
        $this->sessionAsGeneralCoach = $value;
1870
1871
        return $this;
1872
    }
1873
1874
    /**
1875
     * @return mixed
1876
     */
1877
    public function getCommentedUserSkills()
1878
    {
1879
        return $this->commentedUserSkills;
1880
    }
1881
1882
    /**
1883
     * @param mixed $commentedUserSkills
1884
     *
1885
     * @return User
1886
     */
1887
    public function setCommentedUserSkills($commentedUserSkills)
1888
    {
1889
        $this->commentedUserSkills = $commentedUserSkills;
1890
1891
        return $this;
1892
    }
1893
1894
    /**
1895
     * @return bool
1896
     */
1897
    public function isEqualTo(UserInterface $user)
1898
    {
1899
        if ($this->password !== $user->getPassword()) {
1900
            return false;
1901
        }
1902
1903
        if ($this->salt !== $user->getSalt()) {
1904
            return false;
1905
        }
1906
1907
        if ($this->username !== $user->getUsername()) {
1908
            return false;
1909
        }
1910
1911
        return true;
1912
    }
1913
1914
    public function getPictureLegacy(): string
1915
    {
1916
        $id = $this->id;
1917
        $uri = $this->getPictureUri();
1918
        if ($uri) {
1919
            return 'users/'.substr((string) $id, 0, 1).'/'.$id.'/'.'small_'.$uri;
1920
        }
1921
1922
        return '';
1923
    }
1924
1925
    /**
1926
     * Get sentMessages.
1927
     *
1928
     * @return ArrayCollection
1929
     */
1930
    public function getSentMessages()
1931
    {
1932
        return $this->sentMessages;
1933
    }
1934
1935
    /**
1936
     * Get receivedMessages.
1937
     *
1938
     * @return ArrayCollection
1939
     */
1940
    public function getReceivedMessages()
1941
    {
1942
        return $this->receivedMessages;
1943
    }
1944
1945
    /**
1946
     * @param int $lastId Optional. The ID of the last received message
1947
     */
1948
    public function getUnreadReceivedMessages($lastId = 0): ArrayCollection
1949
    {
1950
        $criteria = Criteria::create();
1951
        $criteria->where(
1952
            Criteria::expr()->eq('msgStatus', MESSAGE_STATUS_UNREAD)
1953
        );
1954
1955
        if ($lastId > 0) {
1956
            $criteria->andWhere(
1957
                Criteria::expr()->gt('id', (int) $lastId)
1958
            );
1959
        }
1960
1961
        $criteria->orderBy(['sendDate' => Criteria::DESC]);
1962
1963
        return $this->receivedMessages->matching($criteria);
1964
    }
1965
1966
    public function getCourseGroupsAsMember(): Collection
1967
    {
1968
        return $this->courseGroupsAsMember;
1969
    }
1970
1971
    public function getCourseGroupsAsTutor(): Collection
1972
    {
1973
        return $this->courseGroupsAsTutor;
1974
    }
1975
1976
    public function getCourseGroupsAsMemberFromCourse(Course $course): ArrayCollection
1977
    {
1978
        $criteria = Criteria::create();
1979
        $criteria->where(
1980
            Criteria::expr()->eq('cId', $course)
1981
        );
1982
1983
        return $this->courseGroupsAsMember->matching($criteria);
1984
    }
1985
1986
    public function getCourseGroupsAsTutorFromCourse(Course $course): ArrayCollection
1987
    {
1988
        $criteria = Criteria::create();
1989
        $criteria->where(
1990
            Criteria::expr()->eq('cId', $course->getId())
1991
        );
1992
1993
        return $this->courseGroupsAsTutor->matching($criteria);
1994
    }
1995
}
1996