Passed
Push — master ( 41516e...c87549 )
by Julito
13:42
created

User::isPasswordRequestNonExpired()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 1
b 0
f 1
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Entity;
6
7
use ApiPlatform\Core\Annotation\ApiFilter;
8
use ApiPlatform\Core\Annotation\ApiProperty;
9
use ApiPlatform\Core\Annotation\ApiResource;
10
use ApiPlatform\Core\Annotation\ApiSubresource;
11
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
12
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
13
use Chamilo\CourseBundle\Entity\CGroupRelUser;
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 Ramsey\Uuid\Uuid;
20
use Ramsey\Uuid\UuidInterface;
21
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
22
use Symfony\Component\Security\Core\User\EquatableInterface;
23
use Symfony\Component\Security\Core\User\UserInterface;
24
use Symfony\Component\Serializer\Annotation\Groups;
25
use Symfony\Component\Validator\Constraints as Assert;
26
use Symfony\Component\Validator\Mapping\ClassMetadata;
27
28
/**
29
 * @ApiResource(
30
 *      attributes={"security"="is_granted('ROLE_ADMIN')"},
31
 *      iri="http://schema.org/Person",
32
 *      normalizationContext={"groups"={"user:read"}},
33
 *      denormalizationContext={"groups"={"user:write"}},
34
 *      collectionOperations={"get"},
35
 *      itemOperations={
36
 *          "get"={},
37
 *          "put"={},
38
 *          "delete"={},
39
 *     }
40
 * )
41
 *
42
 * @ApiFilter(SearchFilter::class, properties={"username": "partial", "firstname" : "partial"})
43
 * @ApiFilter(BooleanFilter::class, properties={"isActive"})
44
 *
45
 * @ORM\HasLifecycleCallbacks
46
 * @ORM\Table(
47
 *  name="user",
48
 *  indexes={
49
 *      @ORM\Index(name="status", columns={"status"})
50
 *  }
51
 * )
52
 * @UniqueEntity("username")
53
 * @ORM\Entity
54
 */
