Additional event informations can be added

This commit is contained in:
2026-08-12 15:01:35 +02:00
parent 554166803b
commit 9581176a0c
28 changed files with 675 additions and 39 deletions
@@ -27,6 +27,14 @@ class SignUpCommand {
return $response;
}
// Teilnahmeoptionen (event-spezifische Pflicht-Auswahl) gegen die Event-Definition absichern.
$participationOptionRows = $this->buildParticipationOptionRows();
if ($participationOptionRows === null) {
$response->success = false;
$response->message = 'Bitte alle Auswahlfelder ausfüllen.';
return $response;
}
$eatingHabit = match ($this->request->eating_habit) {
'vegan' => EatingHabit::EATING_HABIT_VEGAN,
'vegetarian' => EatingHabit::EATING_HABIT_VEGETARIAN,
@@ -80,8 +88,68 @@ class SignUpCommand {
]
);
$this->persistParticipationOptions($response->participant, $participationOptionRows);
$response->success = true;
return $response;
}
/**
* Validiert die Antworten gegen die am Event definierten Teilnahmeoptionen und erzeugt die zu speichernden
* Zeilen mit Label-Snapshots. Gibt null zurück, wenn eine Pflicht-Frage unbeantwortet oder eine Antwort
* ungültig ist (Absicherung gegen manipulierte Payloads).
*
* @return array<int, array{question_key: string, question_label: string, value: string, value_label: string}>|null
*/
private function buildParticipationOptionRows(): ?array
{
$rows = [];
foreach ($this->request->event->participation_options ?? [] as $question) {
$key = $question['key'] ?? null;
if ($key === null) {
continue;
}
$value = $this->request->participationOptions[$key] ?? null;
if ($value === null || $value === '') {
return null;
}
$option = null;
foreach ($question['options'] ?? [] as $candidate) {
if (($candidate['value'] ?? null) === $value) {
$option = $candidate;
break;
}
}
if ($option === null) {
return null;
}
$rows[] = [
'question_key' => $key,
'question_label' => $question['label'] ?? $key,
'value' => $value,
'value_label' => $option['label'] ?? $value,
];
}
return $rows;
}
/**
* @param array<int, array{question_key: string, question_label: string, value: string, value_label: string}> $rows
*/
private function persistParticipationOptions(\App\Models\EventParticipant $participant, array $rows): void
{
foreach ($rows as $row) {
$participant->selectedOptions()->create(array_merge($row, [
'tenant' => $this->request->event->tenant,
'event_id' => $this->request->event->id,
]));
}
}
}