WIP: Implement availabilities
This commit is contained in:
@@ -5,6 +5,8 @@ namespace App\Entity;
|
||||
use App\Entity\Traits\BlameableEntity;
|
||||
use App\Entity\Traits\TimestampableEntity;
|
||||
use App\Repository\AvailabilityRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
@@ -25,9 +27,17 @@ class Availability implements BlameableEntityInterface, TimestampableEntityInter
|
||||
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
|
||||
private ?\DateTimeImmutable $dateTo = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'availabilities')]
|
||||
#[ORM\ManyToOne(inversedBy: 'customAvailabilities')]
|
||||
private ?Teamer $owner = null;
|
||||
|
||||
#[ORM\ManyToMany(targetEntity: Teamer::class, mappedBy: 'availabilities')]
|
||||
private Collection $teamers;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->teamers = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@@ -68,4 +78,31 @@ class Availability implements BlameableEntityInterface, TimestampableEntityInter
|
||||
|
||||
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);
|
||||
$teamer->addAvailability($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeTeamer(Teamer $teamer): static
|
||||
{
|
||||
if ($this->teamers->removeElement($teamer)) {
|
||||
$teamer->removeAvailability($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
+33
-5
@@ -83,9 +83,12 @@ class Teamer implements TimestampableEntityInterface
|
||||
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
||||
private ?string $remarks = null;
|
||||
|
||||
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Availability::class)]
|
||||
#[ORM\ManyToMany(targetEntity: Availability::class, inversedBy: 'teamers')]
|
||||
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;
|
||||
@@ -136,6 +139,7 @@ class Teamer implements TimestampableEntityInterface
|
||||
$this->bookmarks = new ArrayCollection();
|
||||
$this->applications = new ArrayCollection();
|
||||
$this->dispositions = new ArrayCollection();
|
||||
$this->customAvailabilities = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function toPayload(): array
|
||||
@@ -375,7 +379,6 @@ class Teamer implements TimestampableEntityInterface
|
||||
{
|
||||
if (!$this->availabilities->contains($availability)) {
|
||||
$this->availabilities->add($availability);
|
||||
$availability->setOwner($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -383,10 +386,35 @@ class Teamer implements TimestampableEntityInterface
|
||||
|
||||
public function removeAvailability(Availability $availability): static
|
||||
{
|
||||
if ($this->availabilities->removeElement($availability)) {
|
||||
$this->availabilities->removeElement($availability);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Availability>
|
||||
*/
|
||||
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 ($availability->getOwner() === $this) {
|
||||
$availability->setOwner(null);
|
||||
if ($customAvailability->getOwner() === $this) {
|
||||
$customAvailability->setOwner(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user