55
class User implements UserInterface, EquatableInterface
56
{
57
    public const ROLE_DEFAULT = 'ROLE_USER';
58
    public const ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN';
59
60
    public const COURSE_MANAGER = 1;
61
    public const TEACHER = 1;
62
    public const SESSION_ADMIN = 3;
63
    public const DRH = 4;
64
    public const STUDENT = 5;
65
    public const ANONYMOUS = 6;
66
67
    /**
68
     * @var int
69
     * @Groups({"user:read", "resource_node:read"})
70
     * @ORM\Column(name="id", type="integer")
71
     * @ORM\Id
72
     * @ORM\GeneratedValue(strategy="AUTO")
73
     */
74
    protected $id;
75
76
    /**
77
     * @var UuidInterface|null
78
     *
79
     * @ORM\Column(type="uuid", unique=true)
80
     */
81
    protected $uuid;
82
83
    /**
84
     * @ORM\Column(type="string", unique=true, nullable=true)
85
     */
86
    protected $apiToken;
87
88
    /**
89
     * @var string
90
     * @Assert\NotBlank()
91
     * @ApiProperty(iri="http://schema.org/name")
92
     * @Groups({"user:read", "user:write", "resource_node:read"})
93
     * @ORM\Column(name="firstname", type="string", length=64, nullable=true, unique=false)
94
     */
95
    protected $firstname;
96
97
    /**
98
     * @var string
99
     * @Groups({"user:read", "user:write", "resource_node:read"})
100
     * @ORM\Column(name="lastname", type="string", length=64, nullable=true, unique=false)
101
     */
102
    protected $lastname;
103
104
    /**
105
     * @var string
106
     * @Groups({"user:read", "user:write"})
107
     * @ORM\Column(name="website", type="string", length=64, nullable=true)
108
     */
109
    protected $website;
110
111
    /**
112
     * @var string
113
     * @Groups({"user:read", "user:write"})
114
     * @ORM\Column(name="biography", type="text", nullable=true)
115
     */
116
    protected $biography;
117
118
    /**
119
     * @var string
120
     * @Groups({"user:read", "user:write"})
121
     * @ORM\Column(name="locale", type="string", length=8, nullable=true, unique=false)
122
     */
123
    protected $locale;
124
125
    /**
126
     * @var string
127
     * @Groups({"user:read", "user:write", "course:read", "resource_node:read"})
128
     * @Assert\NotBlank()
129
     * @ORM\Column(name="username", type="string", length=100, nullable=false, unique=true)
130
     */
131
    protected $username;
132
133
    /**
134
     * @var string|null
135
     */
136
    protected $plainPassword;
137
138
    /**
139
     * @var string
140
     * @ORM\Column(name="password", type="string", length=255, nullable=false, unique=false)
141
     */
142
    protected $password;
143
144
    /**
145
     * @var string
146
     *
147
     * @ORM\Column(name="username_canonical", type="string", length=180, nullable=false)
148
     */
149
    protected $usernameCanonical;
150
151
    /**
152
     * @var string
153
     * @Groups({"user:read", "user:write"})
154
     * @ORM\Column(name="timezone", type="string", length=64)
155
     */
156
    protected $timezone;
157
158
    /**
159
     * @var string
160
     * @ORM\Column(name="email_canonical", type="string", length=100, nullable=false, unique=false)
161
     */
162
    protected $emailCanonical;
163
164
    /**
165
     * @var string
166
     * @var string
167
     * @Groups({"user:read", "user:write"})
168
     * @Assert\NotBlank()
169
     * @Assert\Email()
170
     *
171
     * @ORM\Column(name="email", type="string", length=100, nullable=false, unique=false)
172
     */
173
    protected $email;
174
175
    /**
176
     * @var bool
177
     *
178
     * @ORM\Column(name="locked", type="boolean")
179
     */
180
    protected $locked;
181
182
    /**
183
     * @var bool
184
     * @Assert\NotBlank()
185
     * @Groups({"user:read", "user:write"})
186
     * @ORM\Column(name="enabled", type="boolean")
187
     */
188
    protected $enabled;
189
190
    /**
191
     * @var bool
192
     * @Groups({"user:read", "user:write"})
193
     * @ORM\Column(name="expired", type="boolean")
194
     */
195
    protected $expired;
196
197
    /**
198
     * @var bool
199
     *
200
     * @ORM\Column(name="credentials_expired", type="boolean")
201
     */
202
    protected $credentialsExpired;
203
204
    /**
205
     * @var \DateTime
206
     *
207
     * @ORM\Column(name="credentials_expire_at", type="datetime", nullable=true, unique=false)
208
     */
209
    protected $credentialsExpireAt;
210
211
    /**
212
     * @var \DateTime
213
     *
214
     * @ORM\Column(name="date_of_birth", type="datetime", nullable=true)
215
     */
216
    protected $dateOfBirth;
217
218
    /**
219
     * @var \DateTime
220
     * @Groups({"user:read", "user:write"})
221
     * @ORM\Column(name="expires_at", type="datetime", nullable=true, unique=false)
222
     */
223
    protected $expiresAt;
224
225
    /**
226
     * @var string
227
     * @Groups({"user:read", "user:write"})
228
     * @ORM\Column(name="phone", type="string", length=64, nullable=true, unique=false)
229
     */
230
    protected $phone;
231
232
    /**
233
     * @var string
234
     * @Groups({"user:read", "user:write"})
235
     * @ORM\Column(name="address", type="string", length=250, nullable=true, unique=false)
236
     */
237
    protected $address;
238
239
    /**
240
     * @var AccessUrl
241
     */
242
    protected $currentUrl;
243
244
    /**
245
     * @ORM\Column(type="string", length=255)
246
     */
247
    protected $salt;
248
249
    /**
250
     * @var \DateTime
251
     * @Groups({"user:read", "user:write"})
252
     * @ORM\Column(name="last_login", type="datetime", nullable=true, unique=false)
253
     */
254
    protected $lastLogin;
255
256
    /**
257
     * Random string sent to the user email address in order to verify it.
258
     *
259
     * @var string
260
     * @ORM\Column(name="confirmation_token", type="string", length=255, nullable=true)
261
     */
262
    protected $confirmationToken;
263
264
    /**
265
     * @var \DateTime
266
     *
267
     * @ORM\Column(name="password_requested_at", type="datetime", nullable=true, unique=false)
268
     */
269
    protected $passwordRequestedAt;
270
271
    /**
272
     * @var CourseRelUser[]|ArrayCollection
273
     *
274
     * @ApiSubresource()
275
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CourseRelUser", mappedBy="user", orphanRemoval=true)
276
     */
277
    protected $courses;
278
279
    /**
280
     * @var UsergroupRelUser[]|ArrayCollection
281
     *
282
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\UsergroupRelUser", mappedBy="user")
283
     */
284
    protected $classes;
285
286
    /**
287
     * ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CDropboxPost", mappedBy="user").
288
     */
289
    protected $dropBoxReceivedFiles;
290
291
    /**
292
     * ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CDropboxFile", mappedBy="userSent").
293
     */
294
    protected $dropBoxSentFiles;
295
296
    /**
297
     * @Groups({"user:read", "user:write"})
298
     * @ORM\Column(type="array")
299
     */
300
    protected $roles;
301
302
    /**
303
     * @var bool
304
     *
305
     * @ORM\Column(name="profile_completed", type="boolean", nullable=true)
306
     */
307
    protected $profileCompleted;
308
309
    /**
310
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\JuryMembers", mappedBy="user")
311
     */
312
    //protected $jurySubscriptions;
313
314
    /**
315
     * @var Group[]
316
     * @ORM\ManyToMany(targetEntity="Chamilo\CoreBundle\Entity\Group", inversedBy="users")
317
     * @ORM\JoinTable(
318
     *      name="fos_user_user_group",
319
     *      joinColumns={
320
     *          @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="cascade")
321
     *      },
322
     *      inverseJoinColumns={
323
     *          @ORM\JoinColumn(name="group_id", referencedColumnName="id")
324
     *      }
325
     * )
326
     */
327
    protected $groups;
328
329
    /**
330
     * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CurriculumItemRelUser", mappedBy="user").
331
     */
332
    protected $curriculumItems;
333
334
    /**
335
     * @var AccessUrlRelUser[]|ArrayCollection
336
     *
337
     * @ORM\OneToMany(
338
     *     targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelUser",
339
     *     mappedBy="user",
340
     *     cascade={"persist", "remove"},
341
     *     orphanRemoval=true
342
     * )
343
     */
344
    protected $portals;
345
346
    /**
347
     * @var ArrayCollection
348
     *
349
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Session", mappedBy="generalCoach")
350
     */
351
    protected $sessionAsGeneralCoach;
352
353
    /**
354
     * @ORM\OneToOne(
355
     *     targetEntity="Chamilo\CoreBundle\Entity\ResourceNode", cascade={"remove"}, orphanRemoval=true
356
     * )
357
     * @ORM\JoinColumn(name="resource_node_id", referencedColumnName="id", onDelete="CASCADE")
358
     */
359
    protected $resourceNode;
360
361
    /**
362
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\ResourceNode", mappedBy="creator")
363
     */
364
    protected $resourceNodes;
365
366
    /**
367
     * @ApiSubresource()
368
     * @ORM\OneToMany(
369
     *     targetEntity="Chamilo\CoreBundle\Entity\SessionRelCourseRelUser",
370
     *     mappedBy="user",
371
     *     cascade={"persist"},
372
     *     orphanRemoval=true
373
     * )
374
     */
375
    protected $sessionCourseSubscriptions;
376
377
    /**
378
     * @ORM\OneToMany(
379
     *     targetEntity="Chamilo\CoreBundle\Entity\SkillRelUser",
380
     *     mappedBy="user",
381
     *     cascade={"persist", "remove"},
382
     *     orphanRemoval=true
383
     * )
384
     */
385
    protected $achievedSkills;
386
387
    /**
388
     * @ORM\OneToMany(
389
     *     targetEntity="Chamilo\CoreBundle\Entity\SkillRelUserComment",
390
     *     mappedBy="feedbackGiver",
391
     *     cascade={"persist", "remove"},
392
     *     orphanRemoval=true
393
     * )
394
     */
395
    protected $commentedUserSkills;
396
397
    /**
398
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\GradebookCategory", mappedBy="user")
399
     */
400
    protected $gradeBookCategories;
401
402
    /**
403
     * @var Session[]|ArrayCollection
404
     *
405
     * @ORM\OneToMany(
406
     *     targetEntity="Chamilo\CoreBundle\Entity\SessionRelUser",
407
     *     mappedBy="user",
408
     *     cascade={"persist", "remove"},
409
     *     orphanRemoval=true
410
     * )
411
     */
412
    protected $sessions;
413
414
    /**
415
     * @var CGroupRelUser[]|ArrayCollection
416
     *
417
     * @ORM\OneToMany(
418
     *     targetEntity="Chamilo\CourseBundle\Entity\CGroupRelUser",
419
     *     mappedBy="user",
420
     *     cascade={"persist", "remove"},
421
     *     orphanRemoval=true
422
     * )
423
     */
424
    protected $courseGroupsAsMember;
425
426
    /**
427
     * @var Collection
428
     *
429
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CGroupRelTutor", mappedBy="user", orphanRemoval=true)
430
     */
431
    protected $courseGroupsAsTutor;
432
433
    /**
434
     * @var string
435
     *
436
     * @ORM\Column(name="auth_source", type="string", length=50, nullable=true, unique=false)
437
     */
438
    protected $authSource;
439
440
    /**
441
     * @var int
442
     *
443
     * @ORM\Column(name="status", type="integer", nullable=false)
444
     */
445
    protected $status;
446
447
    /**
448
     * @var string
449
     *
450
     * @ORM\Column(name="official_code", type="string", length=40, nullable=true, unique=false)
451
     */
452
    protected $officialCode;
453
454
    /**
455
     * @var string
456
     *
457
     * @ORM\Column(name="picture_uri", type="string", length=250, nullable=true, unique=false)
458
     */
459
    protected $pictureUri;
460
461
    /**
462
     * @var int
463
     *
464
     * @ORM\Column(name="creator_id", type="integer", nullable=true, unique=false)
465
     */
466
    protected $creatorId;
467
468
    /**
469
     * @var string
470
     *
471
     * @ORM\Column(name="competences", type="text", nullable=true, unique=false)
472
     */
473
    protected $competences;
474
475
    /**
476
     * @var string
477
     *
478
     * @ORM\Column(name="diplomas", type="text", nullable=true, unique=false)
479
     */
480
    protected $diplomas;
481
482
    /**
483
     * @var string
484
     *
485
     * @ORM\Column(name="openarea", type="text", nullable=true, unique=false)
486
     */
487
    protected $openarea;
488
489
    /**
490
     * @var string
491
     *
492
     * @ORM\Column(name="teach", type="text", nullable=true, unique=false)
493
     */
494
    protected $teach;
495
496
    /**
497
     * @var string
498
     *
499
     * @ORM\Column(name="productions", type="string", length=250, nullable=true, unique=false)
500
     */
501
    protected $productions;
502
503
    /**
504
     * @var string
505
     *
506
     * @ORM\Column(name="language", type="string", length=40, nullable=true, unique=false)
507
     */
508
    protected $language;
509
510
    /**
511
     * @var \DateTime
512
     *
513
     * @ORM\Column(name="registration_date", type="datetime", nullable=false, unique=false)
514
     */
515
    protected $registrationDate;
516
517
    /**
518
     * @var \DateTime
519
     *
520
     * @ORM\Column(name="expiration_date", type="datetime", nullable=true, unique=false)
521
     */
522
    protected $expirationDate;
523
524
    /**
525
     * @var bool
526
     *
527
     * @ORM\Column(name="active", type="boolean", nullable=false, unique=false)
528
     */
529
    protected $active;
530
531
    /**
532
     * @var string
533
     *
534
     * @ORM\Column(name="openid", type="string", length=255, nullable=true, unique=false)
535
     */
536
    protected $openid;
537
538
    /**
539
     * @var string
540
     *
541
     * @ORM\Column(name="theme", type="string", length=255, nullable=true, unique=false)
542
     */
543
    protected $theme;
544
545
    /**
546
     * @var int
547
     *
548
     * @ORM\Column(name="hr_dept_id", type="smallint", nullable=true, unique=false)
549
     */
550
    protected $hrDeptId;
551
552
    /**
553
     * @var ArrayCollection
554
     *
555
     * @ORM\OneToMany(
556
     *     targetEntity="Chamilo\CoreBundle\Entity\Message",
557
     *     mappedBy="userSender",
558
     *     cascade={"persist", "remove"},
559
     *     orphanRemoval=true
560
     * )
561
     */
562
    protected $sentMessages;
563
564
    /**
565
     * @var ArrayCollection
566
     *
567
     * @ORM\OneToMany(
568
     *     targetEntity="Chamilo\CoreBundle\Entity\Message",
569
     *     mappedBy="userReceiver",
570
     *     cascade={"persist", "remove"},
571
     *     orphanRemoval=true
572
     * )
573
     */
574
    protected $receivedMessages;
575
576
    /**
577
     * @var \DateTime
578
     * @ORM\Column(name="created_at", type="datetime", nullable=true, unique=false)
579
     */
580
    protected $createdAt;
581
582
    /**
583
     * @var \DateTime
584
     * @ORM\Column(name="updated_at", type="datetime", nullable=true, unique=false)
585
     */
586
    protected $updatedAt;
587
588
    /**
589
     * Constructor.
590
     */
591
    public function __construct()
592
    {
593
        $this->uuid = Uuid::uuid4()->toString();
594
        $this->status = self::STUDENT;
595
        $this->salt = sha1(uniqid(null, true));
596
        $this->active = true;
597
        $this->registrationDate = new \DateTime();
598
        $this->authSource = 'platform';
599
        $this->courses = new ArrayCollection();
600
        //$this->items = new ArrayCollection();
601
        $this->classes = new ArrayCollection();
602
        $this->curriculumItems = new ArrayCollection();
603
        $this->portals = new ArrayCollection();
604
        $this->dropBoxSentFiles = new ArrayCollection();
605
        $this->dropBoxReceivedFiles = new ArrayCollection();
606
        $this->groups = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Doctrine\Common\Collections\ArrayCollection() of type Doctrine\Common\Collections\ArrayCollection is incompatible with the declared type Chamilo\CoreBundle\Entity\Group[] of property $groups.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
607
        //$this->extraFields = new ArrayCollection();
608
        $this->createdAt = new \DateTime();
609
        $this->updatedAt = new \DateTime();
610
611
        $this->enabled = false;
612
        $this->locked = false;
613
        $this->expired = false;
614
        $this->roles = [];
615
        $this->credentialsExpired = false;
616
617
        $this->courseGroupsAsMember = new ArrayCollection();
618
        $this->courseGroupsAsTutor = new ArrayCollection();
619
    }
620
621
    /**
622
     * @return string
623
     */
624
    public function __toString()
625
    {
626
        return $this->username;
627
    }
628
629
    /**
630
     * @return int
631
     */
632
    public function getId()
633
    {
634
        return $this->id;
635
    }
636
637
    /**
638
     * @param int $userId
639
     */
640
    public function setId($userId)
641
    {
642
        $this->id = $userId;
643
    }
644
645
    public function getUuid(): UuidInterface
646
    {
647
        return $this->uuid;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->uuid could return the type null which is incompatible with the type-hinted return Ramsey\Uuid\UuidInterface. Consider adding an additional type-check to rule them out.
Loading history...
648
    }
649
650
    public function setResourceNode(ResourceNode $resourceNode): self
651
    {
652
        $this->resourceNode = $resourceNode;
653
654
        return $this;
655
    }
656
657
    public function getResourceNode(): ResourceNode
658
    {
659
        return $this->resourceNode;
660
    }
661
662
    /**
663
     * @return ArrayCollection|ResourceNode[]
664
     */
665
    public function getResourceNodes()
666
    {
667
        return $this->resourceNodes;
668
    }
669
670
    /**
671
     * @return User
672
     */
673
    public function setResourceNodes($resourceNodes)
674
    {
675
        $this->resourceNodes = $resourceNodes;
676
677
        return $this;
678
    }
679
680
    /**
681
     * @ORM\PostPersist()
682
     */
683
    public function postPersist(LifecycleEventArgs $args)
684
    {
685
        /*$user = $args->getEntity();
686
        */
687
    }
688
689
    /**
690
     * @return ArrayCollection
691
     */
692
    public function getDropBoxSentFiles()
693
    {
694
        return $this->dropBoxSentFiles;
695
    }
696
697
    /**
698
     * @return ArrayCollection
699
     */
700
    public function getDropBoxReceivedFiles()
701
    {
702
        return $this->dropBoxReceivedFiles;
703
    }
704
705
    /**
706
     * @param ArrayCollection $value
707
     */
708
    public function setDropBoxSentFiles($value)
709
    {
710
        $this->dropBoxSentFiles = $value;
711
    }
712
713
    /**
714
     * @param ArrayCollection $value
715
     */
716
    public function setDropBoxReceivedFiles($value)
717
    {
718
        $this->dropBoxReceivedFiles = $value;
719
    }
720
721
    /**
722
     * @param ArrayCollection $courses
723
     */
724
    public function setCourses($courses): self
725
    {
726
        $this->courses = $courses;
727
728
        return $this;
729
    }
730
731
    public function getCourses()
732
    {
733
        return $this->courses;
734
    }
735
736
    /**
737
     * @return array
738
     */
739
    public static function getPasswordConstraints()
740
    {
741
        return
742
            [
743
                new Assert\Length(['min' => 5]),
744
                // Alpha numeric + "_" or "-"
745
                new Assert\Regex(
746
                    [
747
                        'pattern' => '/^[a-z\-_0-9]+$/i',
748
                        'htmlPattern' => '/^[a-z\-_0-9]+$/i', ]
749
                ),
750
                // Min 3 letters - not needed
751
                /*new Assert\Regex(array(
752
                    'pattern' => '/[a-z]{3}/i',
753
                    'htmlPattern' => '/[a-z]{3}/i')
754
                ),*/
755
                // Min 2 numbers
756
                new Assert\Regex(
757
                    [
758
                        'pattern' => '/[0-9]{2}/',
759
                        'htmlPattern' => '/[0-9]{2}/', ]
760
                ),
761
            ]
762
            ;
763
    }
764
765
    public static function loadValidatorMetadata(ClassMetadata $metadata)
766
    {
767
        //$metadata->addPropertyConstraint('firstname', new Assert\NotBlank());
768
        //$metadata->addPropertyConstraint('lastname', new Assert\NotBlank());
769
        //$metadata->addPropertyConstraint('email', new Assert\Email());
770
        /*
771
        $metadata->addPropertyConstraint('password',
772
            new Assert\Collection(self::getPasswordConstraints())
773
        );*/
774
775
        /*$metadata->addConstraint(new UniqueEntity(array(
776
            'fields'  => 'username',
777
            'message' => 'This value is already used.',
778
        )));*/
779
780
        /*$metadata->addPropertyConstraint(
781
            'username',
782
            new Assert\Length(array(
783
                'min'        => 2,
784
                'max'        => 50,
785
                '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.',
786
                '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.',
787
            ))
788
        );*/
789
    }
790
791
    /**
792
     * @return ArrayCollection
793
     */
794
    public function getPortals()
795
    {
796
        return $this->portals;
797
    }
798
799
    /**
800
     * @param $portal
801
     */
802
    public function setPortal($portal)
803
    {
804
        $this->portals->add($portal);
805
    }
806
807
    public function setPortals(array $value)
808
    {
809
        $this->portals = $value;
810
    }
811
812
    /**
813
     * @return ArrayCollection
814
     */
815
    public function getCurriculumItems()
816
    {
817
        return $this->curriculumItems;
818
    }
819
820
    public function setCurriculumItems(array $items): self
821
    {
822
        $this->curriculumItems = $items;
823
824
        return $this;
825
    }
826
827
    public function getIsActive(): bool
828
    {
829
        return true === $this->active;
830
    }
831
832
    public function isActive(): bool
833
    {
834
        return $this->getIsActive();
835
    }
836
837
    public function isEnabled()
838
    {
839
        return $this->isActive();
840
    }
841
842
    /**
843
     * Set salt.
844
     *
845
     * @param string $salt
846
     *
847
     * @return User
848
     */
849
    public function setSalt($salt)
850
    {
851
        $this->salt = $salt;
852
853
        return $this;
854
    }
855
856
    /**
857
     * Get salt.
858
     *
859
     * @return string
860
     */
861
    public function getSalt()
862
    {
863
        return $this->salt;
864
    }
865
866
    /**
867
     * @param ArrayCollection $classes
868
     *
869
     * @return $this
870
     */
871
    public function setClasses($classes)
872
    {
873
        $this->classes = $classes;
874
875
        return $this;
876
    }
877
878
    /**
879
     * @return ArrayCollection
880
     */
881
    public function getClasses()
882
    {
883
        return $this->classes;
884
    }
885
886
    public function getLps()
887
    {
888
        //return $this->lps;
889
        /*$criteria = Criteria::create()
890
            ->where(Criteria::expr()->eq("id", "666"))
891
            //->orderBy(array("username" => "ASC"))
892
            //->setFirstResult(0)
893
            //->setMaxResults(20)
894
        ;
895
        $lps = $this->lps->matching($criteria);*/
896
        /*return $this->lps->filter(
897
            function($entry) use ($idsToFilter) {
898
                return $entry->getId() == 1;
899
        });*/
900
    }
901
902
    /**
903
     * Returns the list of classes for the user.
904
     *
905
     * @return string
906
     */
907
    public function getCompleteNameWithClasses()
908
    {
909
        $classSubscription = $this->getClasses();
910
        $classList = [];
911
        /** @var UsergroupRelUser $subscription */
912
        foreach ($classSubscription as $subscription) {
913
            $class = $subscription->getUsergroup();
914
            $classList[] = $class->getName();
915
        }
916
        $classString = !empty($classList) ? ' ['.implode(', ', $classList).']' : null;
917
918
        return \UserManager::formatUserFullName($this).$classString;
919
    }
920
921
    /**
922
     * Set lastname.
923
     *
924
     * @return User
925
     */
926
    public function setLastname(string $lastname): self
927
    {
928
        $this->lastname = $lastname;
929
930
        return $this;
931
    }
932
933
    /**
934
     * Set firstname.
935
     *
936
     * @return User
937
     */
938
    public function setFirstname(string $firstname): self
939
    {
940
        $this->firstname = $firstname;
941
942
        return $this;
943
    }
944
945
    public function getPassword()
946
    {
947
        return $this->password;
948
    }
949
950
    public function setPassword(string $password): self
951
    {
952
        $this->password = $password;
953
954
        return $this;
955
    }
956
957
    /**
958
     * Set authSource.
959
     *
960
     * @param string $authSource
961
     *
962
     * @return User
963
     */
964
    public function setAuthSource($authSource)
965
    {
966
        $this->authSource = $authSource;
967
968
        return $this;
969
    }
970
971
    /**
972
     * Get authSource.
973
     *
974
     * @return string
975
     */
976
    public function getAuthSource()
977
    {
978
        return $this->authSource;
979
    }
980
981
    /**
982
     * Set email.
983
     *
984
     * @param string $email
985
     *
986
     * @return User
987
     */
988
    public function setEmail($email)
989
    {
990
        $this->email = $email;
991
992
        return $this;
993
    }
994
995
    /**
996
     * Get email.
997
     *
998
     * @return string
999
     */
1000
    public function getEmail()
1001
    {
1002
        return $this->email;
1003
    }
1004
1005
    /**
1006
     * Set status.
1007
     *
1008
     * @return User
1009
     */
1010
    public function setStatus(int $status)
1011
    {
1012
        $this->status = $status;
1013
1014
        return $this;
1015
    }
1016
1017
    /**
1018
     * Get status.
1019
     *
1020
     * @return int
1021
     */
1022
    public function getStatus()
1023
    {
1024
        return (int) $this->status;
1025
    }
1026
1027
    /**
1028
     * Set officialCode.
1029
     *
1030
     * @param string $officialCode
1031
     *
1032
     * @return User
1033
     */
1034
    public function setOfficialCode($officialCode)
1035
    {
1036
        $this->officialCode = $officialCode;
1037
1038
        return $this;
1039
    }
1040
1041
    /**
1042
     * Get officialCode.
1043
     *
1044
     * @return string
1045
     */
1046
    public function getOfficialCode()
1047
    {
1048
        return $this->officialCode;
1049
    }
1050
1051
    /**
1052
     * Set phone.
1053
     *
1054
     * @param string $phone
1055
     *
1056
     * @return User
1057
     */
1058
    public function setPhone($phone)
1059
    {
1060
        $this->phone = $phone;
1061
1062
        return $this;
1063
    }
1064
1065
    /**
1066
     * Get phone.
1067
     *
1068
     * @return string
1069
     */
1070
    public function getPhone()
1071
    {
1072
        return $this->phone;
1073
    }
1074
1075
    /**
1076
     * Set address.
1077
     *
1078
     * @param string $address
1079
     *
1080
     * @return User
1081
     */
1082
    public function setAddress($address)
1083
    {
1084
        $this->address = $address;
1085
1086
        return $this;
1087
    }
1088
1089
    /**
1090
     * Get address.
1091
     *
1092
     * @return string
1093
     */
1094
    public function getAddress()
1095
    {
1096
        return $this->address;
1097
    }
1098
1099
    /**
1100
     * Set creatorId.
1101
     *
1102
     * @param int $creatorId
1103
     *
1104
     * @return User
1105
     */
1106
    public function setCreatorId($creatorId)
1107
    {
1108
        $this->creatorId = $creatorId;
1109
1110
        return $this;
1111
    }
1112
1113
    /**
1114
     * Get creatorId.
1115
     *
1116
     * @return int
1117
     */
1118
    public function getCreatorId()
1119
    {
1120
        return $this->creatorId;
1121
    }
1122
1123
    /**
1124
     * Set competences.
1125
     *
1126
     * @param string $competences
1127
     *
1128
     * @return User
1129
     */
1130
    public function setCompetences($competences)
1131
    {
1132
        $this->competences = $competences;
1133
1134
        return $this;
1135
    }
1136
1137
    /**
1138
     * Get competences.
1139
     *
1140
     * @return string
1141
     */
1142
    public function getCompetences()
1143
    {
1144
        return $this->competences;
1145
    }
1146
1147
    /**
1148
     * Set diplomas.
1149
     *
1150
     * @param string $diplomas
1151
     *
1152
     * @return User
1153
     */
1154
    public function setDiplomas($diplomas)
1155
    {
1156
        $this->diplomas = $diplomas;
1157
1158
        return $this;
1159
    }
1160
1161
    /**
1162
     * Get diplomas.
1163
     *
1164
     * @return string
1165
     */
1166
    public function getDiplomas()
1167
    {
1168
        return $this->diplomas;
1169
    }
1170
1171
    /**
1172
     * Set openarea.
1173
     *
1174
     * @param string $openarea
1175
     *
1176
     * @return User
1177
     */
1178
    public function setOpenarea($openarea)
1179
    {
1180
        $this->openarea = $openarea;
1181
1182
        return $this;
1183
    }
1184
1185
    /**
1186
     * Get openarea.
1187
     *
1188
     * @return string
1189
     */
1190
    public function getOpenarea()
1191
    {
1192
        return $this->openarea;
1193
    }
1194
1195
    /**
1196
     * Set teach.
1197
     *
1198
     * @param string $teach
1199
     *
1200
     * @return User
1201
     */
1202
    public function setTeach($teach)
1203
    {
1204
        $this->teach = $teach;
1205
1206
        return $this;
1207
    }
1208
1209
    /**
1210
     * Get teach.
1211
     *
1212
     * @return string
1213
     */
1214
    public function getTeach()
1215
    {
1216
        return $this->teach;
1217
    }
1218
1219
    /**
1220
     * Set productions.
1221
     *
1222
     * @param string $productions
1223
     *
1224
     * @return User
1225
     */
1226
    public function setProductions($productions)
1227
    {
1228
        $this->productions = $productions;
1229
1230
        return $this;
1231
    }
1232
1233
    /**
1234
     * Get productions.
1235
     *
1236
     * @return string
1237
     */
1238
    public function getProductions()
1239
    {
1240
        return $this->productions;
1241
    }
1242
1243
    /**
1244
     * Set language.
1245
     *
1246
     * @param string $language
1247
     *
1248
     * @return User
1249
     */
1250
    public function setLanguage($language)
1251
    {
1252
        $this->language = $language;
1253
1254
        return $this;
1255
    }
1256
1257
    /**
1258
     * Get language.
1259
     *
1260
     * @return string
1261
     */
1262
    public function getLanguage()
1263
    {
1264
        return $this->language;
1265
    }
1266
1267
    /**
1268
     * Set registrationDate.
1269
     *
1270
     * @param \DateTime $registrationDate
1271
     *
1272
     * @return User
1273
     */
1274
    public function setRegistrationDate($registrationDate)
1275
    {
1276
        $this->registrationDate = $registrationDate;
1277
1278
        return $this;
1279
    }
1280
1281
    /**
1282
     * Get registrationDate.
1283
     *
1284
     * @return \DateTime
1285
     */
1286
    public function getRegistrationDate()
1287
    {
1288
        return $this->registrationDate;
1289
    }
1290
1291
    /**
1292
     * Set expirationDate.
1293
     *
1294
     * @param \DateTime $expirationDate
1295
     *
1296
     * @return User
1297
     */
1298
    public function setExpirationDate($expirationDate)
1299
    {
1300
        $this->expirationDate = $expirationDate;
1301
1302
        return $this;
1303
    }
1304
1305
    /**
1306
     * Get expirationDate.
1307
     *
1308
     * @return \DateTime
1309
     */
1310
    public function getExpirationDate()
1311
    {
1312
        return $this->expirationDate;
1313
    }
1314
1315
    /**
1316
     * Set active.
1317
     *
1318
     * @param bool $active
1319
     *
1320
     * @return User
1321
     */
1322
    public function setActive($active)
1323
    {
1324
        $this->active = $active;
1325
1326
        return $this;
1327
    }
1328
1329
    /**
1330
     * Get active.
1331
     *
1332
     * @return bool
1333
     */
1334
    public function getActive()
1335
    {
1336
        return $this->active;
1337
    }
1338
1339
    /**
1340
     * Set openid.
1341
     *
1342
     * @param string $openid
1343
     *
1344
     * @return User
1345
     */
1346
    public function setOpenid($openid)
1347
    {
1348
        $this->openid = $openid;
1349
1350
        return $this;
1351
    }
1352
1353
    /**
1354
     * Get openid.
1355
     *
1356
     * @return string
1357
     */
1358
    public function getOpenid()
1359
    {
1360
        return $this->openid;
1361
    }
1362
1363
    /**
1364
     * Set theme.
1365
     *
1366
     * @param string $theme
1367
     *
1368
     * @return User
1369
     */
1370
    public function setTheme($theme)
1371
    {
1372
        $this->theme = $theme;
1373
1374
        return $this;
1375
    }
1376
1377
    /**
1378
     * Get theme.
1379
     *
1380
     * @return string
1381
     */
1382
    public function getTheme()
1383
    {
1384
        return $this->theme;
1385
    }
1386
1387
    /**
1388
     * Set hrDeptId.
1389
     *
1390
     * @param int $hrDeptId
1391
     *
1392
     * @return User
1393
     */
1394
    public function setHrDeptId($hrDeptId)
1395
    {
1396
        $this->hrDeptId = $hrDeptId;
1397
1398
        return $this;
1399
    }
1400
1401
    /**
1402
     * Get hrDeptId.
1403
     *
1404
     * @return int
1405
     */
1406
    public function getHrDeptId()
1407
    {
1408
        return $this->hrDeptId;
1409
    }
1410
1411
    /**
1412
     * @return \DateTime
1413
     */
1414
    public function getMemberSince()
1415
    {
1416
        return $this->registrationDate;
1417
    }
1418
1419
    /**
1420
     * @return bool
1421
     */
1422
    public function isOnline()
1423
    {
1424
        return false;
1425
    }
1426
1427
    /**
1428
     * @return int
1429
     */
1430
    public function getIdentifier()
1431
    {
1432
        return $this->getId();
1433
    }
1434
1435
    /**
1436
     * @return string
1437
     */
1438
    public function getSlug()
1439
    {
1440
        return $this->getUsername();
1441
    }
1442
1443
    /**
1444
     * @param string $slug
1445
     *
1446
     * @return User
1447
     */
1448
    public function setSlug($slug)
1449
    {
1450
        return $this->setUsername($slug);
1451
    }
1452
1453
    public function setUsername($username): self
1454
    {
1455
        $this->username = $username;
1456
1457
        return $this;
1458
    }
1459
1460
    public function setUsernameCanonical($usernameCanonical)
1461
    {
1462
        $this->usernameCanonical = $usernameCanonical;
1463
1464
        return $this;
1465
    }
1466
1467
    public function setEmailCanonical($emailCanonical): self
1468
    {
1469
        $this->emailCanonical = $emailCanonical;
1470
1471
        return $this;
1472
    }
1473
1474
    /**
1475
     * Set lastLogin.
1476
     *
1477
     * @param \DateTime $lastLogin
1478
     */
1479
    public function setLastLogin(\DateTime $lastLogin = null): self
1480
    {
1481
        $this->lastLogin = $lastLogin;
1482
1483
        return $this;
1484
    }
1485
1486
    /**
1487
     * Get lastLogin.
1488
     *
1489
     * @return \DateTime
1490
     */
1491
    public function getLastLogin()
1492
    {
1493
        return $this->lastLogin;
1494
    }
1495
1496
    /**
1497
     * Get sessionCourseSubscription.
1498
     *
1499
     * @return ArrayCollection
1500
     */
1501
    public function getSessionCourseSubscriptions()
1502
    {
1503
        return $this->sessionCourseSubscriptions;
1504
    }
1505
1506
    public function setSessionCourseSubscriptions(array $value): self
1507
    {
1508
        $this->sessionCourseSubscriptions = $value;
1509
1510
        return $this;
1511
    }
1512
1513
    /**
1514
     * @return string
1515
     */
1516
    public function getConfirmationToken()
1517
    {
1518
        return $this->confirmationToken;
1519
    }
1520
1521
    /**
1522
     * @param string $confirmationToken
1523
     */
1524
    public function setConfirmationToken($confirmationToken): self
1525
    {
1526
        $this->confirmationToken = $confirmationToken;
1527
1528
        return $this;
1529
    }
1530
1531
    /**
1532
     * @return \DateTime
1533
     */
1534
    public function getPasswordRequestedAt()
1535
    {
1536
        return $this->passwordRequestedAt;
1537
    }
1538
1539
    public function isPasswordRequestNonExpired($ttl)
1540
    {
1541
        return $this->getPasswordRequestedAt() instanceof \DateTime &&
1542
            $this->getPasswordRequestedAt()->getTimestamp() + $ttl > time();
1543
    }
1544
1545
    public function getUsername(): string
1546
    {
1547
        return (string) $this->username;
1548
    }
1549
1550
    public function getPlainPassword(): ?string
1551
    {
1552
        return $this->plainPassword;
1553
    }
1554
1555
    public function setPlainPassword(string $password): self
1556
    {
1557
        $this->plainPassword = $password;
1558
1559
        // forces the object to look "dirty" to Doctrine. Avoids
1560
        // Doctrine *not* saving this entity, if only plainPassword changes
1561
        $this->password = null;
1562
1563
        return $this;
1564
    }
1565
1566
    /**
1567
     * Returns the expiration date.
1568
     *
1569
     * @return \DateTime|null
1570
     */
1571
    public function getExpiresAt()
1572
    {
1573
        return $this->expiresAt;
1574
    }
1575
1576
    /**
1577
     * Returns the credentials expiration date.
1578
     *
1579
     * @return \DateTime
1580
     */
1581
    public function getCredentialsExpireAt()
1582
    {
1583
        return $this->credentialsExpireAt;
1584
    }
1585
1586
    /**
1587
     * Sets the credentials expiration date.
1588
     */
1589
    public function setCredentialsExpireAt(\DateTime $date = null): self
1590
    {
1591
        $this->credentialsExpireAt = $date;
1592
1593
        return $this;
1594
    }
1595
1596
    public function addGroup($group): self
1597
    {
1598
        if (!$this->getGroups()->contains($group)) {
1599
            $this->getGroups()->add($group);
1600
        }
1601
1602
        return $this;
1603
    }
1604
1605
    /**
1606
     * Sets the user groups.
1607
     *
1608
     * @param array $groups
1609
     */
1610
    public function setGroups($groups): self
1611
    {
1612
        foreach ($groups as $group) {
1613
            $this->addGroup($group);
1614
        }
1615
1616
        return $this;
1617
    }
1618
1619
    public function getFullname(): string
1620
    {
1621
        return sprintf('%s %s', $this->getFirstname(), $this->getLastname());
1622
    }
1623
1624
    public function getGroups()
1625
    {
1626
        return $this->groups;
1627
    }
1628
1629
    public function getGroupNames(): array
1630
    {
1631
        $names = [];
1632
        foreach ($this->getGroups() as $group) {
1633
            $names[] = $group->getName();
1634
        }
1635
1636
        return $names;
1637
    }
1638
1639
    /**
1640
     * @param string $name
1641
     */
1642
    public function hasGroup($name): bool
1643
    {
1644
        return in_array($name, $this->getGroupNames());
1645
    }
1646
1647
    public function removeGroup($group): self
1648
    {
1649
        if ($this->getGroups()->contains($group)) {
1650
            $this->getGroups()->removeElement($group);
1651
        }
1652
1653
        return $this;
1654
    }
1655
1656
    /**
1657
     * @param string $role
1658
     */
1659
    public function addRole($role): self
1660
    {
1661
        $role = strtoupper($role);
1662
        if ($role === static::ROLE_DEFAULT) {
1663
            return $this;
1664
        }
1665
1666
        if (!in_array($role, $this->roles, true)) {
1667
            $this->roles[] = $role;
1668
        }
1669
1670
        return $this;
1671
    }
1672
1673
    /**
1674
     * Returns the user roles.
1675
     *
1676
     * @return array The roles
1677
     */
1678
    public function getRoles()
1679
    {
1680
        $roles = $this->roles;
1681
1682
        foreach ($this->getGroups() as $group) {
1683
            $roles = array_merge($roles, $group->getRoles());
1684
        }
1685
1686
        // we need to make sure to have at least one role
1687
        $roles[] = 'ROLE_USER';
1688
1689
        return array_unique($roles);
1690
    }
1691
1692
    public function isAccountNonExpired()
1693
    {
1694
        /*if (true === $this->expired) {
1695
            return false;
1696
        }
1697
1698
        if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
1699
            return false;
1700
        }*/
1701
1702
        return true;
1703
    }
1704
1705
    public function isAccountNonLocked()
1706
    {
1707
        return true;
1708
        //return !$this->locked;
1709
    }
1710
1711
    public function isCredentialsNonExpired()
1712
    {
1713
        /*if (true === $this->credentialsExpired) {
1714
            return false;
1715
        }
1716
1717
        if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
1718
            return false;
1719
        }*/
1720
1721
        return true;
1722
    }
1723
1724
    /**
1725
     * @return bool
1726
     */
1727
    public function getCredentialsExpired()
1728
    {
1729
        return $this->credentialsExpired;
1730
    }
1731
1732
    /**
1733
     * @param bool $boolean
1734
     */
1735
    public function setCredentialsExpired($boolean): self
1736
    {
1737
        $this->credentialsExpired = $boolean;
1738
1739
        return $this;
1740
    }
1741
1742
    /**
1743
     * @param $boolean
1744
     */
1745
    public function setEnabled($boolean): self
1746
    {
1747
        $this->enabled = (bool) $boolean;
1748
1749
        return $this;
1750
    }
1751
1752
    /**
1753
     * @return bool
1754
     */
1755
    public function getExpired()
1756
    {
1757
        return $this->expired;
1758
    }
1759
1760
    /**
1761
     * Sets this user to expired.
1762
     *
1763
     * @param bool $boolean
1764
     */
1765
    public function setExpired($boolean): self
1766
    {
1767
        $this->expired = (bool) $boolean;
1768
1769
        return $this;
1770
    }
1771
1772
    public function setExpiresAt(\DateTime $date): self
1773
    {
1774
        $this->expiresAt = $date;
1775
1776
        return $this;
1777
    }
1778
1779
    public function getLocked(): bool
1780
    {
1781
        return $this->locked;
1782
    }
1783
1784
    /**
1785
     * @param $boolean
1786
     */
1787
    public function setLocked($boolean): self
1788
    {
1789
        $this->locked = $boolean;
1790
1791
        return $this;
1792
    }
1793
1794
    public function setPasswordRequestedAt(\DateTime $date = null)
1795
    {
1796
        $this->passwordRequestedAt = $date;
1797
1798
        return $this;
1799
    }
1800
1801
    public function setRoles(array $roles): self
1802
    {
1803
        $this->roles = [];
1804
1805
        foreach ($roles as $role) {
1806
            $this->addRole($role);
1807
        }
1808
1809
        return $this;
1810
    }
1811
1812
    /**
1813
     * Get achievedSkills.
1814
     *
1815
     * @return ArrayCollection
1816
     */
1817
    public function getAchievedSkills()
1818
    {
1819
        return $this->achievedSkills;
1820
    }
1821
1822
    /**
1823
     * @param string[] $value
1824
     */
1825
    public function setAchievedSkills(array $value): self
1826
    {
1827
        $this->achievedSkills = $value;
1828
1829
        return $this;
1830
    }
1831
1832
    /**
1833
     * Check if the user has the skill.
1834
     *
1835
     * @param Skill $skill The skill
1836
     */
1837
    public function hasSkill(Skill $skill): bool
1838
    {
1839
        $achievedSkills = $this->getAchievedSkills();
1840
1841
        foreach ($achievedSkills as $userSkill) {
1842
            if ($userSkill->getSkill()->getId() !== $skill->getId()) {
1843
                continue;
1844
            }
1845
1846
            return true;
1847
        }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
1848
    }
1849
1850
    /**
1851
     * @return bool
1852
     */
1853
    public function isProfileCompleted()
1854
    {
1855
        return $this->profileCompleted;
1856
    }
1857
1858
    public function setProfileCompleted($profileCompleted): self
1859
    {
1860
        $this->profileCompleted = $profileCompleted;
1861
1862
        return $this;
1863
    }
1864
1865
    /**
1866
     * Sets the AccessUrl for the current user in memory.
1867
     */
1868
    public function setCurrentUrl(AccessUrl $url): self
1869
    {
1870
        $urlList = $this->getPortals();
1871
        /** @var AccessUrlRelUser $item */
1872
        foreach ($urlList as $item) {
1873
            if ($item->getUrl()->getId() === $url->getId()) {
1874
                $this->currentUrl = $url;
1875
1876
                break;
1877
            }
1878
        }
1879
1880
        return $this;
1881
    }
1882
1883
    /**
1884
     * @return AccessUrl
1885
     */
1886
    public function getCurrentUrl()
1887
    {
1888
        return $this->currentUrl;
1889
    }
1890
1891
    /**
1892
     * Get sessionAsGeneralCoach.
1893
     *
1894
     * @return ArrayCollection
1895
     */
1896
    public function getSessionAsGeneralCoach()
1897
    {
1898
        return $this->sessionAsGeneralCoach;
1899
    }
1900
1901
    /**
1902
     * Get sessionAsGeneralCoach.
1903
     *
1904
     * @param ArrayCollection $value
1905
     */
1906
    public function setSessionAsGeneralCoach($value): self
1907
    {
1908
        $this->sessionAsGeneralCoach = $value;
1909
1910
        return $this;
1911
    }
1912
1913
    public function getCommentedUserSkills()
1914
    {
1915
        return $this->commentedUserSkills;
1916
    }
1917
1918
    /**
1919
     * @return User
1920
     */
1921
    public function setCommentedUserSkills(array $commentedUserSkills): self
1922
    {
1923
        $this->commentedUserSkills = $commentedUserSkills;
1924
1925
        return $this;
1926
    }
1927
1928
    /**
1929
     * @return bool
1930
     */
1931
    public function isEqualTo(UserInterface $user)
1932
    {
1933
        if ($this->password !== $user->getPassword()) {
1934
            return false;
1935
        }
1936
1937
        if ($this->salt !== $user->getSalt()) {
1938
            return false;
1939
        }
1940
1941
        if ($this->username !== $user->getUsername()) {
1942
            return false;
1943
        }
1944
1945
        return true;
1946
    }
1947
1948
    /**
1949
     * Get sentMessages.
1950
     *
1951
     * @return ArrayCollection
1952
     */
1953
    public function getSentMessages()
1954
    {
1955
        return $this->sentMessages;
1956
    }
1957
1958
    /**
1959
     * Get receivedMessages.
1960
     *
1961
     * @return ArrayCollection
1962
     */
1963
    public function getReceivedMessages()
1964
    {
1965
        return $this->receivedMessages;
1966
    }
1967
1968
    /**
1969
     * @param int $lastId Optional. The ID of the last received message
1970
     */
1971
    public function getUnreadReceivedMessages($lastId = 0): ArrayCollection
1972
    {
1973
        $criteria = Criteria::create();
1974
        $criteria->where(
1975
            Criteria::expr()->eq('msgStatus', MESSAGE_STATUS_UNREAD)
1976
        );
1977
1978
        if ($lastId > 0) {
1979
            $criteria->andWhere(
1980
                Criteria::expr()->gt('id', (int) $lastId)
1981
            );
1982
        }
1983
1984
        $criteria->orderBy(['sendDate' => Criteria::DESC]);
1985
1986
        return $this->receivedMessages->matching($criteria);
1987
    }
1988
1989
    public function getCourseGroupsAsMember(): Collection
1990
    {
1991
        return $this->courseGroupsAsMember;
1992
    }
1993
1994
    public function getCourseGroupsAsTutor(): Collection
1995
    {
1996
        return $this->courseGroupsAsTutor;
1997
    }
1998
1999
    public function getCourseGroupsAsMemberFromCourse(Course $course): ArrayCollection
2000
    {
2001
        $criteria = Criteria::create();
2002
        $criteria->where(
2003
            Criteria::expr()->eq('cId', $course)
2004
        );
2005
2006
        return $this->courseGroupsAsMember->matching($criteria);
2007
    }
2008
2009
    public function getFirstname()
2010
    {
2011
        return $this->firstname;
2012
    }
2013
2014
    public function getLastname()
2015
    {
2016
        return $this->lastname;
2017
    }
2018
2019
    public function eraseCredentials()
2020
    {
2021
        $this->plainPassword = null;
2022
    }
2023
2024
    public function hasRole($role)
2025
    {
2026
        return in_array(strtoupper($role), $this->getRoles(), true);
2027
    }
2028
2029
    public function isSuperAdmin()
2030
    {
2031
        return $this->hasRole('ROLE_SUPER_ADMIN');
2032
    }
2033
2034
    public function isUser(UserInterface $user = null)
2035
    {
2036
        return null !== $user && $this->getId() === $user->getId();
2037
    }
2038
2039
    public function removeRole($role)
2040
    {
2041
        if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
2042
            unset($this->roles[$key]);
2043
            $this->roles = array_values($this->roles);
2044
        }
2045
2046
        return $this;
2047
    }
