Veranstalter am Markt verankern
This commit is contained in:
1 parent
ba36485180
commit
0e71aca89b
10 files changed
+271
-106
No files matched your search
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../../modules/shared/db.php';
|
||||
require_once __DIR__ . '/../../modules/shared/auth/service.php';
|
||||
require_once __DIR__ . '/../../modules/erp/kontakte/service.php';
|
||||
require_once __DIR__ . '/../../modules/market_management/service.php';
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
@@ -40,6 +41,15 @@ if (!is_array($payload)) {
|
||||
|
||||
try {
|
||||
$fields = is_array($payload['fields'] ?? null) ? $payload['fields'] : [];
|
||||
if (($fields['organizer_party_id'] ?? '') === '__new__') {
|
||||
$organizer = create_market_organizer(
|
||||
$pdo,
|
||||
(string) ($fields['organizer_name'] ?? ''),
|
||||
(string) ($fields['organizer_email'] ?? ''),
|
||||
(string) ($fields['organizer_phone'] ?? '')
|
||||
);
|
||||
$fields['organizer_party_id'] = $organizer['id'];
|
||||
}
|
||||
if (($payload['action'] ?? 'create') === 'delete') {
|
||||
$marketId = (int) ($payload['id'] ?? 0);
|
||||
if ($marketId < 1) {
|
||||
@@ -57,12 +67,14 @@ try {
|
||||
$market = market_management_update_market($pdo, $marketId, [
|
||||
'name' => $fields['name'] ?? null,
|
||||
'category_id' => $fields['category_id'] ?? null,
|
||||
'organizer_party_id' => $fields['organizer_party_id'] ?? null,
|
||||
'website_url' => $fields['website_url'] ?? null,
|
||||
]);
|
||||
} else {
|
||||
$market = market_management_create_market($pdo, [
|
||||
'name' => $fields['name'] ?? null,
|
||||
'category_id' => $fields['category_id'] ?? null,
|
||||
'organizer_party_id' => $fields['organizer_party_id'] ?? null,
|
||||
'website_url' => $fields['website_url'] ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -88,6 +88,7 @@ if ($currentUser !== null) {
|
||||
'offset' => 0,
|
||||
]),
|
||||
'categories' => market_management_list_categories($pdo),
|
||||
'organizers' => get_market_organizer_options($pdo),
|
||||
];
|
||||
if ((string) ($_GET['bestellungen_fragment'] ?? '') === '1') {
|
||||
echo auth_render_bestellungen_content($bestellungenTable);
|
||||
|
||||
Reference in new issue
Block a user