Total Complexity | 268 |
Total Lines | 2358 |
Duplicated Lines | 0 % |
Changes | 2 | ||
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: 'auth_source', type: 'string', length: 50, nullable: true)] |
||
589 | protected ?string $authSource; |
||
590 | |||
591 | #[ORM\Column(name: 'status', type: 'integer')] |
||
592 | protected int $status; |
||
593 | |||
594 | #[ORM\Column(name: 'official_code', type: 'string', length: 40, nullable: true)] |
||
595 | protected ?string $officialCode = null; |
||
596 | |||
597 | #[ORM\Column(name: 'picture_uri', type: 'string', length: 250, nullable: true)] |
||
598 | protected ?string $pictureUri = null; |
||
599 | |||
600 | #[ORM\Column(name: 'creator_id', type: 'integer', unique: false, nullable: true)] |
||
601 | protected ?int $creatorId = null; |
||
602 | |||
603 | #[ORM\Column(name: 'competences', type: 'text', unique: false, nullable: true)] |
||
604 | protected ?string $competences = null; |
||
605 | |||
606 | #[ORM\Column(name: 'diplomas', type: 'text', unique: false, nullable: true)] |
||
607 | protected ?string $diplomas = null; |
||
608 | |||
609 | #[ORM\Column(name: 'openarea', type: 'text', unique: false, nullable: true)] |
||
610 | protected ?string $openarea = null; |
||
611 | |||
612 | #[ORM\Column(name: 'teach', type: 'text', unique: false, nullable: true)] |
||
613 | protected ?string $teach = null; |
||
614 | |||
615 | #[ORM\Column(name: 'productions', type: 'string', length: 250, unique: false, nullable: true)] |
||
616 | protected ?string $productions = null; |
||
617 | |||
618 | #[ORM\Column(name: 'expiration_date', type: 'datetime', unique: false, nullable: true)] |
||
619 | protected ?DateTime $expirationDate = null; |
||
620 | |||
621 | #[Groups(['user:read', 'user_json:read'])] |
||
622 | #[ORM\Column(name: 'active', type: 'integer')] |
||
623 | protected int $active; |
||
624 | |||
625 | #[ORM\Column(name: 'openid', type: 'string', length: 255, unique: false, nullable: true)] |
||
626 | protected ?string $openid = null; |
||
627 | |||
628 | #[ORM\Column(name: 'theme', type: 'string', length: 255, unique: false, nullable: true)] |
||
629 | protected ?string $theme = null; |
||
630 | |||
631 | #[ORM\Column(name: 'hr_dept_id', type: 'smallint', unique: false, nullable: true)] |
||
632 | protected ?int $hrDeptId = null; |
||
633 | |||
634 | #[Groups(['user:write'])] |
||
635 | protected ?AccessUrl $currentUrl = null; |
||
636 | |||
637 | /** |
||
638 | * @var Collection<int, MessageTag> |
||
639 | */ |
||
640 | #[ORM\OneToMany( |
||
641 | mappedBy: 'user', |
||
642 | targetEntity: MessageTag::class, |
||
643 | cascade: ['persist', 'remove'], |
||
644 | orphanRemoval: true |
||
645 | )] |
||
646 | protected Collection $messageTags; |
||
647 | |||
648 | /** |
||
649 | * @var Collection<int, Message> |
||
650 | */ |
||
651 | #[ORM\OneToMany( |
||
652 | mappedBy: 'sender', |
||
653 | targetEntity: Message::class, |
||
654 | cascade: ['persist'] |
||
655 | )] |
||
656 | protected Collection $sentMessages; |
||
657 | |||
658 | /** |
||
659 | * @var Collection<int, MessageRelUser> |
||
660 | */ |
||
661 | #[ORM\OneToMany(mappedBy: 'receiver', targetEntity: MessageRelUser::class, cascade: ['persist', 'remove'])] |
||
662 | protected Collection $receivedMessages; |
||
663 | |||
664 | /** |
||
665 | * @var Collection<int, CSurveyInvitation> |
||
666 | */ |
||
667 | #[ORM\OneToMany(mappedBy: 'user', targetEntity: CSurveyInvitation::class, cascade: ['persist', 'remove'])] |
||
668 | protected Collection $surveyInvitations; |
||
669 | |||
670 | /** |
||
671 | * @var Collection<int, TrackELogin> |
||
672 | */ |
||
673 | #[ORM\OneToMany(mappedBy: 'user', targetEntity: TrackELogin::class, cascade: ['persist', 'remove'])] |
||
674 | protected Collection $logins; |
||
675 | |||
676 | #[ORM\OneToOne(mappedBy: 'user', targetEntity: Admin::class, cascade: ['persist', 'remove'], orphanRemoval: true)] |
||
677 | protected ?Admin $admin = null; |
||
678 | |||
679 | #[ORM\Column(type: 'uuid', unique: true)] |
||
680 | protected Uuid $uuid; |
||
681 | |||
682 | // Property used only during installation. |
||
683 | protected bool $skipResourceNode = false; |
||
684 | |||
685 | #[Groups([ |
||
686 | 'user:read', |
||
687 | 'user_json:read', |
||
688 | 'social_post:read', |
||
689 | 'course:read', |
||
690 | 'course_rel_user:read', |
||
691 | 'message:read', |
||
692 | 'user_subscriptions:sessions', |
||
693 | ])] |
||
694 | protected string $fullName; |
||
695 | |||
696 | #[ORM\OneToMany(mappedBy: 'sender', targetEntity: SocialPost::class, orphanRemoval: true)] |
||
697 | private Collection $sentSocialPosts; |
||
698 | |||
699 | #[ORM\OneToMany(mappedBy: 'userReceiver', targetEntity: SocialPost::class)] |
||
700 | private Collection $receivedSocialPosts; |
||
701 | |||
702 | #[ORM\OneToMany(mappedBy: 'user', targetEntity: SocialPostFeedback::class, orphanRemoval: true)] |
||
703 | private Collection $socialPostsFeedbacks; |
||
704 | |||
705 | public function __construct() |
||
706 | { |
||
707 | $this->skipResourceNode = false; |
||
708 | $this->uuid = Uuid::v4(); |
||
709 | $this->apiToken = null; |
||
710 | $this->biography = ''; |
||
711 | $this->website = ''; |
||
712 | $this->locale = 'en'; |
||
713 | $this->timezone = 'Europe\Paris'; |
||
714 | $this->authSource = 'platform'; |
||
715 | $this->status = CourseRelUser::STUDENT; |
||
716 | $this->salt = sha1(uniqid('', true)); |
||
717 | $this->active = 1; |
||
718 | $this->locked = false; |
||
719 | $this->expired = false; |
||
720 | $this->courses = new ArrayCollection(); |
||
721 | $this->classes = new ArrayCollection(); |
||
722 | $this->curriculumItems = new ArrayCollection(); |
||
723 | $this->portals = new ArrayCollection(); |
||
724 | $this->dropBoxSentFiles = new ArrayCollection(); |
||
725 | $this->dropBoxReceivedFiles = new ArrayCollection(); |
||
726 | $this->groups = new ArrayCollection(); |
||
727 | $this->gradeBookCertificates = new ArrayCollection(); |
||
728 | $this->courseGroupsAsMember = new ArrayCollection(); |
||
729 | $this->courseGroupsAsTutor = new ArrayCollection(); |
||
730 | $this->resourceNodes = new ArrayCollection(); |
||
731 | $this->sessionRelCourseRelUsers = new ArrayCollection(); |
||
732 | $this->achievedSkills = new ArrayCollection(); |
||
733 | $this->commentedUserSkills = new ArrayCollection(); |
||
734 | $this->gradeBookCategories = new ArrayCollection(); |
||
735 | $this->gradeBookComments = new ArrayCollection(); |
||
736 | $this->gradeBookResults = new ArrayCollection(); |
||
737 | $this->gradeBookResultLogs = new ArrayCollection(); |
||
738 | $this->gradeBookScoreLogs = new ArrayCollection(); |
||
739 | $this->friends = new ArrayCollection(); |
||
740 | $this->friendsWithMe = new ArrayCollection(); |
||
741 | $this->gradeBookLinkEvalLogs = new ArrayCollection(); |
||
742 | $this->messageTags = new ArrayCollection(); |
||
743 | $this->sequenceValues = new ArrayCollection(); |
||
744 | $this->trackEExerciseConfirmations = new ArrayCollection(); |
||
745 | $this->trackEAccessCompleteList = new ArrayCollection(); |
||
746 | $this->templates = new ArrayCollection(); |
||
747 | $this->trackEAttempts = new ArrayCollection(); |
||
748 | $this->trackECourseAccess = new ArrayCollection(); |
||
749 | $this->userCourseCategories = new ArrayCollection(); |
||
750 | $this->userRelCourseVotes = new ArrayCollection(); |
||
751 | $this->userRelTags = new ArrayCollection(); |
||
752 | $this->sessionsRelUser = new ArrayCollection(); |
||
753 | $this->sentMessages = new ArrayCollection(); |
||
754 | $this->receivedMessages = new ArrayCollection(); |
||
755 | $this->surveyInvitations = new ArrayCollection(); |
||
756 | $this->logins = new ArrayCollection(); |
||
757 | $this->createdAt = new DateTime(); |
||
758 | $this->updatedAt = new DateTime(); |
||
759 | $this->roles = []; |
||
760 | $this->credentialsExpired = false; |
||
761 | $this->credentialsExpireAt = new DateTime(); |
||
762 | $this->dateOfBirth = new DateTime(); |
||
763 | $this->expiresAt = new DateTime(); |
||
764 | $this->passwordRequestedAt = new DateTime(); |
||
765 | $this->sentSocialPosts = new ArrayCollection(); |
||
766 | $this->receivedSocialPosts = new ArrayCollection(); |
||
767 | $this->socialPostsFeedbacks = new ArrayCollection(); |
||
768 | } |
||
769 | |||
770 | public function __toString(): string |
||
771 | { |
||
772 | return $this->username; |
||
773 | } |
||
774 | |||
775 | public static function getPasswordConstraints(): array |
||
776 | { |
||
777 | return [ |
||
778 | new Assert\Length(['min' => 5]), |
||
779 | new Assert\Regex(['pattern' => '/^[a-z\-_0-9]+$/i', 'htmlPattern' => '/^[a-z\-_0-9]+$/i']), |
||
780 | new Assert\Regex(['pattern' => '/[0-9]{2}/', 'htmlPattern' => '/[0-9]{2}/']), |
||
781 | ]; |
||
782 | } |
||
783 | |||
784 | public static function loadValidatorMetadata(ClassMetadata $metadata): void {} |
||
785 | |||
786 | public function getUuid(): Uuid |
||
787 | { |
||
788 | return $this->uuid; |
||
789 | } |
||
790 | |||
791 | public function setUuid(Uuid $uuid): self |
||
792 | { |
||
793 | $this->uuid = $uuid; |
||
794 | |||
795 | return $this; |
||
796 | } |
||
797 | |||
798 | public function getResourceNode(): ?ResourceNode |
||
801 | } |
||
802 | |||
803 | public function setResourceNode(ResourceNode $resourceNode): self |
||
804 | { |
||
805 | $this->resourceNode = $resourceNode; |
||
806 | |||
807 | return $this; |
||
808 | } |
||
809 | |||
810 | public function hasResourceNode(): bool |
||
811 | { |
||
812 | return $this->resourceNode instanceof ResourceNode; |
||
813 | } |
||
814 | |||
815 | public function getResourceNodes(): Collection |
||
816 | { |
||
817 | return $this->resourceNodes; |
||
818 | } |
||
819 | |||
820 | public function addResourceNode(ResourceNode $resourceNode): static |
||
821 | { |
||
822 | if (!$this->resourceNodes->contains($resourceNode)) { |
||
823 | $this->resourceNodes->add($resourceNode); |
||
824 | $resourceNode->setCreator($this); |
||
825 | } |
||
826 | |||
827 | return $this; |
||
828 | } |
||
829 | |||
830 | public function getDropBoxSentFiles(): Collection |
||
833 | } |
||
834 | |||
835 | public function setDropBoxSentFiles(Collection $value): self |
||
836 | { |
||
837 | $this->dropBoxSentFiles = $value; |
||
838 | |||
839 | return $this; |
||
840 | } |
||
841 | |||
842 | public function getCourses(): Collection |
||
843 | { |
||
844 | return $this->courses; |
||
845 | } |
||
846 | |||
847 | /** |
||
848 | * @param Collection<int, CourseRelUser> $courses |
||
849 | */ |
||
850 | public function setCourses(Collection $courses): self |
||
851 | { |
||
852 | $this->courses = $courses; |
||
853 | |||
854 | return $this; |
||
855 | } |
||
856 | |||
857 | public function setPortal(AccessUrlRelUser $portal): self |
||
858 | { |
||
859 | $this->portals->add($portal); |
||
860 | |||
861 | return $this; |
||
862 | } |
||
863 | |||
864 | /** |
||
865 | * 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). |
||
866 | * |
||
867 | * @return bool True if active = 1, false in any other case (0 = inactive, -1 = predeleted) |
||
868 | */ |
||
869 | public function getIsActive(): bool |
||
870 | { |
||
871 | return 1 === $this->active; |
||
872 | } |
||
873 | |||
874 | public function isEnabled(): bool |
||
875 | { |
||
876 | return $this->isActive(); |
||
877 | } |
||
878 | |||
879 | /** |
||
880 | * Returns the list of classes for the user. |
||
881 | */ |
||
882 | public function getCompleteNameWithClasses(): string |
||
883 | { |
||
884 | $classSubscription = $this->getClasses(); |
||
885 | $classList = []; |
||
886 | |||
887 | /** @var UsergroupRelUser $subscription */ |
||
888 | foreach ($classSubscription as $subscription) { |
||
889 | $class = $subscription->getUsergroup(); |
||
890 | $classList[] = $class->getTitle(); |
||
891 | } |
||
892 | $classString = empty($classList) ? null : ' ['.implode(', ', $classList).']'; |
||
893 | |||
894 | return UserManager::formatUserFullName($this).$classString; |
||
895 | } |
||
896 | |||
897 | public function getClasses(): Collection |
||
898 | { |
||
899 | return $this->classes; |
||
900 | } |
||
901 | |||
902 | /** |
||
903 | * @param Collection<int, UsergroupRelUser> $classes |
||
904 | */ |
||
905 | public function setClasses(Collection $classes): self |
||
906 | { |
||
907 | $this->classes = $classes; |
||
908 | |||
909 | return $this; |
||
910 | } |
||
911 | |||
912 | public function getAuthSource(): ?string |
||
913 | { |
||
914 | return $this->authSource; |
||
915 | } |
||
916 | |||
917 | public function setAuthSource(string $authSource): self |
||
918 | { |
||
919 | $this->authSource = $authSource; |
||
920 | |||
921 | return $this; |
||
922 | } |
||
923 | |||
924 | public function getEmail(): string |
||
925 | { |
||
926 | return $this->email; |
||
927 | } |
||
928 | |||
929 | public function setEmail(string $email): self |
||
930 | { |
||
931 | $this->email = $email; |
||
932 | |||
933 | return $this; |
||
934 | } |
||
935 | |||
936 | public function getOfficialCode(): ?string |
||
937 | { |
||
938 | return $this->officialCode; |
||
939 | } |
||
940 | |||
941 | public function setOfficialCode(?string $officialCode): self |
||
942 | { |
||
943 | $this->officialCode = $officialCode; |
||
944 | |||
945 | return $this; |
||
946 | } |
||
947 | |||
948 | public function getPhone(): ?string |
||
949 | { |
||
950 | return $this->phone; |
||
951 | } |
||
952 | |||
953 | public function setPhone(?string $phone): self |
||
954 | { |
||
955 | $this->phone = $phone; |
||
956 | |||
957 | return $this; |
||
958 | } |
||
959 | |||
960 | public function getAddress(): ?string |
||
961 | { |
||
962 | return $this->address; |
||
963 | } |
||
964 | |||
965 | public function setAddress(?string $address): self |
||
966 | { |
||
967 | $this->address = $address; |
||
968 | |||
969 | return $this; |
||
970 | } |
||
971 | |||
972 | public function getCreatorId(): ?int |
||
973 | { |
||
974 | return $this->creatorId; |
||
975 | } |
||
976 | |||
977 | public function setCreatorId(int $creatorId): self |
||
978 | { |
||
979 | $this->creatorId = $creatorId; |
||
980 | |||
981 | return $this; |
||
982 | } |
||
983 | |||
984 | public function getCompetences(): ?string |
||
985 | { |
||
986 | return $this->competences; |
||
987 | } |
||
988 | |||
989 | public function setCompetences(?string $competences): self |
||
990 | { |
||
991 | $this->competences = $competences; |
||
992 | |||
993 | return $this; |
||
994 | } |
||
995 | |||
996 | public function getDiplomas(): ?string |
||
997 | { |
||
998 | return $this->diplomas; |
||
999 | } |
||
1000 | |||
1001 | public function setDiplomas(?string $diplomas): self |
||
1002 | { |
||
1003 | $this->diplomas = $diplomas; |
||
1004 | |||
1005 | return $this; |
||
1006 | } |
||
1007 | |||
1008 | public function getOpenarea(): ?string |
||
1009 | { |
||
1010 | return $this->openarea; |
||
1011 | } |
||
1012 | |||
1013 | public function setOpenarea(?string $openarea): self |
||
1014 | { |
||
1015 | $this->openarea = $openarea; |
||
1016 | |||
1017 | return $this; |
||
1018 | } |
||
1019 | |||
1020 | public function getTeach(): ?string |
||
1021 | { |
||
1022 | return $this->teach; |
||
1023 | } |
||
1024 | |||
1025 | public function setTeach(?string $teach): self |
||
1026 | { |
||
1027 | $this->teach = $teach; |
||
1028 | |||
1029 | return $this; |
||
1030 | } |
||
1031 | |||
1032 | public function getProductions(): ?string |
||
1033 | { |
||
1034 | return $this->productions; |
||
1035 | } |
||
1036 | |||
1037 | public function setProductions(?string $productions): self |
||
1038 | { |
||
1039 | $this->productions = $productions; |
||
1040 | |||
1041 | return $this; |
||
1042 | } |
||
1043 | |||
1044 | public function getExpirationDate(): ?DateTime |
||
1045 | { |
||
1046 | return $this->expirationDate; |
||
1047 | } |
||
1048 | |||
1049 | public function setExpirationDate(?DateTime $expirationDate): self |
||
1050 | { |
||
1051 | $this->expirationDate = $expirationDate; |
||
1052 | |||
1053 | return $this; |
||
1054 | } |
||
1055 | |||
1056 | public function getActive(): int |
||
1057 | { |
||
1058 | return $this->active; |
||
1059 | } |
||
1060 | |||
1061 | public function isActive(): bool |
||
1062 | { |
||
1063 | return $this->getIsActive(); |
||
1064 | } |
||
1065 | |||
1066 | public function setActive(int $active): self |
||
1067 | { |
||
1068 | $this->active = $active; |
||
1069 | |||
1070 | return $this; |
||
1071 | } |
||
1072 | |||
1073 | public function getOpenid(): ?string |
||
1074 | { |
||
1075 | return $this->openid; |
||
1076 | } |
||
1077 | |||
1078 | public function setOpenid(string $openid): self |
||
1079 | { |
||
1080 | $this->openid = $openid; |
||
1081 | |||
1082 | return $this; |
||
1083 | } |
||
1084 | |||
1085 | public function getTheme(): ?string |
||
1086 | { |
||
1087 | return $this->theme; |
||
1088 | } |
||
1089 | |||
1090 | public function setTheme(string $theme): self |
||
1091 | { |
||
1092 | $this->theme = $theme; |
||
1093 | |||
1094 | return $this; |
||
1095 | } |
||
1096 | |||
1097 | public function getHrDeptId(): ?int |
||
1098 | { |
||
1099 | return $this->hrDeptId; |
||
1100 | } |
||
1101 | |||
1102 | public function setHrDeptId(int $hrDeptId): self |
||
1103 | { |
||
1104 | $this->hrDeptId = $hrDeptId; |
||
1105 | |||
1106 | return $this; |
||
1107 | } |
||
1108 | |||
1109 | public function isOnline(): bool |
||
1110 | { |
||
1111 | return false; |
||
1112 | } |
||
1113 | |||
1114 | public function getIdentifier(): int |
||
1115 | { |
||
1116 | return $this->getId(); |
||
|
|||
1117 | } |
||
1118 | |||
1119 | public function getId(): ?int |
||
1120 | { |
||
1121 | return $this->id; |
||
1122 | } |
||
1123 | |||
1124 | public function getIri(): ?string |
||
1125 | { |
||
1126 | if (null === $this->id) { |
||
1127 | return null; |
||
1128 | } |
||
1129 | |||
1130 | return '/api/users/'.$this->getId(); |
||
1131 | } |
||
1132 | |||
1133 | public function getSlug(): string |
||
1134 | { |
||
1135 | return $this->getUsername(); |
||
1136 | } |
||
1137 | |||
1138 | public function getUsername(): string |
||
1139 | { |
||
1140 | return $this->username; |
||
1141 | } |
||
1142 | |||
1143 | public function setUsername(string $username): self |
||
1144 | { |
||
1145 | $this->username = $username; |
||
1146 | |||
1147 | return $this; |
||
1148 | } |
||
1149 | |||
1150 | public function setSlug(string $slug): self |
||
1151 | { |
||
1152 | return $this->setUsername($slug); |
||
1153 | } |
||
1154 | |||
1155 | public function getLastLogin(): ?DateTime |
||
1156 | { |
||
1157 | return $this->lastLogin; |
||
1158 | } |
||
1159 | |||
1160 | public function setLastLogin(?DateTime $lastLogin = null): self |
||
1161 | { |
||
1162 | $this->lastLogin = $lastLogin; |
||
1163 | |||
1164 | return $this; |
||
1165 | } |
||
1166 | |||
1167 | public function getConfirmationToken(): ?string |
||
1168 | { |
||
1169 | return $this->confirmationToken; |
||
1170 | } |
||
1171 | |||
1172 | public function setConfirmationToken(string $confirmationToken): self |
||
1173 | { |
||
1174 | $this->confirmationToken = $confirmationToken; |
||
1175 | |||
1176 | return $this; |
||
1177 | } |
||
1178 | |||
1179 | public function isPasswordRequestNonExpired(int $ttl): bool |
||
1180 | { |
||
1181 | return $this->getPasswordRequestedAt() instanceof DateTime && $this->getPasswordRequestedAt()->getTimestamp( |
||
1182 | ) + $ttl > time(); |
||
1183 | } |
||
1184 | |||
1185 | public function getPasswordRequestedAt(): ?DateTime |
||
1186 | { |
||
1187 | return $this->passwordRequestedAt; |
||
1188 | } |
||
1189 | |||
1190 | public function setPasswordRequestedAt(?DateTime $date = null): self |
||
1191 | { |
||
1192 | $this->passwordRequestedAt = $date; |
||
1193 | |||
1194 | return $this; |
||
1195 | } |
||
1196 | |||
1197 | public function getPlainPassword(): ?string |
||
1198 | { |
||
1199 | return $this->plainPassword; |
||
1200 | } |
||
1201 | |||
1202 | public function setPlainPassword(?string $password): self |
||
1203 | { |
||
1204 | $this->plainPassword = $password; |
||
1205 | // forces the object to look "dirty" to Doctrine. Avoids |
||
1206 | // Doctrine *not* saving this entity, if only plainPassword changes |
||
1207 | $this->password = ''; |
||
1208 | |||
1209 | return $this; |
||
1210 | } |
||
1211 | |||
1212 | /** |
||
1213 | * Returns the expiration date. |
||
1214 | */ |
||
1215 | public function getExpiresAt(): ?DateTime |
||
1216 | { |
||
1217 | return $this->expiresAt; |
||
1218 | } |
||
1219 | |||
1220 | public function setExpiresAt(DateTime $date): self |
||
1221 | { |
||
1222 | $this->expiresAt = $date; |
||
1223 | |||
1224 | return $this; |
||
1225 | } |
||
1226 | |||
1227 | /** |
||
1228 | * Returns the credentials expiration date. |
||
1229 | */ |
||
1230 | public function getCredentialsExpireAt(): ?DateTime |
||
1231 | { |
||
1232 | return $this->credentialsExpireAt; |
||
1233 | } |
||
1234 | |||
1235 | /** |
||
1236 | * Sets the credentials expiration date. |
||
1237 | */ |
||
1238 | public function setCredentialsExpireAt(?DateTime $date = null): self |
||
1239 | { |
||
1240 | $this->credentialsExpireAt = $date; |
||
1241 | |||
1242 | return $this; |
||
1243 | } |
||
1244 | |||
1245 | public function getFullname(): string |
||
1246 | { |
||
1247 | if (empty($this->fullName)) { |
||
1248 | return \sprintf('%s %s', $this->getFirstname(), $this->getLastname()); |
||
1249 | } |
||
1250 | |||
1251 | return $this->fullName; |
||
1252 | } |
||
1253 | |||
1254 | public function setFullName(string $fullName): self |
||
1255 | { |
||
1256 | $this->fullName = $fullName; |
||
1257 | |||
1258 | return $this; |
||
1259 | } |
||
1260 | |||
1261 | public function getFirstname(): ?string |
||
1262 | { |
||
1263 | return $this->firstname; |
||
1264 | } |
||
1265 | |||
1266 | public function setFirstname(string $firstname): self |
||
1267 | { |
||
1268 | $this->firstname = $firstname; |
||
1269 | |||
1270 | return $this; |
||
1271 | } |
||
1272 | |||
1273 | public function getLastname(): ?string |
||
1274 | { |
||
1275 | return $this->lastname; |
||
1276 | } |
||
1277 | |||
1278 | public function setLastname(string $lastname): self |
||
1279 | { |
||
1280 | $this->lastname = $lastname; |
||
1281 | |||
1282 | return $this; |
||
1283 | } |
||
1284 | |||
1285 | public function hasGroup(string $name): bool |
||
1286 | { |
||
1287 | return \in_array($name, $this->getGroupNames(), true); |
||
1288 | } |
||
1289 | |||
1290 | public function getGroupNames(): array |
||
1291 | { |
||
1292 | $names = []; |
||
1293 | foreach ($this->getGroups() as $group) { |
||
1294 | $names[] = $group->getTitle(); |
||
1295 | } |
||
1296 | |||
1297 | return $names; |
||
1298 | } |
||
1299 | |||
1300 | public function getGroups(): Collection |
||
1301 | { |
||
1302 | return $this->groups; |
||
1303 | } |
||
1304 | |||
1305 | /** |
||
1306 | * Sets the user groups. |
||
1307 | */ |
||
1308 | public function setGroups(Collection $groups): self |
||
1309 | { |
||
1310 | foreach ($groups as $group) { |
||
1311 | $this->addGroup($group); |
||
1312 | } |
||
1313 | |||
1314 | return $this; |
||
1315 | } |
||
1316 | |||
1317 | public function addGroup(Group $group): self |
||
1318 | { |
||
1319 | if (!$this->getGroups()->contains($group)) { |
||
1320 | $this->getGroups()->add($group); |
||
1321 | } |
||
1322 | |||
1323 | return $this; |
||
1324 | } |
||
1325 | |||
1326 | public function removeGroup(Group $group): self |
||
1327 | { |
||
1328 | if ($this->getGroups()->contains($group)) { |
||
1329 | $this->getGroups()->removeElement($group); |
||
1330 | } |
||
1331 | |||
1332 | return $this; |
||
1333 | } |
||
1334 | |||
1335 | public function isAccountNonExpired(): bool |
||
1336 | { |
||
1337 | return true; |
||
1338 | } |
||
1339 | |||
1340 | public function isAccountNonLocked(): bool |
||
1341 | { |
||
1342 | return true; |
||
1343 | } |
||
1344 | |||
1345 | public function isCredentialsNonExpired(): bool |
||
1346 | { |
||
1347 | return true; |
||
1348 | } |
||
1349 | |||
1350 | public function getCredentialsExpired(): bool |
||
1351 | { |
||
1352 | return $this->credentialsExpired; |
||
1353 | } |
||
1354 | |||
1355 | public function setCredentialsExpired(bool $boolean): self |
||
1356 | { |
||
1357 | $this->credentialsExpired = $boolean; |
||
1358 | |||
1359 | return $this; |
||
1360 | } |
||
1361 | |||
1362 | public function getExpired(): bool |
||
1363 | { |
||
1364 | return $this->expired; |
||
1365 | } |
||
1366 | |||
1367 | /** |
||
1368 | * Sets this user to expired. |
||
1369 | */ |
||
1370 | public function setExpired(bool $boolean): self |
||
1371 | { |
||
1372 | $this->expired = $boolean; |
||
1373 | |||
1374 | return $this; |
||
1375 | } |
||
1376 | |||
1377 | public function getLocked(): bool |
||
1378 | { |
||
1379 | return $this->locked; |
||
1380 | } |
||
1381 | |||
1382 | public function setLocked(bool $boolean): self |
||
1383 | { |
||
1384 | $this->locked = $boolean; |
||
1385 | |||
1386 | return $this; |
||
1387 | } |
||
1388 | |||
1389 | /** |
||
1390 | * Check if the user has the skill. |
||
1391 | * |
||
1392 | * @param Skill $skill The skill |
||
1393 | */ |
||
1394 | public function hasSkill(Skill $skill): bool |
||
1395 | { |
||
1396 | $achievedSkills = $this->getAchievedSkills(); |
||
1397 | foreach ($achievedSkills as $userSkill) { |
||
1398 | if ($userSkill->getSkill()->getId() !== $skill->getId()) { |
||
1399 | continue; |
||
1400 | } |
||
1401 | |||
1402 | return true; |
||
1403 | } |
||
1404 | |||
1405 | return false; |
||
1406 | } |
||
1407 | |||
1408 | /** |
||
1409 | * @return Collection<int, SkillRelUser> |
||
1410 | */ |
||
1411 | public function getAchievedSkills(): Collection |
||
1412 | { |
||
1413 | return $this->achievedSkills; |
||
1414 | } |
||
1415 | |||
1416 | /** |
||
1417 | * @param Collection<int, SkillRelUser> $value |
||
1418 | */ |
||
1419 | public function setAchievedSkills(Collection $value): self |
||
1420 | { |
||
1421 | $this->achievedSkills = $value; |
||
1422 | |||
1423 | return $this; |
||
1424 | } |
||
1425 | |||
1426 | public function isProfileCompleted(): ?bool |
||
1427 | { |
||
1428 | return $this->profileCompleted; |
||
1429 | } |
||
1430 | |||
1431 | public function setProfileCompleted(?bool $profileCompleted): self |
||
1432 | { |
||
1433 | $this->profileCompleted = $profileCompleted; |
||
1434 | |||
1435 | return $this; |
||
1436 | } |
||
1437 | |||
1438 | public function getCurrentUrl(): ?AccessUrl |
||
1439 | { |
||
1440 | return $this->currentUrl; |
||
1441 | } |
||
1442 | |||
1443 | public function setCurrentUrl(AccessUrl $url): self |
||
1444 | { |
||
1445 | $accessUrlRelUser = (new AccessUrlRelUser())->setUrl($url)->setUser($this); |
||
1446 | $this->getPortals()->add($accessUrlRelUser); |
||
1447 | |||
1448 | return $this; |
||
1449 | } |
||
1450 | |||
1451 | public function getPortals(): Collection |
||
1452 | { |
||
1453 | return $this->portals; |
||
1454 | } |
||
1455 | |||
1456 | /** |
||
1457 | * @param Collection<int, AccessUrlRelUser> $value |
||
1458 | */ |
||
1459 | public function setPortals(Collection $value): void |
||
1460 | { |
||
1461 | $this->portals = $value; |
||
1462 | } |
||
1463 | |||
1464 | public function getSessionsAsGeneralCoach(): array |
||
1465 | { |
||
1466 | return $this->getSessions(Session::GENERAL_COACH); |
||
1467 | } |
||
1468 | |||
1469 | /** |
||
1470 | * Retrieves this user's related sessions. |
||
1471 | */ |
||
1472 | public function getSessions(int $relationType): array |
||
1473 | { |
||
1474 | $sessions = []; |
||
1475 | foreach ($this->getSessionsRelUser() as $sessionRelUser) { |
||
1476 | if ($sessionRelUser->getRelationType() === $relationType) { |
||
1477 | $sessions[] = $sessionRelUser->getSession(); |
||
1478 | } |
||
1479 | } |
||
1480 | |||
1481 | return $sessions; |
||
1482 | } |
||
1483 | |||
1484 | /** |
||
1485 | * @return Collection<int, SessionRelUser> |
||
1486 | */ |
||
1487 | public function getSessionsRelUser(): Collection |
||
1488 | { |
||
1489 | return $this->sessionsRelUser; |
||
1490 | } |
||
1491 | |||
1492 | public function getSessionsAsAdmin(): array |
||
1493 | { |
||
1494 | return $this->getSessions(Session::SESSION_ADMIN); |
||
1495 | } |
||
1496 | |||
1497 | public function getCommentedUserSkills(): Collection |
||
1498 | { |
||
1499 | return $this->commentedUserSkills; |
||
1500 | } |
||
1501 | |||
1502 | /** |
||
1503 | * @param Collection<int, SkillRelUserComment> $commentedUserSkills |
||
1504 | */ |
||
1505 | public function setCommentedUserSkills(Collection $commentedUserSkills): self |
||
1506 | { |
||
1507 | $this->commentedUserSkills = $commentedUserSkills; |
||
1508 | |||
1509 | return $this; |
||
1510 | } |
||
1511 | |||
1512 | public function isEqualTo(UserInterface $user): bool |
||
1513 | { |
||
1514 | if ($this->password !== $user->getPassword()) { |
||
1515 | return false; |
||
1516 | } |
||
1517 | if ($this->salt !== $user->getSalt()) { |
||
1518 | return false; |
||
1519 | } |
||
1520 | if ($this->username !== $user->getUserIdentifier()) { |
||
1521 | return false; |
||
1522 | } |
||
1523 | |||
1524 | return true; |
||
1525 | } |
||
1526 | |||
1527 | public function getPassword(): ?string |
||
1528 | { |
||
1529 | return $this->password; |
||
1530 | } |
||
1531 | |||
1532 | public function setPassword(string $password): self |
||
1533 | { |
||
1534 | $this->password = $password; |
||
1535 | |||
1536 | return $this; |
||
1537 | } |
||
1538 | |||
1539 | public function getSalt(): ?string |
||
1540 | { |
||
1541 | return $this->salt; |
||
1542 | } |
||
1543 | |||
1544 | public function setSalt(string $salt): self |
||
1545 | { |
||
1546 | $this->salt = $salt; |
||
1547 | |||
1548 | return $this; |
||
1549 | } |
||
1550 | |||
1551 | public function getUserIdentifier(): string |
||
1552 | { |
||
1553 | return $this->username; |
||
1554 | } |
||
1555 | |||
1556 | /** |
||
1557 | * @return Collection<int, Message> |
||
1558 | */ |
||
1559 | public function getSentMessages(): Collection |
||
1560 | { |
||
1561 | return $this->sentMessages; |
||
1562 | } |
||
1563 | |||
1564 | public function getReceivedMessages(): Collection |
||
1565 | { |
||
1566 | return $this->receivedMessages; |
||
1567 | } |
||
1568 | |||
1569 | public function getCourseGroupsAsMember(): Collection |
||
1570 | { |
||
1571 | return $this->courseGroupsAsMember; |
||
1572 | } |
||
1573 | |||
1574 | public function getCourseGroupsAsTutor(): Collection |
||
1575 | { |
||
1576 | return $this->courseGroupsAsTutor; |
||
1577 | } |
||
1578 | |||
1579 | public function getCourseGroupsAsMemberFromCourse(Course $course): Collection |
||
1580 | { |
||
1581 | $criteria = Criteria::create(); |
||
1582 | $criteria->where(Criteria::expr()->eq('cId', $course)); |
||
1583 | |||
1584 | return $this->courseGroupsAsMember->matching($criteria); |
||
1585 | } |
||
1586 | |||
1587 | public function eraseCredentials(): void |
||
1588 | { |
||
1589 | $this->plainPassword = null; |
||
1590 | } |
||
1591 | |||
1592 | public function isSuperAdmin(): bool |
||
1593 | { |
||
1594 | return $this->hasRole('ROLE_SUPER_ADMIN'); |
||
1595 | } |
||
1596 | |||
1597 | public function hasRole(string $role): bool |
||
1598 | { |
||
1599 | return \in_array(strtoupper($role), $this->getRoles(), true); |
||
1600 | } |
||
1601 | |||
1602 | /** |
||
1603 | * Returns the user roles. |
||
1604 | */ |
||
1605 | public function getRoles(): array |
||
1606 | { |
||
1607 | $roles = $this->roles; |
||
1608 | foreach ($this->getGroups() as $group) { |
||
1609 | $roles = array_merge($roles, $group->getRoles()); |
||
1610 | } |
||
1611 | // we need to make sure to have at least one role |
||
1612 | $roles[] = 'ROLE_USER'; |
||
1613 | |||
1614 | return array_unique($roles); |
||
1615 | } |
||
1616 | |||
1617 | public function setRoles(array $roles): self |
||
1618 | { |
||
1619 | $this->roles = []; |
||
1620 | foreach ($roles as $role) { |
||
1621 | $this->addRole($role); |
||
1622 | } |
||
1623 | |||
1624 | return $this; |
||
1625 | } |
||
1626 | |||
1627 | public function setRoleFromStatus(int $status): void |
||
1628 | { |
||
1629 | $role = self::getRoleFromStatus($status); |
||
1630 | $this->addRole($role); |
||
1631 | } |
||
1632 | |||
1633 | public static function getRoleFromStatus(int $status): string |
||
1634 | { |
||
1635 | return match ($status) { |
||
1636 | COURSEMANAGER => 'ROLE_TEACHER', |
||
1637 | STUDENT => 'ROLE_STUDENT', |
||
1638 | DRH => 'ROLE_HR', |
||
1639 | SESSIONADMIN => 'ROLE_SESSION_MANAGER', |
||
1640 | STUDENT_BOSS => 'ROLE_STUDENT_BOSS', |
||
1641 | INVITEE => 'ROLE_INVITEE', |
||
1642 | default => 'ROLE_USER', |
||
1643 | }; |
||
1644 | } |
||
1645 | |||
1646 | public function addRole(string $role): self |
||
1647 | { |
||
1648 | $role = strtoupper($role); |
||
1649 | if ($role === static::ROLE_DEFAULT || empty($role)) { |
||
1650 | return $this; |
||
1651 | } |
||
1652 | if (!\in_array($role, $this->roles, true)) { |
||
1653 | $this->roles[] = $role; |
||
1654 | } |
||
1655 | |||
1656 | return $this; |
||
1657 | } |
||
1658 | |||
1659 | public function removeRole(string $role): self |
||
1660 | { |
||
1661 | if (false !== ($key = array_search(strtoupper($role), $this->roles, true))) { |
||
1662 | unset($this->roles[$key]); |
||
1663 | $this->roles = array_values($this->roles); |
||
1664 | } |
||
1665 | |||
1666 | return $this; |
||
1667 | } |
||
1668 | |||
1669 | public function getUsernameCanonical(): string |
||
1670 | { |
||
1671 | return $this->usernameCanonical; |
||
1672 | } |
||
1673 | |||
1674 | public function setUsernameCanonical(string $usernameCanonical): self |
||
1675 | { |
||
1676 | $this->usernameCanonical = $usernameCanonical; |
||
1677 | |||
1678 | return $this; |
||
1679 | } |
||
1680 | |||
1681 | public function getEmailCanonical(): string |
||
1682 | { |
||
1683 | return $this->emailCanonical; |
||
1684 | } |
||
1685 | |||
1686 | public function setEmailCanonical(string $emailCanonical): self |
||
1687 | { |
||
1688 | $this->emailCanonical = $emailCanonical; |
||
1689 | |||
1690 | return $this; |
||
1691 | } |
||
1692 | |||
1693 | public function getTimezone(): string |
||
1694 | { |
||
1695 | return $this->timezone; |
||
1696 | } |
||
1697 | |||
1698 | public function setTimezone(string $timezone): self |
||
1699 | { |
||
1700 | $this->timezone = $timezone; |
||
1701 | |||
1702 | return $this; |
||
1703 | } |
||
1704 | |||
1705 | public function getLocale(): string |
||
1706 | { |
||
1707 | return $this->locale; |
||
1708 | } |
||
1709 | |||
1710 | public function setLocale(string $locale): self |
||
1711 | { |
||
1712 | $this->locale = $locale; |
||
1713 | |||
1714 | return $this; |
||
1715 | } |
||
1716 | |||
1717 | public function getApiToken(): ?string |
||
1718 | { |
||
1719 | return $this->apiToken; |
||
1720 | } |
||
1721 | |||
1722 | public function setApiToken(string $apiToken): self |
||
1723 | { |
||
1724 | $this->apiToken = $apiToken; |
||
1725 | |||
1726 | return $this; |
||
1727 | } |
||
1728 | |||
1729 | public function getWebsite(): ?string |
||
1730 | { |
||
1731 | return $this->website; |
||
1732 | } |
||
1733 | |||
1734 | public function setWebsite(string $website): self |
||
1735 | { |
||
1736 | $this->website = $website; |
||
1737 | |||
1738 | return $this; |
||
1739 | } |
||
1740 | |||
1741 | public function getBiography(): ?string |
||
1742 | { |
||
1743 | return $this->biography; |
||
1744 | } |
||
1745 | |||
1746 | public function setBiography(string $biography): self |
||
1747 | { |
||
1748 | $this->biography = $biography; |
||
1749 | |||
1750 | return $this; |
||
1751 | } |
||
1752 | |||
1753 | public function getDateOfBirth(): ?DateTime |
||
1754 | { |
||
1755 | return $this->dateOfBirth; |
||
1756 | } |
||
1757 | |||
1758 | public function setDateOfBirth(?DateTime $dateOfBirth = null): self |
||
1759 | { |
||
1760 | $this->dateOfBirth = $dateOfBirth; |
||
1761 | |||
1762 | return $this; |
||
1763 | } |
||
1764 | |||
1765 | public function getProfileUrl(): string |
||
1766 | { |
||
1767 | return '/main/social/profile.php?u='.$this->id; |
||
1768 | } |
||
1769 | |||
1770 | public function getIconStatus(): string |
||
1771 | { |
||
1772 | $hasCertificates = $this->getGradeBookCertificates()->count() > 0; |
||
1773 | $urlImg = '/img/'; |
||
1774 | if ($this->isStudent()) { |
||
1775 | $iconStatus = $urlImg.'icons/svg/identifier_student.svg'; |
||
1776 | if ($hasCertificates) { |
||
1777 | $iconStatus = $urlImg.'icons/svg/identifier_graduated.svg'; |
||
1778 | } |
||
1779 | |||
1780 | return $iconStatus; |
||
1781 | } |
||
1782 | if ($this->isTeacher()) { |
||
1783 | $iconStatus = $urlImg.'icons/svg/identifier_teacher.svg'; |
||
1784 | if ($this->isAdmin()) { |
||
1785 | $iconStatus = $urlImg.'icons/svg/identifier_admin.svg'; |
||
1786 | } |
||
1787 | |||
1788 | return $iconStatus; |
||
1789 | } |
||
1790 | if ($this->isStudentBoss()) { |
||
1791 | return $urlImg.'icons/svg/identifier_teacher.svg'; |
||
1792 | } |
||
1793 | |||
1794 | return ''; |
||
1795 | } |
||
1796 | |||
1797 | public function getGradeBookCertificates(): Collection |
||
1798 | { |
||
1799 | return $this->gradeBookCertificates; |
||
1800 | } |
||
1801 | |||
1802 | /** |
||
1803 | * @param Collection<int, GradebookCertificate> $gradeBookCertificates |
||
1804 | */ |
||
1805 | public function setGradeBookCertificates(Collection $gradeBookCertificates): self |
||
1806 | { |
||
1807 | $this->gradeBookCertificates = $gradeBookCertificates; |
||
1808 | |||
1809 | return $this; |
||
1810 | } |
||
1811 | |||
1812 | public function isStudent(): bool |
||
1813 | { |
||
1814 | return $this->hasRole('ROLE_STUDENT'); |
||
1815 | } |
||
1816 | |||
1817 | public function isTeacher(): bool |
||
1818 | { |
||
1819 | return $this->hasRole('ROLE_TEACHER'); |
||
1820 | } |
||
1821 | |||
1822 | public function isAdmin(): bool |
||
1823 | { |
||
1824 | return $this->hasRole('ROLE_ADMIN'); |
||
1825 | } |
||
1826 | |||
1827 | public function isStudentBoss(): bool |
||
1828 | { |
||
1829 | return $this->hasRole('ROLE_STUDENT_BOSS'); |
||
1830 | } |
||
1831 | |||
1832 | public function isSessionAdmin(): bool |
||
1833 | { |
||
1834 | return $this->hasRole('ROLE_SESSION_MANAGER'); |
||
1835 | } |
||
1836 | |||
1837 | public function isInvitee(): bool |
||
1838 | { |
||
1839 | return $this->hasRole('ROLE_INVITEE'); |
||
1840 | } |
||
1841 | |||
1842 | public function isHRM(): bool |
||
1843 | { |
||
1844 | return $this->hasRole('ROLE_HR'); |
||
1845 | } |
||
1846 | |||
1847 | public function getStatus(): int |
||
1848 | { |
||
1849 | return $this->status; |
||
1850 | } |
||
1851 | |||
1852 | public function setStatus(int $status): self |
||
1853 | { |
||
1854 | $this->status = $status; |
||
1855 | |||
1856 | return $this; |
||
1857 | } |
||
1858 | |||
1859 | public function getPictureUri(): ?string |
||
1860 | { |
||
1861 | return $this->pictureUri; |
||
1862 | } |
||
1863 | |||
1864 | /** |
||
1865 | * @return Collection<int, GradebookCategory> |
||
1866 | */ |
||
1867 | public function getGradeBookCategories(): Collection |
||
1868 | { |
||
1869 | return $this->gradeBookCategories; |
||
1870 | } |
||
1871 | |||
1872 | /** |
||
1873 | * @return Collection<int, GradebookComment> |
||
1874 | */ |
||
1875 | public function getGradeBookComments(): Collection |
||
1876 | { |
||
1877 | return $this->gradeBookComments; |
||
1878 | } |
||
1879 | |||
1880 | /** |
||
1881 | * @return Collection<int, GradebookResult> |
||
1882 | */ |
||
1883 | public function getGradeBookResults(): Collection |
||
1884 | { |
||
1885 | return $this->gradeBookResults; |
||
1886 | } |
||
1887 | |||
1888 | /** |
||
1889 | * @return Collection<int, GradebookResultLog> |
||
1890 | */ |
||
1891 | public function getGradeBookResultLogs(): Collection |
||
1892 | { |
||
1893 | return $this->gradeBookResultLogs; |
||
1894 | } |
||
1895 | |||
1896 | /** |
||
1897 | * @return Collection<int, GradebookScoreLog> |
||
1898 | */ |
||
1899 | public function getGradeBookScoreLogs(): Collection |
||
1900 | { |
||
1901 | return $this->gradeBookScoreLogs; |
||
1902 | } |
||
1903 | |||
1904 | /** |
||
1905 | * @return Collection<int, GradebookLinkevalLog> |
||
1906 | */ |
||
1907 | public function getGradeBookLinkEvalLogs(): Collection |
||
1908 | { |
||
1909 | return $this->gradeBookLinkEvalLogs; |
||
1910 | } |
||
1911 | |||
1912 | /** |
||
1913 | * @return Collection<int, UserRelCourseVote> |
||
1914 | */ |
||
1915 | public function getUserRelCourseVotes(): Collection |
||
1916 | { |
||
1917 | return $this->userRelCourseVotes; |
||
1918 | } |
||
1919 | |||
1920 | /** |
||
1921 | * @return Collection<int, UserRelTag> |
||
1922 | */ |
||
1923 | public function getUserRelTags(): Collection |
||
1924 | { |
||
1925 | return $this->userRelTags; |
||
1926 | } |
||
1927 | |||
1928 | public function getCurriculumItems(): Collection |
||
1929 | { |
||
1930 | return $this->curriculumItems; |
||
1931 | } |
||
1932 | |||
1933 | /** |
||
1934 | * @return Collection<int, UserRelUser> |
||
1935 | */ |
||
1936 | public function getFriends(): Collection |
||
1939 | } |
||
1940 | |||
1941 | /** |
||
1942 | * @return Collection<int, UserRelUser> |
||
1943 | */ |
||
1944 | public function getFriendsWithMe(): Collection |
||
1945 | { |
||
1946 | return $this->friendsWithMe; |
||
1947 | } |
||
1948 | |||
1949 | public function addFriend(self $friend): self |
||
1952 | } |
||
1953 | |||
1954 | public function addUserRelUser(self $friend, int $relationType): self |
||
1955 | { |
||
1956 | $userRelUser = (new UserRelUser())->setUser($this)->setFriend($friend)->setRelationType($relationType); |
||
1957 | $this->friends->add($userRelUser); |
||
1958 | |||
1959 | return $this; |
||
1960 | } |
||
1961 | |||
1962 | /** |
||
1963 | * @return Collection<int, Templates> |
||
1964 | */ |
||
1965 | public function getTemplates(): Collection |
||
1966 | { |
||
1967 | return $this->templates; |
||
1968 | } |
||
1969 | |||
1970 | public function getDropBoxReceivedFiles(): Collection |
||
1971 | { |
||
1972 | return $this->dropBoxReceivedFiles; |
||
1973 | } |
||
1974 | |||
1975 | /** |
||
1976 | * @return Collection<int, SequenceValue> |
||
1977 | */ |
||
1978 | public function getSequenceValues(): Collection |
||
1979 | { |
||
1980 | return $this->sequenceValues; |
||
1981 | } |
||
1982 | |||
1983 | /** |
||
1984 | * @return Collection<int, TrackEExerciseConfirmation> |
||
1985 | */ |
||
1986 | public function getTrackEExerciseConfirmations(): Collection |
||
1987 | { |
||
1988 | return $this->trackEExerciseConfirmations; |
||
1989 | } |
||
1990 | |||
1991 | /** |
||
1992 | * @return Collection<int, TrackEAttempt> |
||
1993 | */ |
||
1994 | public function getTrackEAccessCompleteList(): Collection |
||
1997 | } |
||
1998 | |||
1999 | /** |
||
2000 | * @return Collection<int, TrackEAttempt> |
||
2001 | */ |
||
2002 | public function getTrackEAttempts(): Collection |
||
2003 | { |
||
2004 | return $this->trackEAttempts; |
||
2005 | } |
||
2006 | |||
2007 | /** |
||
2008 | * @return Collection<int, TrackECourseAccess> |
||
2009 | */ |
||
2010 | public function getTrackECourseAccess(): Collection |
||
2011 | { |
||
2012 | return $this->trackECourseAccess; |
||
2013 | } |
||
2014 | |||
2015 | /** |
||
2016 | * @return Collection<int, UserCourseCategory> |
||
2017 | */ |
||
2018 | public function getUserCourseCategories(): Collection |
||
2019 | { |
||
2020 | return $this->userCourseCategories; |
||
2021 | } |
||
2022 | |||
2023 | public function getCourseGroupsAsTutorFromCourse(Course $course): Collection |
||
2024 | { |
||
2025 | $criteria = Criteria::create(); |
||
2026 | $criteria->where(Criteria::expr()->eq('cId', $course->getId())); |
||
2027 | |||
2028 | return $this->courseGroupsAsTutor->matching($criteria); |
||
2029 | } |
||
2030 | |||
2031 | /** |
||
2032 | * Retrieves this user's related student sessions. |
||
2033 | * |
||
2034 | * @return Session[] |
||
2035 | */ |
||
2036 | public function getSessionsAsStudent(): array |
||
2037 | { |
||
2038 | return $this->getSessions(Session::STUDENT); |
||
2039 | } |
||
2040 | |||
2041 | public function addSessionRelUser(SessionRelUser $sessionSubscription): static |
||
2042 | { |
||
2043 | $this->sessionsRelUser->add($sessionSubscription); |
||
2044 | |||
2045 | return $this; |
||
2046 | } |
||
2047 | |||
2048 | public function isSkipResourceNode(): bool |
||
2049 | { |
||
2050 | return $this->skipResourceNode; |
||
2051 | } |
||
2052 | |||
2053 | public function setSkipResourceNode(bool $skipResourceNode): self |
||
2054 | { |
||
2055 | $this->skipResourceNode = $skipResourceNode; |
||
2056 | |||
2057 | return $this; |
||
2058 | } |
||
2059 | |||
2060 | /** |
||
2061 | * Retrieves this user's related DRH sessions. |
||
2062 | * |
||
2063 | * @return Session[] |
||
2064 | */ |
||
2065 | public function getDRHSessions(): array |
||
2066 | { |
||
2067 | return $this->getSessions(Session::DRH); |
||
2068 | } |
||
2069 | |||
2070 | /** |
||
2071 | * Get this user's related accessible sessions of a type, student by default. |
||
2072 | * |
||
2073 | * @return Session[] |
||
2074 | */ |
||
2075 | public function getCurrentlyAccessibleSessions(int $relationType = Session::STUDENT): array |
||
2076 | { |
||
2077 | $sessions = []; |
||
2078 | foreach ($this->getSessions($relationType) as $session) { |
||
2079 | if ($session->isCurrentlyAccessible()) { |
||
2080 | $sessions[] = $session; |
||
2081 | } |
||
2082 | } |
||
2083 | |||
2084 | return $sessions; |
||
2085 | } |
||
2086 | |||
2087 | public function getResourceIdentifier(): int |
||
2088 | { |
||
2089 | return $this->id; |
||
2090 | } |
||
2091 | |||
2092 | public function getResourceName(): string |
||
2093 | { |
||
2094 | return $this->getUsername(); |
||
2095 | } |
||
2096 | |||
2097 | public function setResourceName(string $name): void |
||
2098 | { |
||
2099 | $this->setUsername($name); |
||
2100 | } |
||
2101 | |||
2102 | public function setParent(AbstractResource $parent): void {} |
||
2103 | |||
2104 | public function getDefaultIllustration(int $size): string |
||
2105 | { |
||
2106 | $size = empty($size) ? 32 : $size; |
||
2107 | |||
2108 | return \sprintf('/img/icons/%s/unknown.png', $size); |
||
2109 | } |
||
2110 | |||
2111 | public function getAdmin(): ?Admin |
||
2112 | { |
||
2113 | return $this->admin; |
||
2114 | } |
||
2115 | |||
2116 | public function setAdmin(?Admin $admin): self |
||
2117 | { |
||
2118 | $this->admin = $admin; |
||
2119 | |||
2120 | return $this; |
||
2121 | } |
||
2122 | |||
2123 | public function addUserAsAdmin(): self |
||
2124 | { |
||
2125 | if (null === $this->admin) { |
||
2126 | $admin = new Admin(); |
||
2127 | $admin->setUser($this); |
||
2128 | $this->setAdmin($admin); |
||
2129 | $this->addRole('ROLE_ADMIN'); |
||
2130 | } |
||
2131 | |||
2132 | return $this; |
||
2133 | } |
||
2134 | |||
2135 | public function getSessionsByStatusInCourseSubscription(int $status): ReadableCollection |
||
2136 | { |
||
2137 | $criteria = Criteria::create()->where(Criteria::expr()->eq('status', $status)); |
||
2138 | |||
2139 | /** @var ArrayCollection $subscriptions */ |
||
2140 | $subscriptions = $this->getSessionRelCourseRelUsers(); |
||
2141 | |||
2142 | return $subscriptions->matching($criteria)->map( |
||
2143 | fn (SessionRelCourseRelUser $sessionRelCourseRelUser) => $sessionRelCourseRelUser->getSession() |
||
2144 | ); |
||
2145 | } |
||
2146 | |||
2147 | /** |
||
2148 | * @return Collection<int, SessionRelCourseRelUser> |
||
2149 | */ |
||
2150 | public function getSessionRelCourseRelUsers(): Collection |
||
2151 | { |
||
2152 | return $this->sessionRelCourseRelUsers; |
||
2153 | } |
||
2154 | |||
2155 | /** |
||
2156 | * @param Collection<int, SessionRelCourseRelUser> $sessionRelCourseRelUsers |
||
2157 | */ |
||
2158 | public function setSessionRelCourseRelUsers(Collection $sessionRelCourseRelUsers): self |
||
2159 | { |
||
2160 | $this->sessionRelCourseRelUsers = $sessionRelCourseRelUsers; |
||
2161 | |||
2162 | return $this; |
||
2163 | } |
||
2164 | |||
2165 | public function getGender(): ?string |
||
2166 | { |
||
2167 | return $this->gender; |
||
2168 | } |
||
2169 | |||
2170 | public function setGender(?string $gender): self |
||
2171 | { |
||
2172 | $this->gender = $gender; |
||
2173 | |||
2174 | return $this; |
||
2175 | } |
||
2176 | |||
2177 | /** |
||
2178 | * @return Collection<int, CSurveyInvitation> |
||
2179 | */ |
||
2180 | public function getSurveyInvitations(): Collection |
||
2183 | } |
||
2184 | |||
2185 | public function setSurveyInvitations(Collection $surveyInvitations): self |
||
2186 | { |
||
2187 | $this->surveyInvitations = $surveyInvitations; |
||
2188 | |||
2189 | return $this; |
||
2190 | } |
||
2191 | |||
2192 | public function getLogin(): string |
||
2193 | { |
||
2194 | return $this->username; |
||
2195 | } |
||
2196 | |||
2197 | public function setLogin(string $login): self |
||
2198 | { |
||
2199 | $this->username = $login; |
||
2200 | |||
2201 | return $this; |
||
2202 | } |
||
2203 | |||
2204 | /** |
||
2205 | * @return Collection<int, TrackELogin> |
||
2206 | */ |
||
2207 | public function getLogins(): Collection |
||
2208 | { |
||
2209 | return $this->logins; |
||
2210 | } |
||
2211 | |||
2212 | public function setLogins(Collection $logins): self |
||
2213 | { |
||
2214 | $this->logins = $logins; |
||
2215 | |||
2216 | return $this; |
||
2217 | } |
||
2218 | |||
2219 | /** |
||
2220 | * @return Collection<int, MessageTag> |
||
2221 | */ |
||
2222 | public function getMessageTags(): Collection |
||
2223 | { |
||
2224 | return $this->messageTags; |
||
2225 | } |
||
2226 | |||
2227 | /** |
||
2228 | * @param Collection<int, MessageTag> $messageTags |
||
2229 | */ |
||
2230 | public function setMessageTags(Collection $messageTags): self |
||
2231 | { |
||
2232 | $this->messageTags = $messageTags; |
||
2233 | |||
2234 | return $this; |
||
2235 | } |
||
2236 | |||
2237 | /** |
||
2238 | * @param null|UserCourseCategory $userCourseCategory the user_course_category |
||
2239 | * |
||
2240 | * @todo move in a repo |
||
2241 | * Find the largest sort value in a given UserCourseCategory |
||
2242 | * This method is used when we are moving a course to a different category |
||
2243 | * and also when a user subscribes to courses (the new course is added at the end of the main category). |
||
2244 | * |
||
2245 | * Used to be implemented in global function \api_max_sort_value. |
||
2246 | * Reimplemented using the ORM cache. |
||
2247 | */ |
||
2248 | public function getMaxSortValue(?UserCourseCategory $userCourseCategory = null): int |
||
2249 | { |
||
2250 | $categoryCourses = $this->courses->matching( |
||
2251 | Criteria::create()->where(Criteria::expr()->neq('relationType', COURSE_RELATION_TYPE_RRHH))->andWhere( |
||
2252 | Criteria::expr()->eq('userCourseCat', $userCourseCategory) |
||
2253 | ) |
||
2254 | ); |
||
2255 | |||
2256 | return $categoryCourses->isEmpty() ? 0 : max( |
||
2257 | $categoryCourses->map(fn ($courseRelUser) => $courseRelUser->getSort())->toArray() |
||
2258 | ); |
||
2259 | } |
||
2260 | |||
2261 | public function hasFriendWithRelationType(self $friend, int $relationType): bool |
||
2262 | { |
||
2263 | $friends = $this->getFriendsByRelationType($relationType); |
||
2264 | |||
2265 | return $friends->exists(fn (int $index, UserRelUser $userRelUser) => $userRelUser->getFriend() === $friend); |
||
2266 | } |
||
2267 | |||
2268 | public function isFriendWithMeByRelationType(self $friend, int $relationType): bool |
||
2269 | { |
||
2270 | return $this |
||
2271 | ->getFriendsWithMeByRelationType($relationType) |
||
2272 | ->exists(fn (int $index, UserRelUser $userRelUser) => $userRelUser->getUser() === $friend) |
||
2273 | ; |
||
2274 | } |
||
2275 | |||
2276 | /** |
||
2277 | * @param int $relationType Example: UserRelUser::USER_RELATION_TYPE_BOSS |
||
2278 | * |
||
2279 | * @return Collection<int, UserRelUser> |
||
2280 | */ |
||
2281 | public function getFriendsByRelationType(int $relationType): Collection |
||
2282 | { |
||
2283 | $criteria = Criteria::create(); |
||
2284 | $criteria->where(Criteria::expr()->eq('relationType', $relationType)); |
||
2285 | |||
2286 | return $this->friends->matching($criteria); |
||
2287 | } |
||
2288 | |||
2289 | public function getFriendsWithMeByRelationType(int $relationType): Collection |
||
2290 | { |
||
2291 | $criteria = Criteria::create(); |
||
2292 | $criteria->where(Criteria::expr()->eq('relationType', $relationType)); |
||
2293 | |||
2294 | return $this->friendsWithMe->matching($criteria); |
||
2295 | } |
||
2296 | |||
2297 | public function getFriendsOfFriends(): array |
||
2298 | { |
||
2299 | $friendsOfFriends = []; |
||
2300 | foreach ($this->getFriends() as $friendRelation) { |
||
2301 | foreach ($friendRelation->getFriend()->getFriends() as $friendOfFriendRelation) { |
||
2302 | $friendsOfFriends[] = $friendOfFriendRelation->getFriend(); |
||
2303 | } |
||
2304 | } |
||
2305 | |||
2306 | return $friendsOfFriends; |
||
2307 | } |
||
2308 | |||
2309 | /** |
||
2310 | * @return Collection<int, SocialPost> |
||
2311 | */ |
||
2312 | public function getSentSocialPosts(): Collection |
||
2313 | { |
||
2314 | return $this->sentSocialPosts; |
||
2315 | } |
||
2316 | |||
2317 | public function addSentSocialPost(SocialPost $sentSocialPost): self |
||
2318 | { |
||
2319 | if (!$this->sentSocialPosts->contains($sentSocialPost)) { |
||
2320 | $this->sentSocialPosts[] = $sentSocialPost; |
||
2321 | $sentSocialPost->setSender($this); |
||
2322 | } |
||
2323 | |||
2324 | return $this; |
||
2325 | } |
||
2326 | |||
2327 | /** |
||
2328 | * @return Collection<int, SocialPost> |
||
2329 | */ |
||
2330 | public function getReceivedSocialPosts(): Collection |
||
2331 | { |
||
2332 | return $this->receivedSocialPosts; |
||
2333 | } |
||
2334 | |||
2335 | public function addReceivedSocialPost(SocialPost $receivedSocialPost): self |
||
2336 | { |
||
2337 | if (!$this->receivedSocialPosts->contains($receivedSocialPost)) { |
||
2338 | $this->receivedSocialPosts[] = $receivedSocialPost; |
||
2339 | $receivedSocialPost->setUserReceiver($this); |
||
2340 | } |
||
2341 | |||
2342 | return $this; |
||
2343 | } |
||
2344 | |||
2345 | public function getSocialPostFeedbackBySocialPost(SocialPost $post): ?SocialPostFeedback |
||
2346 | { |
||
2347 | $filtered = $this->getSocialPostsFeedbacks()->filter( |
||
2348 | fn (SocialPostFeedback $postFeedback) => $postFeedback->getSocialPost() === $post |
||
2349 | ); |
||
2350 | if ($filtered->count() > 0) { |
||
2351 | return $filtered->first(); |
||
2352 | } |
||
2353 | |||
2354 | return null; |
||
2355 | } |
||
2356 | |||
2357 | /** |
||
2358 | * @return Collection<int, SocialPostFeedback> |
||
2359 | */ |
||
2360 | public function getSocialPostsFeedbacks(): Collection |
||
2361 | { |
||
2362 | return $this->socialPostsFeedbacks; |
||
2363 | } |
||
2364 | |||
2365 | public function addSocialPostFeedback(SocialPostFeedback $socialPostFeedback): self |
||
2366 | { |
||
2367 | if (!$this->socialPostsFeedbacks->contains($socialPostFeedback)) { |
||
2368 | $this->socialPostsFeedbacks[] = $socialPostFeedback; |
||
2369 | $socialPostFeedback->setUser($this); |
||
2370 | } |
||
2371 | |||
2372 | return $this; |
||
2373 | } |
||
2374 | |||
2375 | public function getSubscriptionToSession(Session $session): ?SessionRelUser |
||
2376 | { |
||
2377 | $criteria = Criteria::create(); |
||
2378 | $criteria->where( |
||
2379 | Criteria::expr()->eq('session', $session) |
||
2380 | ); |
||
2381 | |||
2382 | $match = $this->sessionsRelUser->matching($criteria); |
||
2383 | |||
2384 | if ($match->count() > 0) { |
||
2385 | return $match->first(); |
||
2386 | } |
||
2387 | |||
2388 | return null; |
||
2389 | } |
||
2390 | |||
2391 | public function getFirstAccessToSession(Session $session): ?TrackECourseAccess |
||
2402 | } |
||
2403 | |||
2404 | public function isCourseTutor(?Course $course = null, ?Session $session = null): bool |
||
2407 | } |
||
2408 | } |
||
2409 |