'ASC'])] private Collection $availabilities; #[ORM\OneToMany(mappedBy: 'owner', targetEntity: Availability::class)] private Collection $customAvailabilities; #[ORM\OneToOne(cascade: ['persist', 'remove'], fetch: 'EAGER')] #[Assert\NotNull(message: 'Bitte lade ein Foto von dir hoch', groups: ['profile', 'profile_preflight'])] private ?Upload $photo = null; #[ORM\OneToMany(mappedBy: 'teamer', targetEntity: Feedback::class, cascade: ['remove'])] private Collection $feedback; #[ORM\OneToMany(mappedBy: 'teamer', targetEntity: TrainingAttendance::class, cascade: ['remove'])] private Collection $trainingAttendances; #[ORM\OneToMany(mappedBy: 'teamer', targetEntity: License::class, cascade: ['remove'])] private Collection $licenses; #[ORM\ManyToMany(targetEntity: JobProfile::class)] private Collection $jobProfiles; #[ORM\ManyToMany(targetEntity: Assignment::class, inversedBy: 'teamers')] private Collection $bookmarks; #[ORM\OneToMany(mappedBy: 'teamer', targetEntity: Application::class, cascade: ['remove'])] private Collection $applications; #[ORM\OneToMany(mappedBy: 'teamer', targetEntity: Disposition::class, cascade: ['remove'])] private Collection $dispositions; #[ORM\OneToOne(mappedBy: 'teamer', fetch: 'EXTRA_LAZY')] private ?User $user = null; #[ORM\Column] private array $pickups = []; #[ORM\Column(length: 255, nullable: true)] #[Assert\NotBlank(message: 'Bitte gib deine Sprache(n) an', groups: ['profile', 'profile_preflight'])] private ?string $language = null; #[ORM\Column(length: 3, nullable: true)] private ?string $size = null; #[ORM\Column(nullable: true, enumType: MealPreference::class)] #[Assert\NotNull(message: 'Bitte gib deine Ernährungsweise an', groups: ['profile', 'profile_preflight'])] private ?MealPreference $mealPreference = null; #[ORM\Column(nullable: true)] private ?array $crmSelections = null; #[ORM\Column] private bool $viewed = false; #[ORM\Column] private bool $allowOverlappingApplications = false; #[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)] private ?\DateTimeImmutable $dataVerifiedAt = null; #[ORM\Column(nullable: true)] private ?bool $driverLicenseDeclaration = null; #[ORM\Column] private bool $driverLicenseVerified = false; #[ORM\Column(length: 64)] private string $driverLicenseStatus = self::DRIVER_LICENSE_STATUS_NONE; #[ORM\OneToOne(cascade: ['persist', 'remove'])] private ?Upload $driverLicenseUpload = null; #[ORM\Column(type: Types::TEXT, nullable: true)] private ?string $driverLicenseReviewComment = null; #[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)] private ?\DateTimeImmutable $driverLicenseReviewedAt = null; #[ORM\Column(length: 8, nullable: true)] private ?string $driverLicenseReviewedBy = null; public function __construct() { $this->uuid = Uuid::v4(); $this->status = static::STATUS_NEW; $this->availabilities = new ArrayCollection(); $this->feedback = new ArrayCollection(); $this->trainingAttendances = new ArrayCollection(); $this->licenses = new ArrayCollection(); $this->jobProfiles = new ArrayCollection(); $this->bookmarks = new ArrayCollection(); $this->applications = new ArrayCollection(); $this->dispositions = new ArrayCollection(); $this->customAvailabilities = new ArrayCollection(); } public function __toString() { return $this->getFullName(); } public function toPayload(): array { // Transform gender value $gender = strtoupper($this->getGender()); $gender = 'F' === $gender ? 'W' : $gender; // Ensure date of birth is populated if (null === $dob = $this->getDateOfBirth()) { $dob = new \DateTimeImmutable('18 years ago'); } return [ 'geburtsdatum' => $dob->format('d.m.Y'), 'anrede' => $this->getSalutation(), 'geschlecht' => $gender, 'titel' => $this->getAcademicTitle(), 'vorname' => $this->getFirstName(), 'name' => $this->getLastName(), 'anschrift' => $this->getAddress()->toPayload(), 'kommunikation' => $this->getCommunication()->toPayload(), ]; } public static function fromApiResponse(ProfileResponse $profileResponse): static { $instance = new static(); $instance ->setAcademicTitle($profileResponse->getTitle()) ->setSalutation($profileResponse->getSalutation()) ->setFirstName($profileResponse->getFirstName()) ->setLastName($profileResponse->getName()) ->setGender($profileResponse->getGender()) ->setDateOfBirth($profileResponse->getDateOfBirth()) ; $address = Address::fromApiResponse($profileResponse); $communication = Communication::fromApiResponse($profileResponse); $instance ->setAddress($address) ->setCommunication($communication) ; return $instance; } public static function fromUserinfo(array $userinfo): static { $instance = new static(); $instance ->setAcademicTitle($userinfo['profile']['title'] ?? null) ->setSalutation($userinfo['profile']['salutation'] ?? null) ->setFirstName($userinfo['profile']['first_name'] ?? null) ->setLastName($userinfo['profile']['last_name'] ?? null) ->setGender($userinfo['profile']['gender'] ?? null) ; if (true === isset($userinfo['profile']['date_of_birth'])) { try { $dateOfBirth = new \DateTimeImmutable((string) $userinfo['profile']['date_of_birth']); $instance->setDateOfBirth($dateOfBirth); } catch (\Exception|\TypeError $e) { } } $address = Address::fromUserinfo($userinfo); $communication = Communication::fromUserinfo($userinfo); $instance ->setAddress($address) ->setCommunication($communication) ; return $instance; } public function getId(): ?int { return $this->id; } public function getUuid(): string { return $this->uuid; } public function getFirstName(): ?string { return $this->firstName; } public function setFirstName(?string $firstName): static { $this->firstName = $firstName; return $this; } public function getLastName(): ?string { return $this->lastName; } public function setLastName(?string $lastName): static { $this->lastName = $lastName; return $this; } public function getFullName(bool $formal = false): string { if (true === $formal) { return sprintf('%s, %s', $this->getLastName(), $this->getFirstName()); } return sprintf('%s %s', $this->getFirstName(), $this->getLastName()); } public function getGender(): ?string { return $this->gender; } public function setGender(?string $gender): static { $this->gender = $gender; return $this; } public function getDateOfBirth(): ?\DateTimeImmutable { return $this->dateOfBirth; } public function setDateOfBirth(?\DateTimeImmutable $dateOfBirth): static { $this->dateOfBirth = $dateOfBirth; return $this; } public function getAcademicTitle(): ?string { return $this->academicTitle; } public function setAcademicTitle(?string $academicTitle): static { $this->academicTitle = $academicTitle; return $this; } public function getSalutation(): ?string { return $this->salutation; } public function setSalutation(?string $salutation): static { $this->salutation = $salutation; return $this; } public function getNationality(): ?string { return $this->nationality; } public function setNationality(?string $nationality): static { $this->nationality = $nationality; return $this; } public function getAddress(): ?Address { return $this->address; } public function setAddress(?Address $address): static { $this->address = $address; return $this; } public function getCommunication(): ?Communication { return $this->communication; } public function setCommunication(?Communication $communication): static { $this->communication = $communication; return $this; } public function getBankAccount(): ?BankAccount { return $this->bankAccount; } public function setBankAccount(?BankAccount $bankAccount): static { $this->bankAccount = $bankAccount; return $this; } public function getTaxId(): ?string { return $this->taxId; } public function setTaxId(?string $taxId): static { $this->taxId = $taxId; return $this; } public function getHealthInsuranceCompany(): ?string { return $this->healthInsuranceCompany; } public function setHealthInsuranceCompany(?string $healthInsuranceCompany): static { $this->healthInsuranceCompany = $healthInsuranceCompany; return $this; } public function getStatus(): ?string { return $this->status; } public function setStatus(string $status): static { $this->status = $status; return $this; } public function getRemarks(): ?string { return $this->remarks; } public function setRemarks(?string $remarks): static { $this->remarks = $remarks; return $this; } public function getRemarksInternal(): ?string { return $this->remarksInternal; } public function setRemarksInternal(?string $remarksInternal): static { $this->remarksInternal = $remarksInternal; return $this; } /** * @return Collection */ public function getAvailabilities(): Collection { return $this->availabilities; } public function addAvailability(Availability $availability): static { if (!$this->availabilities->contains($availability)) { $this->availabilities->add($availability); } return $this; } public function removeAvailability(Availability $availability): static { $this->availabilities->removeElement($availability); return $this; } /** * @return Collection */ public function getCustomAvailabilities(): Collection { return $this->customAvailabilities; } public function addCustomAvailability(Availability $customAvailability): static { if (!$this->customAvailabilities->contains($customAvailability)) { $this->customAvailabilities->add($customAvailability); $customAvailability->setOwner($this); } return $this; } public function removeCustomAvailability(Availability $customAvailability): static { if ($this->customAvailabilities->removeElement($customAvailability)) { // set the owning side to null (unless already changed) if ($customAvailability->getOwner() === $this) { $customAvailability->setOwner(null); } } return $this; } public function getAllAvailabilities(): Collection { $allAvailabilities = new ArrayCollection(); foreach ($this->getAvailabilities() as $availability) { $allAvailabilities->add($availability); } foreach ($this->getCustomAvailabilities() as $availability) { $allAvailabilities->add($availability); } return $allAvailabilities; } public function getPhoto(): ?Upload { return $this->photo; } public function setPhoto(?Upload $photo): static { $this->photo = $photo; return $this; } /** * @return Collection */ public function getFeedback(): Collection { return $this->feedback; } public function addFeedback(Feedback $feedback): static { if (!$this->feedback->contains($feedback)) { $this->feedback->add($feedback); $feedback->setTeamer($this); } return $this; } public function removeFeedback(Feedback $feedback): static { if ($this->feedback->removeElement($feedback)) { // set the owning side to null (unless already changed) if ($feedback->getTeamer() === $this) { $feedback->setTeamer(null); } } return $this; } public function getAverageRating(): ?int { $feedbackCount = $this->getFeedback()->count(); if (0 === $feedbackCount) { return null; } $sum = 0; foreach ($this->getFeedback() as $feedback) { $sum += $feedback->getAverageRating(); } return $sum / $feedbackCount; } /** * @return Collection */ public function getTrainingAttendances(): Collection { return $this->trainingAttendances; } public function addTrainingAttendance(TrainingAttendance $trainingAttendance): static { if (!$this->trainingAttendances->contains($trainingAttendance)) { $this->trainingAttendances->add($trainingAttendance); $trainingAttendance->setTeamer($this); } return $this; } public function removeTrainingAttendance(TrainingAttendance $trainingAttendance): static { if ($this->trainingAttendances->removeElement($trainingAttendance)) { // set the owning side to null (unless already changed) if ($trainingAttendance->getTeamer() === $this) { $trainingAttendance->setTeamer(null); } } return $this; } public function getTrainingAttendance(Training $training): ?TrainingAttendance { foreach ($this->getTrainingAttendances() as $attendance) { if ($attendance->getTraining() === $training) { return $attendance; } } return null; } /** * @return Collection */ public function getLicenses(): Collection { return $this->licenses; } public function addLicense(License $license): static { if (!$this->licenses->contains($license)) { $this->licenses->add($license); $license->setTeamer($this); } return $this; } public function removeLicense(License $license): static { if ($this->licenses->removeElement($license)) { // set the owning side to null (unless already changed) if ($license->getTeamer() === $this) { $license->setTeamer(null); } } return $this; } public function getLicenseOfType(string $type): ?License { foreach ($this->getLicenses() as $license) { if ($type === $license->getType()) { return $license; } } return null; } /** * @return Collection */ public function getJobProfiles(): Collection { return $this->jobProfiles; } public function addJobProfile(JobProfile $jobProfile): static { if (!$this->jobProfiles->contains($jobProfile)) { $this->jobProfiles->add($jobProfile); } return $this; } public function removeJobProfile(JobProfile $jobProfile): static { $this->jobProfiles->removeElement($jobProfile); return $this; } /** * @return Collection */ public function getBookmarks(): Collection { return $this->bookmarks; } public function addBookmark(Assignment $bookmark): static { if (!$this->bookmarks->contains($bookmark)) { $this->bookmarks->add($bookmark); } return $this; } public function removeBookmark(Assignment $bookmark): static { $this->bookmarks->removeElement($bookmark); return $this; } /** * @return Collection */ public function getApplications(): Collection { return $this->applications; } public function addApplication(Application $application): static { if (!$this->applications->contains($application)) { $this->applications->add($application); $application->setTeamer($this); } return $this; } public function removeApplication(Application $application): static { if ($this->applications->removeElement($application)) { // set the owning side to null (unless already changed) if ($application->getTeamer() === $this) { $application->setTeamer(null); } } return $this; } /** * @return Collection */ public function getDispositions(): Collection { return $this->dispositions; } public function addDisposition(Disposition $disposition): static { if (!$this->dispositions->contains($disposition)) { $this->dispositions->add($disposition); $disposition->setTeamer($this); } return $this; } public function removeDisposition(Disposition $disposition): static { if ($this->dispositions->removeElement($disposition)) { // set the owning side to null (unless already changed) if ($disposition->getTeamer() === $this) { $disposition->setTeamer(null); } } return $this; } public function getUser(): ?User { return $this->user; } public function setUser(?User $user): static { $this->user = $user; return $this; } public function getPickups(): array { return $this->pickups; } public function setPickups(array $pickups): static { $this->pickups = $pickups; return $this; } public function hasPickup(int $pickupId): bool { return true === in_array($pickupId, $this->getPickups(), true); } public function getDriverLicenseDeclaration(): ?bool { return $this->driverLicenseDeclaration; } public function setDriverLicenseDeclaration(?bool $driverLicenseDeclaration): static { $this->driverLicenseDeclaration = $driverLicenseDeclaration; return $this; } public function isDriverLicenseVerified(): bool { return $this->driverLicenseVerified; } public function setDriverLicenseVerified(bool $driverLicenseVerified): static { $this->driverLicenseVerified = $driverLicenseVerified; return $this; } public function getDriverLicenseStatus(): string { return $this->driverLicenseStatus; } public function setDriverLicenseStatus(string $driverLicenseStatus): static { $this->driverLicenseStatus = $driverLicenseStatus; return $this; } public function getDriverLicenseUpload(): ?Upload { return $this->driverLicenseUpload; } public function setDriverLicenseUpload(?Upload $driverLicenseUpload): static { $this->driverLicenseUpload = $driverLicenseUpload; return $this; } public function getDriverLicenseReviewComment(): ?string { return $this->driverLicenseReviewComment; } public function setDriverLicenseReviewComment(?string $driverLicenseReviewComment): static { $this->driverLicenseReviewComment = $driverLicenseReviewComment; return $this; } public function getDriverLicenseReviewedAt(): ?\DateTimeImmutable { return $this->driverLicenseReviewedAt; } public function setDriverLicenseReviewedAt(?\DateTimeImmutable $driverLicenseReviewedAt): static { $this->driverLicenseReviewedAt = $driverLicenseReviewedAt; return $this; } public function getDriverLicenseReviewedBy(): ?string { return $this->driverLicenseReviewedBy; } public function setDriverLicenseReviewedBy(?string $driverLicenseReviewedBy): static { $this->driverLicenseReviewedBy = $driverLicenseReviewedBy; return $this; } public function getLanguage(): ?string { return $this->language; } public function setLanguage(?string $language): static { $this->language = $language; return $this; } public function getSize(): ?string { return $this->size; } public function setSize(string $size): static { $this->size = $size; return $this; } public function getMealPreference(): ?MealPreference { return $this->mealPreference; } public function setMealPreference(?MealPreference $mealPreference): static { $this->mealPreference = $mealPreference; return $this; } public function getCrmSelections(): ?array { return $this->crmSelections; } public function setCrmSelections(?array $crmSelections): static { $this->crmSelections = $crmSelections; return $this; } public function isViewed(): bool { return $this->viewed; } public function setViewed(bool $viewed): static { $this->viewed = $viewed; return $this; } public function isAllowOverlappingApplications(): bool { return $this->allowOverlappingApplications; } public function setAllowOverlappingApplications(bool $allowOverlappingApplications): static { $this->allowOverlappingApplications = $allowOverlappingApplications; return $this; } public function getDataVerifiedAt(): ?\DateTimeImmutable { return $this->dataVerifiedAt; } public function setDataVerifiedAt(?\DateTimeImmutable $dataVerifiedAt): static { $this->dataVerifiedAt = $dataVerifiedAt; return $this; } }