Passed
Push — master ( 5e2840...d88203 )
by Julito
07:41
created

User::setApiToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 1
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\Validator\Constraints as Assert;
26
use Symfony\Component\Validator\Mapping\ClassMetadata;
27
28
/**
29
 * @ApiResource(
30
 *      attributes={"security"="is_granted('ROLE_ADMIN')"},
31
 *      iri="http://schema.org/Person",
32
 *      normalizationContext={"groups"={"user:read"}},
33
 *      denormalizationContext={"groups"={"user:write"}},
34
 *      collectionOperations={"get"},
35
 *      itemOperations={
36
 *          "get"={},
37
 *          "put"={},
38
 *          "delete"={},
39
 *     }
40
 * )
41
 *
42
 * @ApiFilter(SearchFilter::class, properties={"username": "partial", "firstname" : "partial"})
43
 * @ApiFilter(BooleanFilter::class, properties={"isActive"})
44
 *
45
 * @ORM\HasLifecycleCallbacks
46
 * @ORM\Table(
47
 *  name="user",
48
 *  indexes={
49
 *      @ORM\Index(name="status", columns={"status"})
50
 *  }
51
 * )
52
 * @UniqueEntity("username")
53
 * @ORM\Entity
54
 */
55
class User implements UserInterface, EquatableInterface
56
{
57
    use TimestampableEntity;
58
59
    public const ROLE_DEFAULT = 'ROLE_USER';
60
    public const ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN';
61
62
    public const COURSE_MANAGER = 1;
63
    public const TEACHER = 1;
64
    public const SESSION_ADMIN = 3;
65
    public const DRH = 4;
66
    public const STUDENT = 5;
67
    public const ANONYMOUS = 6;
68
69
    /**
70
     * @var int
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 $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->status = self::STUDENT;
747
        $this->salt = sha1(uniqid(null, true));
748
        $this->active = true;
749
        $this->registrationDate = new \DateTime();
750
        $this->authSource = 'platform';
751
        $this->courses = new ArrayCollection();
752
        //$this->items = new ArrayCollection();
753
        $this->classes = new ArrayCollection();
754
        $this->curriculumItems = new ArrayCollection();
755
        $this->portals = new ArrayCollection();
756
        $this->dropBoxSentFiles = new ArrayCollection();
757
        $this->dropBoxReceivedFiles = new ArrayCollection();
758
        $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...
759
        //$this->extraFields = new ArrayCollection();
760
        $this->createdAt = new \DateTime();
761
        $this->updatedAt = new \DateTime();
762
763
        $this->enabled = false;
764
        $this->locked = false;
765
        $this->expired = false;
766
        $this->roles = [];
767
        $this->credentialsExpired = false;
768
769
        $this->courseGroupsAsMember = new ArrayCollection();
770
        $this->courseGroupsAsTutor = new ArrayCollection();
771
    }
772
773
    /**
774
     * @return string
775
     */
776
    public function __toString()
777
    {
778
        return $this->username;
779
    }
780
781
    /**
782
     * @return int
783
     */
784
    public function getId()
785
    {
786
        return $this->id;
787
    }
788
789
    /**
790
     * @param int $userId
791
     */
792
    public function setId($userId)
793
    {
794
        $this->id = $userId;
795
    }
796
797
    public function getUuid()
798
    {
799
        return $this->uuid;
800
    }
801
802
    public function setResourceNode(ResourceNode $resourceNode): self
803
    {
804
        $this->resourceNode = $resourceNode;
805
806
        return $this;
807
    }
808
809
    public function getResourceNode(): ResourceNode
810
    {
811
        return $this->resourceNode;
812
    }
813
814
    public function hasResourceNode(): bool
815
    {
816
        return $this->resourceNode instanceof ResourceNode;
817
    }
818
819
    /**
820
     * @return ArrayCollection|ResourceNode[]
821
     */
822
    public function getResourceNodes()
823
    {
824
        return $this->resourceNodes;
825
    }
826
827
    /**
828
     * @return User
829
     */
830
    public function setResourceNodes($resourceNodes)
831
    {
832
        $this->resourceNodes = $resourceNodes;
833
834
        return $this;
835
    }
836
837
    /**
838
     * @ORM\PostPersist()
839
     */
840
    public function postPersist(LifecycleEventArgs $args)
841
    {
842
        /*$user = $args->getEntity();
843
        */
844
    }
845
846
    /**
847
     * @return ArrayCollection
848
     */
849
    public function getDropBoxSentFiles()
850
    {
851
        return $this->dropBoxSentFiles;
852
    }
853
854
    /**
855
     * @return ArrayCollection
856
     */
857
    public function getDropBoxReceivedFiles()
858
    {
859
        return $this->dropBoxReceivedFiles;
860
    }
861
862
    /**
863
     * @param ArrayCollection $value
864
     */
865
    public function setDropBoxSentFiles($value)
866
    {
867
        $this->dropBoxSentFiles = $value;
868
    }
869
870
    /**
871
     * @param ArrayCollection $value
872
     */
873
    public function setDropBoxReceivedFiles($value)
874
    {
875
        $this->dropBoxReceivedFiles = $value;
876
    }
877
878
    /**
879
     * @param ArrayCollection $courses
880
     */
881
    public function setCourses($courses): self
882
    {
883
        $this->courses = $courses;
884
885
        return $this;
886
    }
887
888
    public function getCourses()
889
    {
890
        return $this->courses;
891
    }
892
893
    /**
894
     * @return array
895
     */
896
    public static function getPasswordConstraints()
897
    {
898
        return
899
            [
900
                new Assert\Length(['min' => 5]),
901
                // Alpha numeric + "_" or "-"
902
                new Assert\Regex(
903
                    [
904
                        'pattern' => '/^[a-z\-_0-9]+$/i',
905
                        'htmlPattern' => '/^[a-z\-_0-9]+$/i', ]
906
                ),
907
                // Min 3 letters - not needed
908
                /*new Assert\Regex(array(
909
                    'pattern' => '/[a-z]{3}/i',
910
                    'htmlPattern' => '/[a-z]{3}/i')
911
                ),*/
912
                // Min 2 numbers
913
                new Assert\Regex(
914
                    [
915
                        'pattern' => '/[0-9]{2}/',
916
                        'htmlPattern' => '/[0-9]{2}/', ]
917
                ),
918
            ]
919
            ;
920
    }
921
922
    public static function loadValidatorMetadata(ClassMetadata $metadata)
923
    {
924
        //$metadata->addPropertyConstraint('firstname', new Assert\NotBlank());
925
        //$metadata->addPropertyConstraint('lastname', new Assert\NotBlank());
926
        //$metadata->addPropertyConstraint('email', new Assert\Email());
927
        /*
928
        $metadata->addPropertyConstraint('password',
929
            new Assert\Collection(self::getPasswordConstraints())
930
        );*/
931
932
        /*$metadata->addConstraint(new UniqueEntity(array(
933
            'fields'  => 'username',
934
            'message' => 'This value is already used.',
935
        )));*/
936
937
        /*$metadata->addPropertyConstraint(
938
            'username',
939
            new Assert\Length(array(
940
                'min'        => 2,
941
                'max'        => 50,
942
                '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.',
943
                '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.',
944
            ))
945
        );*/
946
    }
947
948
    /**
949
     * @return ArrayCollection
950
     */
951
    public function getPortals()
952
    {
953
        return $this->portals;
954
    }
955
956
    /**
957
     * @param $portal
958
     */
959
    public function setPortal($portal)
960
    {
961
        $this->portals->add($portal);
962
    }
963
964
    public function setPortals(array $value)
965
    {
966
        $this->portals = $value;
967
    }
968
969
    /**
970
     * @return ArrayCollection
971
     */
972
    public function getCurriculumItems()
973
    {
974
        return $this->curriculumItems;
975
    }
976
977
    public function setCurriculumItems(array $items): self
978
    {
979
        $this->curriculumItems = $items;
980
981
        return $this;
982
    }
983
984
    public function getIsActive(): bool
985
    {
986
        return true === $this->active;
987
    }
988
989
    public function isActive(): bool
990
    {
991
        return $this->getIsActive();
992
    }
993
994
    public function isEnabled()
995
    {
996
        return $this->isActive();
997
    }
998
999
    /**
1000
     * Set salt.
1001
     *
1002
     * @param string $salt
1003
     *
1004
     * @return User
1005
     */
1006
    public function setSalt($salt)
1007
    {
1008
        $this->salt = $salt;
1009
1010
        return $this;
1011
    }
1012
1013
    /**
1014
     * Get salt.
1015
     *
1016
     * @return string
1017
     */
1018
    public function getSalt()
1019
    {
1020
        return $this->salt;
1021
    }
1022
1023
    /**
1024
     * @param ArrayCollection $classes
1025
     *
1026
     * @return $this
1027
     */
1028
    public function setClasses($classes)
1029
    {
1030
        $this->classes = $classes;
1031
1032
        return $this;
1033
    }
1034
1035
    /**
1036
     * @return ArrayCollection
1037
     */
1038
    public function getClasses()
1039
    {
1040
        return $this->classes;
1041
    }
1042
1043
    public function getLps()
1044
    {
1045
        //return $this->lps;
1046
        /*$criteria = Criteria::create()
1047
            ->where(Criteria::expr()->eq("id", "666"))
1048
            //->orderBy(array("username" => "ASC"))
1049
            //->setFirstResult(0)
1050
            //->setMaxResults(20)
1051
        ;
1052
        $lps = $this->lps->matching($criteria);*/
1053
        /*return $this->lps->filter(
1054
            function($entry) use ($idsToFilter) {
1055
                return $entry->getId() == 1;
1056
        });*/
1057
    }
1058
1059
    /**
1060
     * Returns the list of classes for the user.
1061
     *
1062
     * @return string
1063
     */
1064
    public function getCompleteNameWithClasses()
1065
    {
1066
        $classSubscription = $this->getClasses();
1067
        $classList = [];
1068
        /** @var UsergroupRelUser $subscription */
1069
        foreach ($classSubscription as $subscription) {
1070
            $class = $subscription->getUsergroup();
1071
            $classList[] = $class->getName();
1072
        }
1073
        $classString = !empty($classList) ? ' ['.implode(', ', $classList).']' : null;
1074
1075
        return \UserManager::formatUserFullName($this).$classString;
1076
    }
1077
1078
    /**
1079
     * Set lastname.
1080
     *
1081
     * @return User
1082
     */
1083
    public function setLastname(string $lastname): self
1084
    {
1085
        $this->lastname = $lastname;
1086
1087
        return $this;
1088
    }
1089
1090
    /**
1091
     * Set firstname.
1092
     *
1093
     * @return User
1094
     */
1095
    public function setFirstname(string $firstname): self
1096
    {
1097
        $this->firstname = $firstname;
1098
1099
        return $this;
1100
    }
1101
1102
    public function getPassword()
1103
    {
1104
        return $this->password;
1105
    }
1106
1107
    public function setPassword(string $password): self
1108
    {
1109
        $this->password = $password;
1110
1111
        return $this;
1112
    }
1113
1114
    /**
1115
     * Set authSource.
1116
     *
1117
     * @param string $authSource
1118
     *
1119
     * @return User
1120
     */
1121
    public function setAuthSource($authSource)
1122
    {
1123
        $this->authSource = $authSource;
1124
1125
        return $this;
1126
    }
1127
1128
    /**
1129
     * Get authSource.
1130
     *
1131
     * @return string
1132
     */
1133
    public function getAuthSource()
1134
    {
1135
        return $this->authSource;
1136
    }
1137
1138
    /**
1139
     * Set email.
1140
     *
1141
     * @param string $email
1142
     *
1143
     * @return User
1144
     */
1145
    public function setEmail($email)
1146
    {
1147
        $this->email = $email;
1148
1149
        return $this;
1150
    }
1151
1152
    /**
1153
     * Get email.
1154
     *
1155
     * @return string
1156
     */
1157
    public function getEmail()
1158
    {
1159
        return $this->email;
1160
    }
1161
1162
    /**
1163
     * Set status.
1164
     *
1165
     * @return User
1166
     */
1167
    public function setStatus(int $status)
1168
    {
1169
        $this->status = $status;
1170
1171
        return $this;
1172
    }
1173
1174
    /**
1175
     * Get status.
1176
     *
1177
     * @return int
1178
     */
1179
    public function getStatus()
1180
    {
1181
        return (int) $this->status;
1182
    }
1183
1184
    /**
1185
     * Set officialCode.
1186
     *
1187
     * @param string $officialCode
1188
     *
1189
     * @return User
1190
     */
1191
    public function setOfficialCode($officialCode)
1192
    {
1193
        $this->officialCode = $officialCode;
1194
1195
        return $this;
1196
    }
1197
1198
    /**
1199
     * Get officialCode.
1200
     *
1201
     * @return string
1202
     */
1203
    public function getOfficialCode()
1204
    {
1205
        return $this->officialCode;
1206
    }
1207
1208
    /**
1209
     * Set phone.
1210
     *
1211
     * @param string $phone
1212
     *
1213
     * @return User
1214
     */
1215
    public function setPhone($phone)
1216
    {
1217
        $this->phone = $phone;
1218
1219
        return $this;
1220
    }
1221
1222
    /**
1223
     * Get phone.
1224
     *
1225
     * @return string
1226
     */
1227
    public function getPhone()
1228
    {
1229
        return $this->phone;
1230
    }
1231
1232
    /**
1233
     * Set address.
1234
     *
1235
     * @param string $address
1236
     *
1237
     * @return User
1238
     */
1239
    public function setAddress($address)
1240
    {
1241
        $this->address = $address;
1242
1243
        return $this;
1244
    }
1245
1246
    /**
1247
     * Get address.
1248
     *
1249
     * @return string
1250
     */
1251
    public function getAddress()
1252
    {
1253
        return $this->address;
1254
    }
1255
1256
    /**
1257
     * Set creatorId.
1258
     *
1259
     * @param int $creatorId
1260
     *
1261
     * @return User
1262
     */
1263
    public function setCreatorId($creatorId)
1264
    {
1265
        $this->creatorId = $creatorId;
1266
1267
        return $this;
1268
    }
1269
1270
    /**
1271
     * Get creatorId.
1272
     *
1273
     * @return int
1274
     */
1275
    public function getCreatorId()
1276
    {
1277
        return $this->creatorId;
1278
    }
1279
1280
    /**
1281
     * Set competences.
1282
     *
1283
     * @param string $competences
1284
     *
1285
     * @return User
1286
     */
1287
    public function setCompetences($competences)
1288
    {
1289
        $this->competences = $competences;
1290
1291
        return $this;
1292
    }
1293
1294
    /**
1295
     * Get competences.
1296
     *
1297
     * @return string
1298
     */
1299
    public function getCompetences()
1300
    {
1301
        return $this->competences;
1302
    }
1303
1304
    /**
1305
     * Set diplomas.
1306
     *
1307
     * @param string $diplomas
1308
     *
1309
     * @return User
1310
     */
1311
    public function setDiplomas($diplomas)
1312
    {
1313
        $this->diplomas = $diplomas;
1314
1315
        return $this;
1316
    }
1317
1318
    /**
1319
     * Get diplomas.
1320
     *
1321
     * @return string
1322
     */
1323
    public function getDiplomas()
1324
    {
1325
        return $this->diplomas;
1326
    }
1327
1328
    /**
1329
     * Set openarea.
1330
     *
1331
     * @param string $openarea
1332
     *
1333
     * @return User
1334
     */
1335
    public function setOpenarea($openarea)
1336
    {
1337
        $this->openarea = $openarea;
1338
1339
        return $this;
1340
    }
1341
1342
    /**
1343
     * Get openarea.
1344
     *
1345
     * @return string
1346
     */
1347
    public function getOpenarea()
1348
    {
1349
        return $this->openarea;
1350
    }
1351
1352
    /**
1353
     * Set teach.
1354
     *
1355
     * @param string $teach
1356
     *
1357
     * @return User
1358
     */
1359
    public function setTeach($teach)
1360
    {
1361
        $this->teach = $teach;
1362
1363
        return $this;
1364
    }
1365
1366
    /**
1367
     * Get teach.
1368
     *
1369
     * @return string
1370
     */
1371
    public function getTeach()
1372
    {
1373
        return $this->teach;
1374
    }
1375
1376
    /**
1377
     * Set productions.
1378
     *
1379
     * @param string $productions
1380
     *
1381
     * @return User
1382
     */
1383
    public function setProductions($productions)
1384
    {
1385
        $this->productions = $productions;
1386
1387
        return $this;
1388
    }
1389
1390
    /**
1391
     * Get productions.
1392
     *
1393
     * @return string
1394
     */
1395
    public function getProductions()
1396
    {
1397
        return $this->productions;
1398
    }
1399
1400
    /**
1401
     * Set language.
1402
     */
1403
    public function setLanguage(string $language): User
1404
    {
1405
        $this->language = $language;
1406
1407
        return $this;
1408
    }
1409
1410
    /**
1411
     * Get language.
1412
     *
1413
     * @return string
1414
     */
1415
    public function getLanguage()
1416
    {
1417
        return $this->language;
1418
    }
1419
1420
    /**
1421
     * Set registrationDate.
1422
     *
1423
     * @param \DateTime $registrationDate
1424
     *
1425
     * @return User
1426
     */
1427
    public function setRegistrationDate($registrationDate)
1428
    {
1429
        $this->registrationDate = $registrationDate;
1430
1431
        return $this;
1432
    }
1433
1434
    /**
1435
     * Get registrationDate.
1436
     *
1437
     * @return \DateTime
1438
     */
1439
    public function getRegistrationDate()
1440
    {
1441
        return $this->registrationDate;
1442
    }
1443
1444
    /**
1445
     * Set expirationDate.
1446
     *
1447
     * @param \DateTime $expirationDate
1448
     *
1449
     * @return User
1450
     */
1451
    public function setExpirationDate($expirationDate)
1452
    {
1453
        $this->expirationDate = $expirationDate;
1454
1455
        return $this;
1456
    }
1457
1458
    /**
1459
     * Get expirationDate.
1460
     *
1461
     * @return \DateTime
1462
     */
1463
    public function getExpirationDate()
1464
    {
1465
        return $this->expirationDate;
1466
    }
1467
1468
    /**
1469
     * Set active.
1470
     *
1471
     * @param bool $active
1472
     *
1473
     * @return User
1474
     */
1475
    public function setActive($active)
1476
    {
1477
        $this->active = $active;
1478
1479
        return $this;
1480
    }
1481
1482
    /**
1483
     * Get active.
1484
     *
1485
     * @return bool
1486
     */
1487
    public function getActive()
1488
    {
1489
        return $this->active;
1490
    }
1491
1492
    /**
1493
     * Set openid.
1494
     *
1495
     * @param string $openid
1496
     *
1497
     * @return User
1498
     */
1499
    public function setOpenid($openid)
1500
    {
1501
        $this->openid = $openid;
1502
1503
        return $this;
1504
    }
1505
1506
    /**
1507
     * Get openid.
1508
     *
1509
     * @return string
1510
     */
1511
    public function getOpenid()
1512
    {
1513
        return $this->openid;
1514
    }
1515
1516
    /**
1517
     * Set theme.
1518
     *
1519
     * @param string $theme
1520
     *
1521
     * @return User
1522
     */
1523
    public function setTheme($theme)
1524
    {
1525
        $this->theme = $theme;
1526
1527
        return $this;
1528
    }
1529
1530
    /**
1531
     * Get theme.
1532
     *
1533
     * @return string
1534
     */
1535
    public function getTheme()
1536
    {
1537
        return $this->theme;
1538
    }
1539
1540
    /**
1541
     * Set hrDeptId.
1542
     *
1543
     * @param int $hrDeptId
1544
     *
1545
     * @return User
1546
     */
1547
    public function setHrDeptId($hrDeptId)
1548
    {
1549
        $this->hrDeptId = $hrDeptId;
1550
1551
        return $this;
1552
    }
1553
1554
    /**
1555
     * Get hrDeptId.
1556
     *
1557
     * @return int
1558
     */
1559
    public function getHrDeptId()
1560
    {
1561
        return $this->hrDeptId;
1562
    }
1563
1564
    /**
1565
     * @return \DateTime
1566
     */
1567
    public function getMemberSince()
1568
    {
1569
        return $this->registrationDate;
1570
    }
1571
1572
    /**
1573
     * @return bool
1574
     */
1575
    public function isOnline()
1576
    {
1577
        return false;
1578
    }
1579
1580
    /**
1581
     * @return int
1582
     */
1583
    public function getIdentifier()
1584
    {
1585
        return $this->getId();
1586
    }
1587
1588
    /**
1589
     * @return string
1590
     */
1591
    public function getSlug()
1592
    {
1593
        return $this->getUsername();
1594
    }
1595
1596
    /**
1597
     * @param string $slug
1598
     *
1599
     * @return User
1600
     */
1601
    public function setSlug($slug)
1602
    {
1603
        return $this->setUsername($slug);
1604
    }
1605
1606
    public function setUsername($username): self
1607
    {
1608
        $this->username = $username;
1609
1610
        return $this;
1611
    }
1612
1613
    public function setUsernameCanonical($usernameCanonical)
1614
    {
1615
        $this->usernameCanonical = $usernameCanonical;
1616
1617
        return $this;
1618
    }
1619
1620
    public function setEmailCanonical($emailCanonical): self
1621
    {
1622
        $this->emailCanonical = $emailCanonical;
1623
1624
        return $this;
1625
    }
1626
1627
    /**
1628
     * Set lastLogin.
1629
     *
1630
     * @param \DateTime $lastLogin
1631
     */
1632
    public function setLastLogin(\DateTime $lastLogin = null): self
1633
    {
1634
        $this->lastLogin = $lastLogin;
1635
1636
        return $this;
1637
    }
1638
1639
    /**
1640
     * Get lastLogin.
1641
     *
1642
     * @return \DateTime
1643
     */
1644
    public function getLastLogin()
1645
    {
1646
        return $this->lastLogin;
1647
    }
1648
1649
    /**
1650
     * Get sessionCourseSubscription.
1651
     *
1652
     * @return ArrayCollection
1653
     */
1654
    public function getSessionCourseSubscriptions()
1655
    {
1656
        return $this->sessionCourseSubscriptions;
1657
    }
1658
1659
    public function setSessionCourseSubscriptions(array $value): self
1660
    {
1661
        $this->sessionCourseSubscriptions = $value;
1662
1663
        return $this;
1664
    }
1665
1666
    /**
1667
     * @return string
1668
     */
1669
    public function getConfirmationToken()
1670
    {
1671
        return $this->confirmationToken;
1672
    }
1673
1674
    /**
1675
     * @param string $confirmationToken
1676
     */
1677
    public function setConfirmationToken($confirmationToken): self
1678
    {
1679
        $this->confirmationToken = $confirmationToken;
1680
1681
        return $this;
1682
    }
1683
1684
    /**
1685
     * @return \DateTime
1686
     */
1687
    public function getPasswordRequestedAt()
1688
    {
1689
        return $this->passwordRequestedAt;
1690
    }
1691
1692
    public function isPasswordRequestNonExpired($ttl)
1693
    {
1694
        return $this->getPasswordRequestedAt() instanceof \DateTime &&
1695
            $this->getPasswordRequestedAt()->getTimestamp() + $ttl > time();
1696
    }
1697
1698
    public function getUsername(): string
1699
    {
1700
        return (string) $this->username;
1701
    }
1702
1703
    public function getPlainPassword(): ?string
1704
    {
1705
        return $this->plainPassword;
1706
    }
1707
1708
    public function setPlainPassword(string $password): self
1709
    {
1710
        $this->plainPassword = $password;
1711
1712
        // forces the object to look "dirty" to Doctrine. Avoids
1713
        // Doctrine *not* saving this entity, if only plainPassword changes
1714
        $this->password = null;
1715
1716
        return $this;
1717
    }
1718
1719
    /**
1720
     * Returns the expiration date.
1721
     *
1722
     * @return \DateTime|null
1723
     */
1724
    public function getExpiresAt()
1725
    {
1726
        return $this->expiresAt;
1727
    }
1728
1729
    /**
1730
     * Returns the credentials expiration date.
1731
     *
1732
     * @return \DateTime
1733
     */
1734
    public function getCredentialsExpireAt()
1735
    {
1736
        return $this->credentialsExpireAt;
1737
    }
1738
1739
    /**
1740
     * Sets the credentials expiration date.
1741
     */
1742
    public function setCredentialsExpireAt(\DateTime $date = null): self
1743
    {
1744
        $this->credentialsExpireAt = $date;
1745
1746
        return $this;
1747
    }
1748
1749
    public function addGroup($group): self
1750
    {
1751
        if (!$this->getGroups()->contains($group)) {
1752
            $this->getGroups()->add($group);
1753
        }
1754
1755
        return $this;
1756
    }
1757
1758
    /**
1759
     * Sets the user groups.
1760
     *
1761
     * @param array $groups
1762
     */
1763
    public function setGroups($groups): self
1764
    {
1765
        foreach ($groups as $group) {
1766
            $this->addGroup($group);
1767
        }
1768
1769
        return $this;
1770
    }
1771
1772
    public function getFullname(): string
1773
    {
1774
        return sprintf('%s %s', $this->getFirstname(), $this->getLastname());
1775
    }
1776
1777
    public function getGroups()
1778
    {
1779
        return $this->groups;
1780
    }
1781
1782
    public function getGroupNames(): array
1783
    {
1784
        $names = [];
1785
        foreach ($this->getGroups() as $group) {
1786
            $names[] = $group->getName();
1787
        }
1788
1789
        return $names;
1790
    }
1791
1792
    /**
1793
     * @param string $name
1794
     */
1795
    public function hasGroup($name): bool
1796
    {
1797
        return in_array($name, $this->getGroupNames());
1798
    }
1799
1800
    public function removeGroup($group): self
1801
    {
1802
        if ($this->getGroups()->contains($group)) {
1803
            $this->getGroups()->removeElement($group);
1804
        }
1805
1806
        return $this;
1807
    }
1808
1809
    /**
1810
     * @param string $role
1811
     */
1812
    public function addRole($role): self
1813
    {
1814
        $role = strtoupper($role);
1815
        if ($role === static::ROLE_DEFAULT) {
1816
            return $this;
1817
        }
1818
1819
        if (!in_array($role, $this->roles, true)) {
1820
            $this->roles[] = $role;
1821
        }
1822
1823
        return $this;
1824
    }
1825
1826
    /**
1827
     * Returns the user roles.
1828
     *
1829
     * @return array The roles
1830
     */
1831
    public function getRoles()
1832
    {
1833
        $roles = $this->roles;
1834
1835
        foreach ($this->getGroups() as $group) {
1836
            $roles = array_merge($roles, $group->getRoles());
1837
        }
1838
1839
        // we need to make sure to have at least one role
1840
        $roles[] = 'ROLE_USER';
1841
1842
        return array_unique($roles);
1843
    }
1844
1845
    public function isAccountNonExpired()
1846
    {
1847
        /*if (true === $this->expired) {
1848
            return false;
1849
        }
1850
1851
        if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
1852
            return false;
1853
        }*/
1854
1855
        return true;
1856
    }
1857
1858
    public function isAccountNonLocked()
1859
    {
1860
        return true;
1861
        //return !$this->locked;
1862
    }
1863
1864
    public function isCredentialsNonExpired()
1865
    {
1866
        /*if (true === $this->credentialsExpired) {
1867
            return false;
1868
        }
1869
1870
        if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
1871
            return false;
1872
        }*/
1873
1874
        return true;
1875
    }
1876
1877
    /**
1878
     * @return bool
1879
     */
1880
    public function getCredentialsExpired()
1881
    {
1882
        return $this->credentialsExpired;
1883
    }
1884
1885
    /**
1886
     * @param bool $boolean
1887
     */
1888
    public function setCredentialsExpired($boolean): self
1889
    {
1890
        $this->credentialsExpired = $boolean;
1891
1892
        return $this;
1893
    }
1894
1895
    /**
1896
     * @param $boolean
1897
     */
1898
    public function setEnabled($boolean): self
1899
    {
1900
        $this->enabled = (bool) $boolean;
1901
1902
        return $this;
1903
    }
1904
1905
    /**
1906
     * @return bool
1907
     */
1908
    public function getExpired()
1909
    {
1910
        return $this->expired;
1911
    }
1912
1913
    /**
1914
     * Sets this user to expired.
1915
     *
1916
     * @param bool $boolean
1917
     */
1918
    public function setExpired($boolean): self
1919
    {
1920
        $this->expired = (bool) $boolean;
1921
1922
        return $this;
1923
    }
1924
1925
    public function setExpiresAt(\DateTime $date): self
1926
    {
1927
        $this->expiresAt = $date;
1928
1929
        return $this;
1930
    }
1931
1932
    public function getLocked(): bool
1933
    {
1934
        return $this->locked;
1935
    }
1936
1937
    /**
1938
     * @param $boolean
1939
     */
1940
    public function setLocked($boolean): self
1941
    {
1942
        $this->locked = $boolean;
1943
1944
        return $this;
1945
    }
1946
1947
    public function setPasswordRequestedAt(\DateTime $date = null)
1948
    {
1949
        $this->passwordRequestedAt = $date;
1950
1951
        return $this;
1952
    }
1953
1954
    public function setRoles(array $roles): self
1955
    {
1956
        $this->roles = [];
1957
1958
        foreach ($roles as $role) {
1959
            $this->addRole($role);
1960
        }
1961
1962
        return $this;
1963
    }
1964
1965
    /**
1966
     * Get achievedSkills.
1967
     *
1968
     * @return ArrayCollection
1969
     */
1970
    public function getAchievedSkills()
1971
    {
1972
        return $this->achievedSkills;
1973
    }
1974
1975
    /**
1976
     * @param string[] $value
1977
     */
1978
    public function setAchievedSkills(array $value): self
1979
    {
1980
        $this->achievedSkills = $value;
1981
1982
        return $this;
1983
    }
1984
1985
    /**
1986
     * Check if the user has the skill.
1987
     *
1988
     * @param Skill $skill The skill
1989
     */
1990
    public function hasSkill(Skill $skill): bool
1991
    {
1992
        $achievedSkills = $this->getAchievedSkills();
1993
1994
        foreach ($achievedSkills as $userSkill) {
1995
            if ($userSkill->getSkill()->getId() !== $skill->getId()) {
1996
                continue;
1997
            }
1998
1999
            return true;
2000
        }
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...
2001
    }
2002
2003
    /**
2004
     * @return bool
2005
     */
2006
    public function isProfileCompleted()
2007
    {
2008
        return $this->profileCompleted;
2009
    }
2010
2011
    public function setProfileCompleted($profileCompleted): self
2012
    {
2013
        $this->profileCompleted = $profileCompleted;
2014
2015
        return $this;
2016
    }
2017
2018
    /**
2019
     * Sets the AccessUrl for the current user in memory.
2020
     */
2021
    public function setCurrentUrl(AccessUrl $url): self
2022
    {
2023
        $urlList = $this->getPortals();
2024
        /** @var AccessUrlRelUser $item */
2025
        foreach ($urlList as $item) {
2026
            if ($item->getUrl()->getId() === $url->getId()) {
2027
                $this->currentUrl = $url;
2028
2029
                break;
2030
            }
2031
        }
2032
2033
        return $this;
2034
    }
2035
2036
    /**
2037
     * @return AccessUrl
2038
     */
2039
    public function getCurrentUrl()
2040
    {
2041
        return $this->currentUrl;
2042
    }
2043
2044
    /**
2045
     * Get sessionAsGeneralCoach.
2046
     *
2047
     * @return ArrayCollection
2048
     */
2049
    public function getSessionAsGeneralCoach()
2050
    {
2051
        return $this->sessionAsGeneralCoach;
2052
    }
2053
2054
    /**
2055
     * Get sessionAsGeneralCoach.
2056
     *
2057
     * @param ArrayCollection $value
2058
     */
2059
    public function setSessionAsGeneralCoach($value): self
2060
    {
2061
        $this->sessionAsGeneralCoach = $value;
2062
2063
        return $this;
2064
    }
2065
2066
    public function getCommentedUserSkills()
2067
    {
2068
        return $this->commentedUserSkills;
2069
    }
2070
2071
    /**
2072
     * @return User
2073
     */
2074
    public function setCommentedUserSkills(array $commentedUserSkills): self
2075
    {
2076
        $this->commentedUserSkills = $commentedUserSkills;
2077
2078
        return $this;
2079
    }
2080
2081
    /**
2082
     * @return bool
2083
     */
2084
    public function isEqualTo(UserInterface $user)
2085
    {
2086
        if ($this->password !== $user->getPassword()) {
2087
            return false;
2088
        }
2089
2090
        if ($this->salt !== $user->getSalt()) {
2091
            return false;
2092
        }
2093
2094
        if ($this->username !== $user->getUsername()) {
2095
            return false;
2096
        }
2097
2098
        return true;
2099
    }
2100
2101
    /**
2102
     * Get sentMessages.
2103
     *
2104
     * @return ArrayCollection
2105
     */
2106
    public function getSentMessages()
2107
    {
2108
        return $this->sentMessages;
2109
    }
2110
2111
    /**
2112
     * Get receivedMessages.
2113
     *
2114
     * @return ArrayCollection
2115
     */
2116
    public function getReceivedMessages()
2117
    {
2118
        return $this->receivedMessages;
2119
    }
2120
2121
    /**
2122
     * @param int $lastId Optional. The ID of the last received message
2123
     */
2124
    public function getUnreadReceivedMessages($lastId = 0): ArrayCollection
2125
    {
2126
        $criteria = Criteria::create();
2127
        $criteria->where(
2128
            Criteria::expr()->eq('msgStatus', MESSAGE_STATUS_UNREAD)
2129
        );
2130
2131
        if ($lastId > 0) {
2132
            $criteria->andWhere(
2133
                Criteria::expr()->gt('id', (int) $lastId)
2134
            );
2135
        }
2136
2137
        $criteria->orderBy(['sendDate' => Criteria::DESC]);
2138
2139
        return $this->receivedMessages->matching($criteria);
2140
    }
2141
2142
    public function getCourseGroupsAsMember(): Collection
2143
    {
2144
        return $this->courseGroupsAsMember;
2145
    }
2146
2147
    public function getCourseGroupsAsTutor(): Collection
2148
    {
2149
        return $this->courseGroupsAsTutor;
2150
    }
2151
2152
    public function getCourseGroupsAsMemberFromCourse(Course $course): ArrayCollection
2153
    {
2154
        $criteria = Criteria::create();
2155
        $criteria->where(
2156
            Criteria::expr()->eq('cId', $course)
2157
        );
2158
2159
        return $this->courseGroupsAsMember->matching($criteria);
2160
    }
2161
2162
    public function getFirstname()
2163
    {
2164
        return $this->firstname;
2165
    }
2166
2167
    public function getLastname()
2168
    {
2169
        return $this->lastname;
2170
    }
2171
2172
    public function eraseCredentials()
2173
    {
2174
        $this->plainPassword = null;
2175
    }
2176
2177
    public function hasRole($role)
2178
    {
2179
        return in_array(strtoupper($role), $this->getRoles(), true);
2180
    }
2181
2182
    public function isSuperAdmin()
2183
    {
2184
        return $this->hasRole('ROLE_SUPER_ADMIN');
2185
    }
2186
2187
    public function isUser(UserInterface $user = null)
2188
    {
2189
        return null !== $user && $this->getId() === $user->getId();
2190
    }
2191
2192
    public function removeRole($role)
2193
    {
2194
        if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
2195
            unset($this->roles[$key]);
2196
            $this->roles = array_values($this->roles);
2197
        }
2198
2199
        return $this;
2200
    }
