Passed
Push — master ( ad5dd8...3078de )
by Julito
08:55
created

User   F

Complexity

Total Complexity 207

Size/Duplication

Total Lines 2432
Duplicated Lines 0 %

Importance

Changes 6
Bugs 1 Features 2
Metric Value
eloc 455
dl 0
loc 2432
rs 2
c 6
b 1
f 2
wmc 207

175 Methods

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

2399
            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...
2400
                $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

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