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