country = request()->route('country', config('app.domain_country')); $timezone = auth()->user()->timezone ?? 'Europe/Berlin'; if ($this->event) { $localFrom = $this->event->from->setTimezone($timezone); $localTo = $this->event->to->setTimezone($timezone); $this->fromDate = $localFrom->format('Y-m-d'); $this->fromTime = $localFrom->format('H:i'); $this->toDate = $localTo->format('Y-m-d'); $this->toTime = $localTo->format('H:i'); $this->venue_id = $this->event->venue_id; $this->link = $this->event->link; } else { // Set default start time to next Monday at 09:00 in user's timezone $nextMonday = now($timezone)->next('Monday')->setTime(9, 0); $this->fromDate = $nextMonday->format('Y-m-d'); $this->fromTime = $nextMonday->format('H:i'); $this->toDate = $nextMonday->format('Y-m-d'); $this->toTime = $nextMonday->copy()->addHours(3)->format('H:i'); } } public function save(): void { $this->validate([ 'fromDate' => 'required|date', 'fromTime' => 'required', 'toDate' => 'required|date|after_or_equal:fromDate', 'toTime' => 'required', 'venue_id' => 'required|exists:venues,id', 'link' => 'required|url|max:255', ]); $timezone = auth()->user()->timezone ?? 'Europe/Berlin'; // Combine date and time in user's timezone, then convert to UTC $localFrom = \Carbon\Carbon::createFromFormat('Y-m-d H:i', $this->fromDate . ' ' . $this->fromTime, $timezone); $utcFrom = $localFrom->setTimezone('UTC'); $localTo = \Carbon\Carbon::createFromFormat('Y-m-d H:i', $this->toDate . ' ' . $this->toTime, $timezone); $utcTo = $localTo->setTimezone('UTC'); // Additional validation: to must be after from if ($utcTo->lte($utcFrom)) { $this->addError('toTime', __('Die Endzeit muss nach der Startzeit liegen.')); return; } $data = [ 'from' => $utcFrom, 'to' => $utcTo, 'venue_id' => $this->venue_id, 'link' => $this->link, ]; if ($this->event) { // Update existing event $this->event->update($data); session()->flash('status', __('Event erfolgreich aktualisiert!')); } else { // Create new event $this->course->courseEvents()->create([ ...$data, 'created_by' => auth()->id(), ]); session()->flash('status', __('Event erfolgreich erstellt!')); } $this->redirect(route('courses.landingpage', ['course' => $this->course, 'country' => $this->country]), navigate: true); } public function delete(): void { if ($this->event) { $this->event->delete(); session()->flash('status', __('Event erfolgreich gelöscht!')); $this->redirect(route('courses.landingpage', ['course' => $this->course, 'country' => $this->country]), navigate: true); } } public function createVenue(): void { $validated = $this->validate([ 'newVenueName' => ['required', 'string', 'max:255', 'unique:venues,name'], 'newVenueCityId' => ['required', 'exists:cities,id'], 'newVenueStreet' => ['required', 'string', 'max:255'], ]); $venue = Venue::create([ 'name' => $validated['newVenueName'], 'city_id' => $validated['newVenueCityId'], 'street' => $validated['newVenueStreet'], 'slug' => str($validated['newVenueName'])->slug(), 'created_by' => auth()->id(), ]); $this->venue_id = $venue->id; $this->reset(['newVenueName', 'newVenueCityId', 'newVenueStreet']); \Flux\Flux::modal('add-venue')->close(); } public function with(): array { return [ 'venues' => Venue::query() ->with([ 'city', ]) ->orderBy('name') ->get(), 'cities' => City::query() ->with([ 'country', ]) ->orderBy('name') ->get(), ]; } }; ?>
{{ $event ? __('Event bearbeiten') : __('Neues Event erstellen') }}: {{ $course->name }}
{{ __('Event Details') }}
{{ __('Startdatum') }} * {{ __('An welchem Tag beginnt das Event?') }} {{ __('Startzeit') }} * {{ __('Um wie viel Uhr beginnt das Event?') }} ({{ auth()->user()->timezone ?? 'Europe/Berlin' }})
{{ __('Enddatum') }} * {{ __('An welchem Tag endet das Event?') }} {{ __('Endzeit') }} * {{ __('Um wie viel Uhr endet das Event?') }} ({{ auth()->user()->timezone ?? 'Europe/Berlin' }})
{{ __('Veranstaltungsort') }} * {{ __('Ort hinzufügen') }}
@foreach($venues as $venue) {{ $venue->name }} @if($venue->city) - {{ $venue->city->name }} @endif @endforeach {{ __('Wo findet das Event statt?') }}
{{ __('Link') }} * {{ __('Link zu weiteren Informationen oder zur Anmeldung') }}
{{ __('Abbrechen') }} @if($event) {{ __('Event löschen') }} @endif
@if (session('status')) {{ session('status') }} @endif {{ $event ? __('Event aktualisieren') : __('Event erstellen') }}
{{ __('Veranstaltungsort hinzufügen') }} {{ __('Füge einen neuen Veranstaltungsort zur Datenbank hinzu.') }}
{{ __('Name') }} * {{ __('Stadt') }} * @foreach($cities as $city) {{ $city->name }} ({{ $city->country->name }}) @endforeach {{ __('Straße') }} *
{{ __('Abbrechen') }} {{ __('Ort erstellen') }}