2201
2202
    public function getUsernameCanonical()
2203
    {
2204
        return $this->usernameCanonical;
2205
    }
2206
2207
    public function getEmailCanonical()
2208
    {
2209
        return $this->emailCanonical;
2210
    }
2211
2212
    /**
2213
     * @param string $timezone
2214
     *
2215
     * @return User
2216
     */
2217
    public function setTimezone($timezone)
2218
    {
2219
        $this->timezone = $timezone;
2220
2221
        return $this;
2222
    }
2223
2224
    /**
2225
     * @return string
2226
     */
2227
    public function getTimezone()
2228
    {
2229
        return $this->timezone;
2230
    }
2231
2232
    /**
2233
     * @param string $locale
2234
     *
2235
     * @return User
2236
     */
2237
    public function setLocale($locale)
2238
    {
2239
        $this->locale = $locale;
2240
2241
        return $this;
2242
    }
2243
2244
    /**
2245
     * @return string
2246
     */
2247
    public function getLocale()
2248
    {
2249
        return $this->locale;
2250
    }
2251
2252
    /**
2253
     * @return string
2254
     */
2255
    public function getApiToken()
2256
    {
2257
        return $this->apiToken;
2258
    }
2259
2260
    /**
2261
     * @param string $apiToken
2262
     *
2263
     * @return User
2264
     */