2048
2049
    public function getUsernameCanonical()
2050
    {
2051
        return $this->usernameCanonical;
2052
    }
2053
2054
    public function getEmailCanonical()
2055
    {
2056
        return $this->emailCanonical;
2057
    }
2058
2059
    /**
2060
     * @param string $timezone
2061
     *
2062
     * @return User
2063
     */
2064
    public function setTimezone($timezone)
2065
    {
2066
        $this->timezone = $timezone;
2067
2068
        return $this;
2069
    }
2070
2071
    /**
2072
     * @return string
2073
     */
2074
    public function getTimezone()
2075
    {
2076
        return $this->timezone;
2077
    }
2078
2079
    /**
2080
     * @param string $locale
2081
     *
2082
     * @return User
2083
     */
2084
    public function setLocale($locale)
2085
    {
2086
        $this->locale = $locale;
2087
2088
        return $this;
2089
    }
2090
2091
    /**
2092
     * @return string
2093
     */
2094
    public function getLocale()
2095
    {
2096
        return $this->locale;
2097
    }
2098
2099
    /**
2100
     * @return string
2101
     */
2102
    public function getApiToken()
2103
    {
2104
        return $this->apiToken;
2105
    }
2106
2107
    /**
2108
     * @param string $apiToken
2109
     *
2110
     * @return User
2111
     */
