Passed
Push — master ( 29e9e9...f3e5fb )
by Julito
09:23
created

User::getPictureLegacy()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10

1 Method

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