Implemented additional event information

This commit is contained in:
2026-08-12 15:54:00 +02:00
parent 9581176a0c
commit e95de52768
16 changed files with 327 additions and 22 deletions
@@ -27,7 +27,7 @@ class SetParticipationOptionsCommand
* Geltungsbereichs eindeutig, damit Antworten robust referenzieren können.
*
* @param array<int, array<string, mixed>> $questions
* @return array<int, array{key: string, label: string, options: array<int, array{value: string, label: string}>}>
* @return array<int, array{key: string, title: string, label: string, options: array<int, array{value: string, label: string}>}>
*/
private function normalize(array $questions): array
{
@@ -35,21 +35,25 @@ class SetParticipationOptionsCommand
$usedKeys = [];
foreach ($questions as $question) {
$label = trim((string)($question['label'] ?? ''));
if ($label === '') {
// Titel ist Pflicht (Überschrift/Feldbeschriftung); die Frage ist optionaler Erklärtext.
$title = trim((string)($question['title'] ?? ''));
if ($title === '') {
continue;
}
$label = trim((string)($question['label'] ?? ''));
$options = $this->normalizeOptions($question['options'] ?? []);
if ($options === []) {
continue;
}
$key = $this->uniqueSlug((string)($question['key'] ?? ''), $label, $usedKeys);
$key = $this->uniqueSlug((string)($question['key'] ?? ''), $title, $usedKeys);
$usedKeys[] = $key;
$normalized[] = [
'key' => $key,
'title' => $title,
'label' => $label,
'options' => $options,
];
@@ -72,11 +72,63 @@ class UpdateParticipantCommand {
$p->save();
if ($this->request->participationOptions !== null) {
$this->syncParticipationOptions($p);
}
$this->response->success = true;
$this->response->participant = $p;
return $this->response;
}
/**
* Ersetzt die zugeordneten Teilnahmeoptionen anhand der übergebenen Antworten. Nachträgliche Zuordnung im
* Back-Office ist lückenlos möglich: nur gegen die Event-Definition gültige Antworten werden gespeichert,
* leere/entfallene Antworten werden abgeräumt. Frage-/Options-Label werden als Snapshot mitgeschrieben.
*/
private function syncParticipationOptions(EventParticipant $participant): void
{
$participant->selectedOptions()->delete();
$answers = $this->request->participationOptions ?? [];
foreach ($participant->event?->participation_options ?? [] as $question) {
$key = $question['key'] ?? null;
if ($key === null) {
continue;
}
$value = $answers[$key] ?? null;
if ($value === null || $value === '') {
continue;
}
$option = null;
foreach ($question['options'] ?? [] as $candidate) {
if (($candidate['value'] ?? null) === $value) {
$option = $candidate;
break;
}
}
if ($option === null) {
continue;
}
$label = trim((string)($question['label'] ?? ''));
$participant->selectedOptions()->create([
'tenant' => $participant->tenant,
'event_id' => $participant->event_id,
'question_key' => $key,
'question_label' => $label !== '' ? $label : ($question['title'] ?? $key),
'value' => $value,
'value_label' => $option['label'] ?? $value,
]);
}
}
private function handleAmountChanges(EventParticipant $participant) {
$this->response->amountPaid = $participant->amount_paid;
$this->response->amountExpected = $participant->amount;
@@ -36,5 +36,7 @@ class UpdateParticipantRequest {
public string $amountPaid,
public string $amountExpected,
public string $cocStatus,
/** Antworten auf die Teilnahmeoptionen: [ question_key => value ]. null = unverändert lassen. */
public ?array $participationOptions = null,
) {}
}