2112
    public function setApiToken($apiToken)
2113
    {
2114
        $this->apiToken = $apiToken;
2115
2116
        return $this;
2117
    }
2118
2119
    public function getWebsite(): ?string
2120
    {
2121
        return $this->website;
2122
    }
2123
2124
    public function setWebsite(string $website): self
2125
    {
2126
        $this->website = $website;
2127
2128
        return $this;
2129
    }
2130
2131
    public function getBiography(): ?string
2132
    {
2133
        return $this->biography;
2134
    }
2135
2136
    public function setBiography(string $biography): self
2137
    {
2138
        $this->biography = $biography;
2139
2140
        return $this;
2141
    }
2142
2143
    /**
2144
     * @param \DateTime $dateOfBirth
2145
     */
2146
    public function setDateOfBirth($dateOfBirth): self
2147
    {
2148
        $this->dateOfBirth = $dateOfBirth;
2149
2150
        return $this;
2151
    }
2152
2153
    /**
2154
     * @return \DateTime
2155
     */
2156
    public function getDateOfBirth()
2157
    {
2158
        return $this->dateOfBirth;
2159
    }
2160
2161
    public function getCourseGroupsAsTutorFromCourse(Course $course): ArrayCollection
2162
    {
2163
        $criteria = Criteria::create();
2164
        $criteria->where(
2165
            Criteria::expr()->eq('cId', $course->getId())
2166
        );
2167
2168
        return $this->courseGroupsAsTutor->matching($criteria);
2169
    }
