Passed
Push — master ( db12d9...b58c60 )
by Julito
12:19
created

User::getCourses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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

2343
            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...
2344
                $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

2344
                /** @scrutinizer ignore-call */ 
2345
                $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...
2345
            }
2346
        }
2347
2348
        return $sessions;
2349
    }
2350
2351
    /**
2352
     * Retreives this user's related student sessions.
2353
     *
2354
     * @return Session[]
2355
     */
2356
    public function getStudentSessions()
2357
    {
2358
        return $this->getSessions(0);
2359
    }
2360
2361
    /**
2362
     * Retreives this user's related DRH sessions.
2363
     *
2364
     * @return Session[]
2365
     */
2366
    public function getDRHSessions()
2367
    {
2368
        return $this->getSessions(1);
2369
    }
2370
2371
    /**
2372
     * Get this user's related accessible sessions of a type, student by default.
2373
     *
2374
     * @param int $relationType \Chamilo\CoreBundle\Entity\SessionRelUser::relationTypeList key
2375
     *
2376
     * @return Session[]
2377
     */
2378
    public function getCurrentlyAccessibleSessions($relationType = 0)
2379
    {
2380
        $sessions = [];
2381
        foreach ($this->getSessions($relationType) as $session) {
2382
            if ($session->isCurrentlyAccessible()) {
2383
                $sessions[] = $session;
2384
            }
2385
        }
2386
2387
        return $sessions;
2388
    }
2389
2390
    /**
2391
     * Find the largest sort value in a given UserCourseCategory
2392
     * This method is used when we are moving a course to a different category
2393
     * and also when a user subscribes to courses (the new course is added at the end of the main category).
2394
     *
2395
     * Used to be implemented in global function \api_max_sort_value.
2396
     * Reimplemented using the ORM cache.
2397
     *
2398
     * @param UserCourseCategory|null $userCourseCategory the user_course_category
2399
     *
2400
     * @return int|mixed
2401
     */
2402
    public function getMaxSortValue($userCourseCategory = null)
2403
    {
2404
        $categoryCourses = $this->courses->matching(
2405
            Criteria::create()
2406
                ->where(Criteria::expr()->neq('relationType', COURSE_RELATION_TYPE_RRHH))
2407
                ->andWhere(Criteria::expr()->eq('userCourseCat', $userCourseCategory))
2408
        );
2409
2410
        return $categoryCourses->isEmpty()
2411
            ? 0
2412
            : max(
2413
                $categoryCourses->map(
2414
                    /** @var CourseRelUser $courseRelUser */
2415
                    function ($courseRelUser) {
2416
                        return $courseRelUser->getSort();
2417
                    }
2418
                )->toArray()
2419
            );
2420
    }
2421
}
2422