603 lines
15 KiB
PHP
603 lines
15 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\BusProNet\Model\ProfileResponse;
|
|
use App\Entity\Embeddable\Address;
|
|
use App\Entity\Embeddable\BankAccount;
|
|
use App\Entity\Embeddable\Communication;
|
|
use App\Entity\Traits\TimestampableEntity;
|
|
use App\Repository\TeamerRepository;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Uid\Uuid;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
#[ORM\Entity(repositoryClass: TeamerRepository::class)]
|
|
class Teamer implements TimestampableEntityInterface
|
|
{
|
|
use TimestampableEntity;
|
|
|
|
public const STATUS_NEW = 'new';
|
|
public const STATUS_EXISTING = 'existing';
|
|
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(type: 'string', length: 36, unique: true)]
|
|
private string $uuid;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
#[Assert\NotBlank(message: 'Bitte angeben')]
|
|
private ?string $firstName = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
#[Assert\NotBlank(message: 'Bitte angeben')]
|
|
private ?string $lastName = null;
|
|
|
|
#[ORM\Column(length: 1)]
|
|
#[Assert\NotBlank(message: 'Bitte angeben')]
|
|
private ?string $gender = null;
|
|
|
|
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
|
|
#[Assert\NotNull(message: 'Bitte angeben')]
|
|
private ?\DateTimeImmutable $dateOfBirth = null;
|
|
|
|
#[ORM\Column(length: 255, nullable: true)]
|
|
private ?string $academicTitle = null;
|
|
|
|
#[ORM\Column(length: 255, nullable: true)]
|
|
private ?string $salutation = null;
|
|
|
|
#[ORM\Column(length: 255, nullable: true)]
|
|
#[Assert\NotBlank(message: 'Bitte angeben')]
|
|
private ?string $nationality = null;
|
|
|
|
#[ORM\Embedded(class: Address::class)]
|
|
#[Assert\Valid()]
|
|
private ?Address $address = null;
|
|
|
|
#[ORM\Embedded(class: Communication::class)]
|
|
#[Assert\Valid()]
|
|
private ?Communication $communication = null;
|
|
|
|
#[ORM\Embedded(class: BankAccount::class)]
|
|
#[Assert\Valid()]
|
|
private ?BankAccount $bankAccount = null;
|
|
|
|
#[ORM\Column(length: 255, nullable: true)]
|
|
#[Assert\NotBlank(message: 'Bitte angeben')]
|
|
private ?string $taxId = null;
|
|
|
|
#[ORM\Column(length: 255, nullable: true)]
|
|
#[Assert\NotBlank(message: 'Bitte angeben')]
|
|
private ?string $healthInsuranceCompany = null;
|
|
|
|
#[ORM\Column(length: 32)]
|
|
private ?string $status;
|
|
|
|
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
|
private ?string $remarks = null;
|
|
|
|
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Availability::class)]
|
|
private Collection $availabilities;
|
|
|
|
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
|
|
private ?Upload $photo = null;
|
|
|
|
#[ORM\OneToMany(mappedBy: 'teamer', targetEntity: Feedback::class)]
|
|
private Collection $feedback;
|
|
|
|
#[ORM\OneToMany(mappedBy: 'teamer', targetEntity: TrainingAttendance::class)]
|
|
private Collection $trainingAttendances;
|
|
|
|
#[ORM\OneToMany(mappedBy: 'teamer', targetEntity: License::class)]
|
|
private Collection $licenses;
|
|
|
|
#[ORM\ManyToMany(targetEntity: JobProfile::class)]
|
|
private Collection $jobProfiles;
|
|
|
|
#[ORM\ManyToMany(targetEntity: Assignment::class)]
|
|
private Collection $bookmarks;
|
|
|
|
#[ORM\OneToMany(mappedBy: 'teamer', targetEntity: Application::class)]
|
|
private Collection $applications;
|
|
|
|
#[ORM\OneToMany(mappedBy: 'teamer', targetEntity: Disposition::class)]
|
|
private Collection $dispositions;
|
|
|
|
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();
|
|
}
|
|
|
|
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 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 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;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Availability>
|
|
*/
|
|
public function getAvailabilities(): Collection
|
|
{
|
|
return $this->availabilities;
|
|
}
|
|
|
|
public function addAvailability(Availability $availability): static
|
|
{
|
|
if (!$this->availabilities->contains($availability)) {
|
|
$this->availabilities->add($availability);
|
|
$availability->setOwner($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeAvailability(Availability $availability): static
|
|
{
|
|
if ($this->availabilities->removeElement($availability)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($availability->getOwner() === $this) {
|
|
$availability->setOwner(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPhoto(): ?Upload
|
|
{
|
|
return $this->photo;
|
|
}
|
|
|
|
public function setPhoto(?Upload $photo): static
|
|
{
|
|
$this->photo = $photo;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Feedback>
|
|
*/
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, TrainingAttendance>
|
|
*/
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, License>
|
|
*/
|
|
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 hasLicenseOfType(string $type): bool
|
|
{
|
|
foreach ($this->getLicenses() as $license) {
|
|
if ($type === $license->getType()) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, JobProfile>
|
|
*/
|
|
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<int, Assignment>
|
|
*/
|
|
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<int, Application>
|
|
*/
|
|
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<int, Disposition>
|
|
*/
|
|
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;
|
|
}
|
|
}
|