2170
2171
    /**
2172
     * Retreives this user's related sessions.
2173
     *
2174
     * @param int $relationType \Chamilo\CoreBundle\Entity\SessionRelUser::relationTypeList key
2175
     *
2176
     * @return Session[]
2177
     */
2178
    public function getSessions($relationType)
2179
    {
2180
        $sessions = [];
2181
        foreach ($this->sessions as $sessionRelUser) {
2182
            if ($sessionRelUser->getRelationType() == $relationType) {
0 ignored issues
show
Bug introduced by
The method getRelationType() does not exist on Chamilo\CoreBundle\Entity\Session. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2182
            if ($sessionRelUser->/** @scrutinizer ignore-call */ getRelationType() == $relationType) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2183
                $sessions[] = $sessionRelUser->getSession();
0 ignored issues
show
Bug introduced by
The method getSession() does not exist on Chamilo\CoreBundle\Entity\Session. Did you maybe mean getSessionAdmin()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2183
                /** @scrutinizer ignore-call */ 
2184
                $sessions[] = $sessionRelUser->getSession();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2184
            }
2185
        }
2186
2187
        return $sessions;
2188
    }
2189
2190
    /**
2191
     * Retreives this user's related student sessions.
2192
     *
2193
     * @return Session[]
2194
     */
