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