2265
    public function setApiToken($apiToken)
2266
    {
2267
        $this->apiToken = $apiToken;
2268
2269
        return $this;
2270
    }
2271
2272
    public function getWebsite(): ?string
2273
    {
2274
        return $this->website;
2275
    }
2276
2277
    public function setWebsite(string $website): self
2278
    {
2279
        $this->website = $website;
2280
2281
        return $this;
2282
    }
2283
2284
    public function getBiography(): ?string
2285
    {
2286
        return $this->biography;
2287
    }
2288
2289
    public function setBiography(string $biography): self
2290
    {
2291
        $this->biography = $biography;
2292
2293
        return $this;
2294
    }
2295
2296
    /**
2297
     * @param \DateTime $dateOfBirth
2298
     */
2299
    public function setDateOfBirth($dateOfBirth): self
2300
    {
2301
        $this->dateOfBirth = $dateOfBirth;
2302
2303
        return $this;
2304
    }
2305
2306
    /**
2307
     * @return \DateTime
2308
     */
2309
    public function getDateOfBirth()
2310
    {
2311
        return $this->dateOfBirth;
2312
    }
2313
2314
    public function getCourseGroupsAsTutorFromCourse(Course $course): ArrayCollection
2315
    {
2316
        $criteria = Criteria::create();
2317
        $criteria->where(
2318
            Criteria::expr()->eq('cId', $course->getId())
2319
        );
2320
2321
        return $this->courseGroupsAsTutor->matching($criteria);
2322
    }
2323
2324
    /**
2325
     * Retreives this user's related sessions.
2326
     *
2327
     * @param int $relationType \Chamilo\CoreBundle\Entity\SessionRelUser::relationTypeList key
2328
     *
2329
     * @return Session[]
2330
     */
2331
    public function getSessions($relationType)
2332
    {
2333
        $sessions = [];
2334
        foreach ($this->sessions as $sessionRelUser) {
2335
            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

2335
            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...
2336
                $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

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