2195
    public function getStudentSessions()
2196
    {
2197
        return $this->getSessions(0);
2198
    }
2199
2200
    /**
2201
     * Retreives this user's related DRH sessions.
2202
     *
2203
     * @return Session[]
2204
     */
2205
    public function getDRHSessions()
2206
    {
2207
        return $this->getSessions(1);
2208
    }
2209
2210
    /**
2211
     * Get this user's related accessible sessions of a type, student by default.
2212
     *
2213
     * @param int $relationType \Chamilo\CoreBundle\Entity\SessionRelUser::relationTypeList key
2214
     *
2215
     * @return Session[]
2216
     */
2217
    public function getCurrentlyAccessibleSessions($relationType = 0)
2218
    {
2219
        $sessions = [];
2220
        foreach ($this->getSessions($relationType) as $session) {
2221
            if ($session->isCurrentlyAccessible()) {
2222
                $sessions[] = $session;
2223
            }
2224
        }
2225
2226
        return $sessions;
2227
    }
2228
2229
    /**
2230
     * Find the largest sort value in a given UserCourseCategory
2231
     * This method is used when we are moving a course to a different category
2232
     * and also when a user subscribes to courses (the new course is added at the end of the main category).
2233
     *
2234
     * Used to be implemented in global function \api_max_sort_value.
2235
     * Reimplemented using the ORM cache.
2236
     *
2237
     * @param UserCourseCategory|null $userCourseCategory the user_course_category
2238
     *
2239
     * @return int|mixed
2240
     */
2241
    public function getMaxSortValue($userCourseCategory = null)
2242
    {
2243
        $categoryCourses = $this->courses->matching(
2244
            Criteria::create()
2245
                ->where(Criteria::expr()->neq('relationType', COURSE_RELATION_TYPE_RRHH))
2246
                ->andWhere(Criteria::expr()->eq('userCourseCat', $userCourseCategory))
2247
        );
2248
2249
        return $categoryCourses->isEmpty()
2250
            ? 0
2251
            : max(
2252
                $categoryCourses->map(
2253
                    /** @var CourseRelUser $courseRelUser */
2254
                    function ($courseRelUser) {
2255
                        return $courseRelUser->getSort();
2256
                    }
2257
                )->toArray()
2258
            );
2259
    }
2260
}
2261