From 77c22b13d5d8b2e36f492175599e455a48909253 Mon Sep 17 00:00:00 2001 From: Lung Date: Sat, 18 May 2024 10:08:45 +0200 Subject: [PATCH] added status for endpoint entry list --- src/Entry/EntryParticipant.php | 1 + src/Entry/EntryStatus.php | 10 ++++++++++ src/Participant/ParticipantRepository.php | 5 ++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Entry/EntryParticipant.php b/src/Entry/EntryParticipant.php index 872bd1c4..e86d864f 100644 --- a/src/Entry/EntryParticipant.php +++ b/src/Entry/EntryParticipant.php @@ -17,6 +17,7 @@ public function __construct( readonly public ?string $patrolName, readonly public string $tieCode, readonly public \DateTimeInterface $birthDate, + readonly public EntryStatus $entryStatus, readonly public bool $sfh, ) { } diff --git a/src/Entry/EntryStatus.php b/src/Entry/EntryStatus.php index 3f5ed588..8e88c3f2 100644 --- a/src/Entry/EntryStatus.php +++ b/src/Entry/EntryStatus.php @@ -4,9 +4,19 @@ namespace kissj\Entry; +use DateTimeInterface; + enum EntryStatus: string { case ENTRY_STATUS_VALID = 'valid'; case ENTRY_STATUS_USED = 'used'; case ENTRY_STATUS_INVALID = 'invalid'; + + public static function fromDatetime(?DateTimeInterface $entryDate): self + { + return match ($entryDate) { + null => self::ENTRY_STATUS_VALID, + default => self::ENTRY_STATUS_USED, + }; + } } diff --git a/src/Participant/ParticipantRepository.php b/src/Participant/ParticipantRepository.php index 432dc794..8ef6c27b 100755 --- a/src/Participant/ParticipantRepository.php +++ b/src/Participant/ParticipantRepository.php @@ -7,6 +7,7 @@ use Dibi\Row; use kissj\Application\DateTimeUtils; use kissj\Entry\EntryParticipant; +use kissj\Entry\EntryStatus; use kissj\Event\Event; use kissj\Event\EventType\Cej\EventTypeCej; use kissj\Orm\Order; @@ -392,6 +393,7 @@ private function getRowsForEntryParticipant(Event $event, array $participantRole participant.birth_date, participant.role, participant.patrol_leader_id, + participant.entry_date, d.is_done AS sfh_done ')->from($this->getTable()); @@ -403,7 +405,6 @@ private function getRowsForEntryParticipant(Event $event, array $participantRole $qb->where('u.event_id = %i', $event->id); $qb->where('participant.role IN %in', $participantRoles); - $qb->where('participant.entry_date IS NULL'); $this->addOrdersBy($qb, [new Order('id')]); @@ -422,6 +423,7 @@ private function mapDataToEntryParticipant(Row $row): EntryParticipant * birth_date: \DateTimeInterface|null, * patrol_leader_id: int|null, * sfh_done: bool|null, + * entry_date: \DateTimeInterface|null, * role: string|null * } $array */ $array = $row->toArray(); @@ -434,6 +436,7 @@ private function mapDataToEntryParticipant(Row $row): EntryParticipant $array['patrol_name'] ?? '', $array['tie_code'], $array['birth_date'] ?? DateTimeUtils::getDateTime(), + EntryStatus::fromDatetime($array['entry_date']), $array['sfh_done'] ?? false, ); }