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