Passed
Push — master ( 4671c2...3df10a )
by Julito
48:25
created

User   F

Complexity

Total Complexity 222

Size/Duplication

Total Lines 2178
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 505
c 2
b 0
f 0
dl 0
loc 2178
rs 2
wmc 222

190 Methods

Rating   Name   Duplication   Size   Complexity  
A setOfficialCode() 0 5 1
A getRoles() 0 12 2
A getCourses() 0 3 1
A getResourceNode() 0 3 1
A setUuid() 0 5 1
A setResourceNode() 0 5 1
A hasResourceNode() 0 3 1
A getPlainPassword() 0 3 1
A getHrDeptId() 0 3 1
A getUsernameCanonical() 0 3 1
A getCourseGroupsAsMember() 0 3 1
A setAuthSource() 0 5 1
A getCompetences() 0 3 1
A setOpenarea() 0 5 1
A setEnabled() 0 5 1
A setEmailCanonical() 0 5 1
A setLastname() 0 5 1
A getTrackEAccessCompleteList() 0 3 1
A getIdentifier() 0 3 1
A getGradeBookComments() 0 3 1
A setDropBoxSentFiles() 0 5 1
A getCurrentlyAccessibleSessions() 0 10 3
A getOfficialCode() 0 3 1
A setUsernameCanonical() 0 5 1
A setPortals() 0 3 1
A getLastLogin() 0 3 1
A getDefaultIllustration() 0 5 2
A setExpiresAt() 0 5 1
A getCreatorId() 0 3 1
A isCredentialsNonExpired() 0 11 1
A setCreatorId() 0 5 1
A getFirstname() 0 3 1
A setLastLogin() 0 5 1
A getSessionsAsGeneralCoach() 0 3 1
A setCurrentUrl() 0 13 3
A getPersonalAgendas() 0 3 1
A getUserRelCourseVotes() 0 3 1
A setProfileCompleted() 0 5 1
A getUserCourseCategories() 0 3 1
A isActive() 0 3 1
A getGradeBookLinks() 0 3 1
A getGradeBookCategories() 0 3 1
A setPasswordRequestedAt() 0 5 1
A setCommentedUserSkills() 0 5 1
A setTheme() 0 5 1
A getPasswordRequestedAt() 0 3 1
A getPictureUri() 0 3 1
A getPassword() 0 3 1
A setActive() 0 5 1
A setRoles() 0 9 2
A getGroupNames() 0 8 2
A getGradeBookResultLogs() 0 3 1
A getSlug() 0 3 1
A getConfirmationToken() 0 3 1
A getCredentialsExpired() 0 3 1
A setClasses() 0 5 1
A getBiography() 0 3 1
A getPhone() 0 3 1
A getGradeBookEvaluations() 0 3 1
A getSalt() 0 3 1
A isOnline() 0 3 1
A setPortal() 0 5 1
A getPortals() 0 3 1
A getCourseGroupsAsTutorFromCourse() 0 8 1
A getEmailCanonical() 0 3 1
A getAchievedSkills() 0 3 1
A getEmail() 0 3 1
A getGradeBookScoreLogs() 0 3 1
A setOpenid() 0 5 1
A setConfirmationToken() 0 5 1
A removeRole() 0 8 2
A setExpired() 0 5 1
A setParent() 0 2 1
A removeGroup() 0 7 2
A getTrackECourseAccess() 0 3 1
A getCredentialsExpireAt() 0 3 1
A getUserRelUsers() 0 3 1
A eraseCredentials() 0 3 1
A getExpiresAt() 0 3 1
A setAchievedSkills() 0 5 1
A setResourceName() 0 3 1
A getWebsite() 0 3 1
A setProductions() 0 5 1
A setBiography() 0 5 1
A getExpired() 0 3 1
A getIsActive() 0 3 1
A setDiplomas() 0 5 1
A getTrackEAttempts() 0 3 1
A getDRHSessions() 0 3 1
A getUserRelTags() 0 3 1
A getGradeBookCertificates() 0 3 1
A getCommentedUserSkills() 0 3 1
A hasRole() 0 3 1
A setPlainPassword() 0 9 1
A getDiplomas() 0 3 1
A setEmail() 0 5 1
A getTimezone() 0 3 1
A getCourseGroupsAsTutor() 0 3 1
B getIconStatus() 0 30 6
A hasSkill() 0 13 3
A setCredentialsExpireAt() 0 5 1
A getCurriculumItems() 0 3 1
A setSalt() 0 5 1
A setRegistrationDate() 0 5 1
A getApiToken() 0 3 1
A setExpirationDate() 0 5 1
A setHrDeptId() 0 5 1
A getTeach() 0 3 1
A getFullname() 0 3 1
A getLps() 0 2 1
A getId() 0 3 1
A getGroups() 0 3 1
A getCurrentUrl() 0 3 1
A getCompleteNameWithClasses() 0 12 3
A getAddress() 0 3 1
A setCredentialsExpired() 0 5 1
A getStatus() 0 3 1
A setSlug() 0 3 1
A setTeach() 0 5 1
A getDateOfBirth() 0 3 1
A isAdmin() 0 3 1
A setFirstname() 0 5 1
A getClasses() 0 3 1
A setWebsite() 0 5 1
A setCourses() 0 5 1
A getLastname() 0 3 1
A getSequenceValues() 0 3 1
A getGradeBookLinkEvalLogs() 0 3 1
A getOpenarea() 0 3 1
A getGradeBookResults() 0 3 1
A setSessionsAsGeneralCoach() 0 5 1
A getMemberSince() 0 3 1
A getActive() 0 3 1
A setSessionCourseSubscriptions() 0 5 1
A getRegistrationDate() 0 3 1
A setGradeBookCertificates() 0 5 1
A hasGroup() 0 3 1
A getTheme() 0 3 1
A setAddress() 0 5 1
A getTemplates() 0 3 1
A getSessionsRelUser() 0 3 1
A getProfileUrl() 0 3 1
A getTrackEExerciseConfirmations() 0 3 1
A setPhone() 0 5 1
A isAccountNonLocked() 0 3 1
A setCompetences() 0 5 1
A getSentMessages() 0 3 1
A getReceivedMessages() 0 3 1
A getLocked() 0 3 1
A isSuperAdmin() 0 3 1
A setPassword() 0 5 1
A getAuthSource() 0 3 1
A isAccountNonExpired() 0 11 1
A setGroups() 0 7 2
A isUser() 0 3 2
A getProductions() 0 3 1
A getStudentSessions() 0 3 1
A setTimezone() 0 5 1
A addGroup() 0 7 2
A getDropBoxReceivedFiles() 0 3 1
A getMaxSortValue() 0 17 2
A setLocked() 0 5 1
A setApiToken() 0 5 1
A isProfileCompleted() 0 3 1
A setDateOfBirth() 0 5 1
A isPasswordRequestNonExpired() 0 4 2
A getCourseGroupsAsMemberFromCourse() 0 8 1
A getSessions() 0 10 3
A setStatus() 0 5 1
A isEqualTo() 0 15 4
A isEnabled() 0 3 1
A getOpenid() 0 3 1
A getResourceIdentifier() 0 3 1
A getSessionCourseSubscriptions() 0 3 1
A getExpirationDate() 0 3 1
A addRole() 0 12 3
A getDropBoxSentFiles() 0 3 1
A getResourceName() 0 3 1
A setLocale() 0 5 1
A getUsername() 0 3 1
A getLocale() 0 3 1
A getUnreadReceivedMessages() 0 18 2
A setUsername() 0 5 1
A getUuid() 0 3 1
A getResourceNodes() 0 3 1
A getPasswordConstraints() 0 23 1
A setResourceNodes() 0 5 1
A loadValidatorMetadata() 0 2 1
A __toString() 0 3 1
B __construct() 0 66 1

How to fix   Complexity   

Complex Class

Complex classes like User often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use User, and based on these observations, apply Extract Interface, too.

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