Handling of event addons
This commit is contained in:
@@ -72,11 +72,97 @@ class UpdateParticipantCommand {
|
||||
|
||||
|
||||
$p->save();
|
||||
|
||||
if ($this->request->participationOptions !== null) {
|
||||
$this->syncParticipationOptions($p);
|
||||
}
|
||||
|
||||
if ($this->request->selectedAddons !== null) {
|
||||
$this->syncAddons($p);
|
||||
}
|
||||
|
||||
$this->response->success = true;
|
||||
$this->response->participant = $p;
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ersetzt die zugeordneten Zusätze (Event-Addons) anhand der Auswahl. Bewusst **ohne Preis/Betrag**
|
||||
* (amount 0): der Teilnahmebeitrag wird in den Details ohnehin manuell gesetzt. Es wird nur der Titel als
|
||||
* Snapshot gespeichert, damit die Zuordnung sichtbar bleibt.
|
||||
*/
|
||||
private function syncAddons(EventParticipant $participant): void
|
||||
{
|
||||
$participant->selectedAddons()->delete();
|
||||
|
||||
$selection = $this->request->selectedAddons ?? [];
|
||||
|
||||
foreach ($participant->event?->addons ?? [] as $addon) {
|
||||
$key = $addon['key'] ?? null;
|
||||
if ($key === null || empty($selection[$key])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$participant->selectedAddons()->create([
|
||||
'tenant' => $participant->tenant,
|
||||
'event_id' => $participant->event_id,
|
||||
'addon_key' => $key,
|
||||
'title' => $addon['title'] ?? $key,
|
||||
'price' => 0,
|
||||
'flat' => (bool)($addon['flat'] ?? false),
|
||||
'days' => 0,
|
||||
'amount' => 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
Reference in New Issue
Block a user