This commit is contained in:
@@ -8,6 +8,7 @@ use App\Avatar\Lorelei;
|
||||
|
||||
final class AccountPages
|
||||
{
|
||||
private const EVENT_DRAFT_SESSION_KEY = 'dashboard_event_draft';
|
||||
private const ENCRYPTED_PROFILE_FIELDS = [
|
||||
'first_name',
|
||||
'last_name',
|
||||
@@ -199,7 +200,14 @@ final class AccountPages
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$action = $_POST['action'] ?? '';
|
||||
try {
|
||||
if ($action === 'profile') {
|
||||
if ($action === 'event_draft_store') {
|
||||
$targetKind = (string)($_POST['target_kind'] ?? '');
|
||||
if (!in_array($targetKind, ['place', 'editorial_event'], true)) {
|
||||
throw new \RuntimeException('Ungültiger Zieltyp für den Zwischenschritt.');
|
||||
}
|
||||
self::storeEventDraftInSession($_POST);
|
||||
redirect('/dashboard?section=places&create_listing=' . rawurlencode($targetKind) . '#places');
|
||||
} elseif ($action === 'profile') {
|
||||
$crypto = self::requireCrypto($crypto, 'Profil');
|
||||
$email = trim((string)($_POST['email'] ?? ''));
|
||||
$languages = $_POST['languages'] ?? '';
|
||||
@@ -441,8 +449,13 @@ final class AccountPages
|
||||
);
|
||||
$info = $entryKind === 'place' ? 'Änderungsanfrage für den Ort eingereicht.' : 'Änderungsanfrage für die Veranstaltung eingereicht.';
|
||||
} else {
|
||||
$listingCatalog->submitCreateSuggestion($userId, $payload);
|
||||
$createdListingId = $listingCatalog->submitCreateSuggestion($userId, $payload);
|
||||
$info = $entryKind === 'place' ? 'Ort zur Freigabe eingereicht.' : 'Veranstaltung zur Freigabe eingereicht.';
|
||||
if (self::hasStoredEventDraft()) {
|
||||
self::attachListingToStoredEventDraft($entryKind, $createdListingId);
|
||||
$app->flash()->set('info', $info);
|
||||
redirect('/dashboard?section=events&restore_event_draft=1#events');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$existingEvent = null;
|
||||
@@ -547,6 +560,7 @@ final class AccountPages
|
||||
'status' => 'published',
|
||||
]);
|
||||
$info = 'Event gespeichert.';
|
||||
self::clearStoredEventDraft();
|
||||
try {
|
||||
$cfgPath = dirname(__DIR__, 2) . '/config/community.php';
|
||||
$communityCfg = file_exists($cfgPath) ? require $cfgPath : [];
|
||||
@@ -580,6 +594,7 @@ final class AccountPages
|
||||
'vis' => $_POST['visibility'] ?? 'public',
|
||||
]);
|
||||
$info = 'Event aktualisiert.';
|
||||
self::clearStoredEventDraft();
|
||||
}
|
||||
}
|
||||
} elseif ($action === 'event_delete') {
|
||||
@@ -743,6 +758,8 @@ final class AccountPages
|
||||
$userSubmittedListings = [];
|
||||
$listingRequestMap = [];
|
||||
$editListing = null;
|
||||
$restoreEventDraftActive = $section === 'events' && ((string)($_GET['restore_event_draft'] ?? '')) === '1' && self::hasStoredEventDraft();
|
||||
$restoredEventDraft = $restoreEventDraftActive ? self::getStoredEventDraft() : null;
|
||||
$listingCategories = $listingCatalog ? $listingCatalog->listCategories(['general', 'place', 'food', 'event', 'family']) : [];
|
||||
$categoryReviewItems = $listingCatalog && $canManageSystemSettings ? $listingCatalog->listCategoryReviewItems() : [];
|
||||
$placeSuggestions = $listingCatalog ? $listingCatalog->listPlaceSuggestions(60) : [];
|
||||
@@ -863,6 +880,8 @@ final class AccountPages
|
||||
'directoryListings',
|
||||
'userSubmittedListings',
|
||||
'listingRequestMap',
|
||||
'restoreEventDraftActive',
|
||||
'restoredEventDraft',
|
||||
'editListing',
|
||||
'listingCategories',
|
||||
'categoryReviewItems',
|
||||
@@ -1163,4 +1182,67 @@ final class AccountPages
|
||||
$resp = @file_get_contents($url, false, $ctx);
|
||||
return $resp === false ? null : $resp;
|
||||
}
|
||||
|
||||
private static function storeEventDraftInSession(array $source): void
|
||||
{
|
||||
$_SESSION[self::EVENT_DRAFT_SESSION_KEY] = self::normalizeEventDraft($source);
|
||||
}
|
||||
|
||||
private static function getStoredEventDraft(): ?array
|
||||
{
|
||||
$draft = $_SESSION[self::EVENT_DRAFT_SESSION_KEY] ?? null;
|
||||
return is_array($draft) ? $draft : null;
|
||||
}
|
||||
|
||||
private static function hasStoredEventDraft(): bool
|
||||
{
|
||||
return is_array($_SESSION[self::EVENT_DRAFT_SESSION_KEY] ?? null);
|
||||
}
|
||||
|
||||
private static function clearStoredEventDraft(): void
|
||||
{
|
||||
unset($_SESSION[self::EVENT_DRAFT_SESSION_KEY]);
|
||||
}
|
||||
|
||||
private static function attachListingToStoredEventDraft(string $listingType, int $listingId): void
|
||||
{
|
||||
$draft = self::getStoredEventDraft();
|
||||
if (!is_array($draft) || $listingId <= 0 || !in_array($listingType, ['place', 'editorial_event'], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$draft['event_location_mode'] = $listingType;
|
||||
$draft['event_location_source_id'] = (string)$listingId;
|
||||
$draft['street'] = '';
|
||||
$draft['zip'] = '';
|
||||
$draft['city'] = '';
|
||||
$draft['region'] = '';
|
||||
$draft['lat'] = '';
|
||||
$draft['lng'] = '';
|
||||
$draft['category_input'] = '';
|
||||
$draft['category_slug'] = '';
|
||||
$_SESSION[self::EVENT_DRAFT_SESSION_KEY] = $draft;
|
||||
}
|
||||
|
||||
private static function normalizeEventDraft(array $source): array
|
||||
{
|
||||
return [
|
||||
'title' => trim((string)($source['title'] ?? '')),
|
||||
'description' => trim((string)($source['description'] ?? '')),
|
||||
'starts_at' => trim((string)($source['starts_at'] ?? '')),
|
||||
'with_children' => ((string)($source['with_children'] ?? 'yes')) === 'no' ? 'no' : 'yes',
|
||||
'max_participants' => trim((string)($source['max_participants'] ?? '')),
|
||||
'visibility' => in_array((string)($source['visibility'] ?? 'public'), ['public', 'members'], true) ? (string)$source['visibility'] : 'public',
|
||||
'event_location_mode' => in_array((string)($source['event_location_mode'] ?? 'custom'), ['custom', 'place', 'editorial_event'], true) ? (string)$source['event_location_mode'] : 'custom',
|
||||
'event_location_source_id' => trim((string)($source['event_location_source_id'] ?? '')),
|
||||
'street' => trim((string)($source['street'] ?? '')),
|
||||
'zip' => trim((string)($source['zip'] ?? '')),
|
||||
'city' => trim((string)($source['city'] ?? '')),
|
||||
'region' => trim((string)($source['region'] ?? '')),
|
||||
'lat' => trim((string)($source['lat'] ?? '')),
|
||||
'lng' => trim((string)($source['lng'] ?? '')),
|
||||
'category_input' => trim((string)($source['category_input'] ?? '')),
|
||||
'category_slug' => trim((string)($source['category_slug'] ?? '')),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user