feat: refactor staffing status assignment and filtering

This commit is contained in:
Björn Fromme
2024-07-16 17:34:50 +02:00
parent fa9c68c463
commit 5dd2f79c2d
14 changed files with 128 additions and 52 deletions
+30 -19
View File
@@ -95,10 +95,14 @@ class Assignment implements BlameableEntityInterface, TimestampableEntityInterfa
#[ORM\Column(length: 64)]
private ?string $status;
#[ORM\Column(length: 64)]
private ?string $staffingStatus;
public function __construct()
{
$this->uuid = Uuid::v4();
$this->status = static::STATUS_DRAFT;
$this->staffingStatus = static::STATUS_UNSTAFFED;
$this->fees = new ArrayCollection();
$this->applications = new ArrayCollection();
$this->dispositions = new ArrayCollection();
@@ -129,6 +133,27 @@ class Assignment implements BlameableEntityInterface, TimestampableEntityInterfa
return $instance;
}
public function updateStaffingStatus(): void
{
$confirmedDispositions = $this->getConfirmedDispositions();
if ($this->availableDispositions === $confirmedDispositions->count()) {
$this->setStaffingStatus(Assignment::STATUS_STAFFED);
} elseif (
$this->availableDispositions > $confirmedDispositions->count()
&& 0 < $confirmedDispositions->count()
) {
$this->setStaffingStatus(Assignment::STATUS_PARTLY_STAFFED);
} elseif (
$this->availableDispositions > $this->dispositions->count()
&& 0 < $this->applications->count()
) {
$this->setStaffingStatus(Assignment::STATUS_STAFFING);
} else {
$this->setStaffingStatus(Assignment::STATUS_UNSTAFFED);
}
}
public function getId(): ?int
{
return $this->id;
@@ -488,29 +513,15 @@ class Assignment implements BlameableEntityInterface, TimestampableEntityInterfa
return $this;
}
public function isStaffed(): bool
public function getStaffingStatus(): ?string
{
$confirmedDispositions = $this->getConfirmedDispositions();
return $this->availableDispositions === $confirmedDispositions->count();
return $this->staffingStatus;
}
public function isUnstaffed(): bool
public function setStaffingStatus(?string $staffingStatus): static
{
return 0 === $this->dispositions->count();
}
$this->staffingStatus = $staffingStatus;
public function isPartlyStaffed(): bool
{
$confirmedDispositions = $this->getConfirmedDispositions();
return $this->availableDispositions > $confirmedDispositions->count()
&& 0 < $confirmedDispositions->count();
}
public function isStaffing(): bool
{
return $this->availableDispositions > $this->dispositions->count()
&& 0 < $this->applications->count();
return $this;
}
}