Completed
Push — master ( 65b406...199b8a )
by Julito
14:24 queued 12s
created

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