Passed
Push — master ( 8dc8d6...0b0f56 )
by Julito
10:41
created

User::setParent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

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

2408
            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...
2409
                $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

2409
                /** @scrutinizer ignore-call */ 
2410
                $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...
2410
            }
2411
        }
2412
2413
        return $sessions;
2414
    }
2415
2416
    /**
2417
     * Retreives this user's related DRH sessions.
2418
     *
2419
     * @return Session[]
2420
     */
2421
    public function getDRHSessions()
2422
    {
2423
        return $this->getSessions(1);
2424
    }
2425
2426
    /**
2427
     * Get this user's related accessible sessions of a type, student by default.
2428
     *
2429
     * @param int $relationType \Chamilo\CoreBundle\Entity\SessionRelUser::relationTypeList key
2430
     *
2431
     * @return Session[]
2432
     */
2433
    public function getCurrentlyAccessibleSessions($relationType = 0)
2434
    {
2435
        $sessions = [];
2436
        foreach ($this->getSessions($relationType) as $session) {
2437
            if ($session->isCurrentlyAccessible()) {
2438
                $sessions[] = $session;
2439
            }
2440
        }
2441
2442
        return $sessions;
2443
    }
2444
2445
    public function getResourceIdentifier(): int
2446
    {
2447
        return $this->id;
2448
    }
2449
2450
    public function getResourceName(): string
2451
    {
2452
        return $this->getUsername();
2453
    }
2454
2455
    public function setResourceName(string $name)
2456
    {
2457
        $this->setUsername($name);
2458
    }
2459
2460
    public function setParent(AbstractResource $parent)
2461
    {
2462
    }
2463
2464
    /**
2465
     * Find the largest sort value in a given UserCourseCategory
2466
     * This method is used when we are moving a course to a different category
2467
     * and also when a user subscribes to courses (the new course is added at the end of the main category).
2468
     *
2469
     * Used to be implemented in global function \api_max_sort_value.
2470
     * Reimplemented using the ORM cache.
2471
     *
2472
     * @param UserCourseCategory|null $userCourseCategory the user_course_category
2473
     *
2474
     * @return int|mixed
2475
     */
2476
    public function getMaxSortValue($userCourseCategory = null)
2477
    {
2478
        $categoryCourses = $this->courses->matching(
2479
            Criteria::create()
2480
                ->where(Criteria::expr()->neq('relationType', COURSE_RELATION_TYPE_RRHH))
2481
                ->andWhere(Criteria::expr()->eq('userCourseCat', $userCourseCategory))
2482
        );
2483
2484
        return $categoryCourses->isEmpty()
2485
            ? 0
2486
            : max(
2487
                $categoryCourses->map(
2488
                    /** @var CourseRelUser $courseRelUser */
2489
                    function ($courseRelUser) {
2490
                        return $courseRelUser->getSort();
2491
                    }
2492
                )->toArray()
2493
            );
2494
    }
2495
}
2496