Veranstalter am Markt verankern
This commit is contained in:
1 parent
ba36485180
commit
0e71aca89b
10 files changed
+271
-106
No files matched your search
@@ -67,43 +67,19 @@ if ($requestMethod === 'POST') {
|
||||
market_management_update_day($pdo, $id, $fields);
|
||||
} elseif (in_array($scope, ['occurrence', 'status', 'overview', 'participation', 'infrastructure', 'travel', 'notes'], true)) {
|
||||
$contactFields = [];
|
||||
foreach (['contact_email', 'contact_phone'] as $contactField) {
|
||||
foreach (['contact_person_name', 'contact_email', 'contact_phone'] as $contactField) {
|
||||
if (array_key_exists($contactField, $fields)) {
|
||||
$contactFields[substr($contactField, 8)] = $fields[$contactField];
|
||||
$contactFields[$contactField] = $fields[$contactField];
|
||||
unset($fields[$contactField]);
|
||||
}
|
||||
}
|
||||
$existingOccurrence = null;
|
||||
if ($contactFields !== [] || array_key_exists('organization_contact_id', $fields) || array_key_exists('contact_person_id', $fields)) {
|
||||
if ($contactFields !== []) {
|
||||
$existingOccurrence = market_management_get_occurrence($pdo, $id, true);
|
||||
}
|
||||
if ($contactFields !== []) {
|
||||
$submittedContactId = trim((string) ($fields['contact_person_id'] ?? ''));
|
||||
$contactId = (int) ($submittedContactId !== '' ? $submittedContactId : ($existingOccurrence['contact_person_id'] ?? 0));
|
||||
$hasContactValue = array_reduce($contactFields, static fn (bool $carry, mixed $value): bool => $carry || trim((string) $value) !== '', false);
|
||||
if ($contactId > 0 && ($hasContactValue || $submittedContactId !== '')) {
|
||||
update_contact_details($pdo, $contactId, $contactFields);
|
||||
} elseif ($hasContactValue) {
|
||||
throw new InvalidArgumentException('Für E-Mail oder Telefon muss eine Kontaktperson ausgewählt sein.');
|
||||
}
|
||||
}
|
||||
$organizerFields = [];
|
||||
foreach (['organization_contact_id', 'contact_person_id'] as $organizerField) {
|
||||
if (array_key_exists($organizerField, $fields)) {
|
||||
$value = trim((string) $fields[$organizerField]);
|
||||
if ($value !== '') {
|
||||
$organizerFields[$organizerField] = $value;
|
||||
}
|
||||
unset($fields[$organizerField]);
|
||||
}
|
||||
}
|
||||
if ($organizerFields !== []) {
|
||||
$existingOccurrence ??= market_management_get_occurrence($pdo, $id, true);
|
||||
$existingOrganizer = $existingOccurrence['organizer'] ?? null;
|
||||
$organizerFields['occurrence_id'] = $id;
|
||||
$organizerFields['organization_contact_id'] ??= $existingOrganizer['organization_contact_id'] ?? null;
|
||||
$organizerFields['contact_person_id'] ??= $existingOrganizer['contact_person_id'] ?? null;
|
||||
market_management_set_organizer($pdo, $organizerFields);
|
||||
$contactFields['occurrence_id'] = $id;
|
||||
market_management_set_occurrence_contact($pdo, $contactFields);
|
||||
}
|
||||
if ($fields !== []) {
|
||||
market_management_update_occurrence($pdo, $id, $fields);
|
||||
|
||||
Reference in new issue
Block a user