Files
myep-team/src/Entity/Assignment.php
T

476 lines
12 KiB
PHP

<?php
namespace App\Entity;
use App\Entity\Traits\BlameableEntity;
use App\Entity\Traits\SoftDeletableEntity;
use App\Entity\Traits\TimestampableEntity;
use App\Repository\AssignmentRepository;
use Carbon\CarbonPeriod;
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: AssignmentRepository::class)]
class Assignment implements BlameableEntityInterface, TimestampableEntityInterface, SoftDeletableEntityInterface
{
use BlameableEntity;
use TimestampableEntity;
use SoftDeletableEntity;
public const STATUS_OPEN = 'open';
public const STATUS_CLOSED = 'closed';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 36, unique: true)]
private string $uuid;
#[ORM\ManyToOne]
#[Assert\NotNull(message: 'Bitte gib die Destination an')]
private ?Destination $destination = null;
#[ORM\ManyToOne]
#[Assert\NotNull(message: 'Bitte gib das Jobprofil an')]
private ?JobProfile $jobProfile = null;
#[ORM\Column(nullable: true)]
#[Assert\Range(min: 1, minMessage: 'Die Mindestanzahl ist 1')]
private ?int $availableDispositions = 1;
#[ORM\Column]
private ?bool $showAvailableDispositions = false;
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
private ?\DateTimeImmutable $dateFrom = null;
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
#[Assert\GreaterThan(propertyPath: 'dateFrom', message: 'Das Enddatum muss nach dem Beginndatum liegen')]
private ?\DateTimeImmutable $dateTo = null;
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
private ?\DateTimeImmutable $pickupDate = null;
#[ORM\Column(nullable: true)]
private ?int $pickup = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $benefits;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $remarks = null;
#[ORM\ManyToMany(targetEntity: Fee::class)]
private Collection $fees;
#[ORM\OneToMany(mappedBy: 'assignment', targetEntity: Application::class)]
private Collection $applications;
#[ORM\OneToMany(mappedBy: 'assignment', targetEntity: Disposition::class)]
private Collection $dispositions;
#[ORM\ManyToOne]
private ?User $contact = null;
#[ORM\ManyToMany(targetEntity: Teamer::class, mappedBy: 'bookmarks')]
private Collection $teamers;
#[ORM\ManyToMany(targetEntity: Upload::class)]
private Collection $documents;
#[ORM\ManyToOne]
private ?User $owner = null;
#[ORM\Column(length: 64)]
private ?string $status;
public function __construct()
{
$this->uuid = Uuid::v4();
$this->status = static::STATUS_OPEN;
$this->fees = new ArrayCollection();
$this->applications = new ArrayCollection();
$this->dispositions = new ArrayCollection();
$this->teamers = new ArrayCollection();
$this->benefits = "Anreise im E&P Reisebus\nUnterkunft\nVerpflegung\nSkipass\n";
$this->documents = new ArrayCollection();
}
public static function duplicate(Assignment $assignment): static
{
$instance = new static();
$instance
->setDestination($assignment->getDestination())
->setJobProfile($assignment->getJobProfile())
->setAvailableDispositions($assignment->getAvailableDispositions())
->setShowAvailableDispositions($assignment->isShowAvailableDispositions())
->setDateFrom($assignment->getDateFrom())
->setDateTo($assignment->getDateTo())
->setPickupDate($assignment->getPickupDate())
->setPickup($assignment->getPickup())
->setBenefits($assignment->getBenefits())
->setContact($assignment->getContact());
$assignment->getFees()->map(function (Fee $fee) use ($instance) {
$instance->addFee($fee);
});
$assignment->getDocuments()->map(function (Upload $document) use ($instance) {
$instance->addDocument($document);
});
return $instance;
}
public function getId(): ?int
{
return $this->id;
}
public function getUuid(): string
{
return $this->uuid;
}
public function getDestination(): ?Destination
{
return $this->destination;
}
public function setDestination(?Destination $destination): static
{
$this->destination = $destination;
return $this;
}
public function getJobProfile(): ?JobProfile
{
return $this->jobProfile;
}
public function setJobProfile(?JobProfile $jobProfile): static
{
$this->jobProfile = $jobProfile;
return $this;
}
public function getAvailableDispositions(): ?int
{
return $this->availableDispositions;
}
public function setAvailableDispositions(?int $availableDispositions): static
{
$this->availableDispositions = $availableDispositions;
return $this;
}
public function isShowAvailableDispositions(): ?bool
{
return $this->showAvailableDispositions;
}
public function setShowAvailableDispositions(bool $showAvailableDispositions): static
{
$this->showAvailableDispositions = $showAvailableDispositions;
return $this;
}
public function getDateFrom(): ?\DateTimeImmutable
{
return $this->dateFrom;
}
public function setDateFrom(?\DateTimeImmutable $dateFrom): static
{
$this->dateFrom = $dateFrom;
return $this;
}
public function getDateTo(): ?\DateTimeImmutable
{
return $this->dateTo;
}
public function setDateTo(?\DateTimeImmutable $dateTo): static
{
$this->dateTo = $dateTo;
return $this;
}
public function getEffectivePeriod(): ?CarbonPeriod
{
if (null !== $destination = $this->getDestination()) {
$dateFrom = $this->getDateFrom() ?? $destination->getDateFrom();
$dateTo = $this->getDateTo() ?? $destination->getDateTo();
return new CarbonPeriod($dateFrom, $dateTo);
}
return null;
}
public function getEffectiveDateFrom(): ?\DateTimeImmutable
{
if (null !== $effectivePeriod = $this->getEffectivePeriod()) {
return $effectivePeriod->start->toDateTimeImmutable();
}
return null;
}
public function getEffectiveDateTo(): ?\DateTimeImmutable
{
if (null !== $effectivePeriod = $this->getEffectivePeriod()) {
return $effectivePeriod->end->toDateTimeImmutable();
}
return null;
}
public function getEffectivePickupDate(): ?\DateTimeImmutable
{
if (null !== $this->pickupDate) {
return $this->pickupDate;
}
if (0 !== (int) $this->pickup && null !== $destination = $this->getDestination()) {
return $destination
->getDateFrom()
->modify('-1 day')
;
}
return null;
}
public function getPickupDate(): ?\DateTimeImmutable
{
return $this->pickupDate;
}
public function setPickupDate(?\DateTimeImmutable $pickupDate): static
{
$this->pickupDate = $pickupDate;
return $this;
}
public function getPickup(): ?int
{
return $this->pickup;
}
public function setPickup(null|int|string $pickup): static
{
$this->pickup = (int) $pickup;
return $this;
}
public function getBenefits(): ?string
{
return $this->benefits;
}
public function setBenefits(?string $benefits): static
{
$this->benefits = $benefits;
return $this;
}
public function getRemarks(): ?string
{
return $this->remarks;
}
public function setRemarks(?string $remarks): static
{
$this->remarks = $remarks;
return $this;
}
/**
* @return Collection<int, Fee>
*/
public function getFees(): Collection
{
return $this->fees;
}
public function addFee(Fee $fee): static
{
if (!$this->fees->contains($fee)) {
$this->fees->add($fee);
}
return $this;
}
public function removeFee(Fee $fee): static
{
$this->fees->removeElement($fee);
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->setAssignment($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->getAssignment() === $this) {
$application->setAssignment(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->setAssignment($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->getAssignment() === $this) {
$disposition->setAssignment(null);
}
}
return $this;
}
public function getContact(): ?User
{
return $this->contact;
}
public function setContact(?User $contact): static
{
$this->contact = $contact;
return $this;
}
/**
* @return Collection<int, Teamer>
*/
public function getTeamers(): Collection
{
return $this->teamers;
}
public function addTeamer(Teamer $teamer): static
{
if (!$this->teamers->contains($teamer)) {
$this->teamers->add($teamer);
}
return $this;
}
public function removeTeamer(Teamer $teamer): static
{
$this->teamers->removeElement($teamer);
return $this;
}
/**
* @return Collection<int, Upload>
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(Upload $document): static
{
if (!$this->documents->contains($document)) {
$this->documents->add($document);
}
return $this;
}
public function removeDocument(Upload $document): static
{
$this->documents->removeElement($document);
return $this;
}
public function getOwner(): ?User
{
return $this->owner;
}
public function setOwner(?User $owner): static
{
$this->owner = $owner;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): static
{
$this->status = $status;
return $this;
}
}