From de08885e0b6502313b8c7ed76a0e5bd829444e61 Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Tue, 17 Dec 2024 12:02:01 -0500 Subject: [PATCH] Add notes and present members collections Add time calculation and getHoursRemaining helper variable and method --- src/Entity/Referral.php | 99 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/src/Entity/Referral.php b/src/Entity/Referral.php index bdc3cbe..74a7bce 100644 --- a/src/Entity/Referral.php +++ b/src/Entity/Referral.php @@ -5,6 +5,8 @@ namespace App\Entity; use App\Enums\DischargeReason; use App\Enums\ReferralServiceType; use App\Repository\ReferralRepository; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Types\UuidType; @@ -41,6 +43,32 @@ class Referral #[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)] private ?\DateTimeInterface $dischargeDate = null; + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: Note::class, mappedBy: 'referral', orphanRemoval: true)] + private Collection $notes; + + /** + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: Member::class)] + private Collection $present; + + /** + * @var float $hoursUsed + */ + private float $hoursUsed = 0.0; + + /** + * Constructor + */ + public function __construct() + { + $this->notes = new ArrayCollection(); + $this->present = new ArrayCollection(); + } + public function getId(): ?Uuid { return $this->id; @@ -129,4 +157,75 @@ class Referral return $this; } + + /** + * @return Collection + */ + public function getNotes(): Collection + { + return $this->notes; + } + + public function addNote(Note $note): static + { + if (!$this->notes->contains($note)) { + $this->notes->add($note); + $note->setReferral($this); + $this->hoursUsed += ($note->calcTimeUsed() / 60); + } + + return $this; + } + + public function removeNote(Note $note): static + { + if ($this->notes->removeElement($note)) { + $this->hoursUsed -= $note->calcTimeUsed(); + // set the owning side to null (unless already changed) + if ($note->getReferral() === $this) { + $note->setReferral(null); + } + } + + return $this; + } + + public function setNotes(ArrayCollection $notes): void + { + $this->notes = $notes; + $this->hoursUsed = 0.0; + + foreach($this->notes as $note) { + $this->hoursUsed += ($note->calcTimeUsed() / 60); + } + } + + /** + * @return Collection + */ + public function getPresent(): Collection + { + return $this->present; + } + + public function addPresent(Member $present): static + { + if (!$this->present->contains($present)) { + $this->present->add($present); + } + + return $this; + } + + public function removePresent(Member $present): static + { + $this->present->removeElement($present); + + return $this; + } + + public function getHoursRemaining(): float + { + return $this->hours - $this->hoursUsed; + } }