Skip to content

Commit

Permalink
added status for endpoint entry list
Browse files Browse the repository at this point in the history
  • Loading branch information
Lung committed May 18, 2024
1 parent d746be2 commit 77c22b1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Entry/EntryParticipant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}
Expand Down
10 changes: 10 additions & 0 deletions src/Entry/EntryStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
}
5 changes: 4 additions & 1 deletion src/Participant/ParticipantRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());

Expand All @@ -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')]);

Expand All @@ -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();
Expand All @@ -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,
);
}
Expand Down

0 comments on commit 77c22b1

Please sign in to comment.