Termine im Portal bearbeiten (0.23.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m53s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m42s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m13s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m10s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m46s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m35s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m54s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m53s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m10s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-27 07:56:48 +00:00
parent 80a0f20447
commit d7d09d6b9a
142 changed files with 917 additions and 315 deletions

View file

@ -3,6 +3,7 @@
namespace Inhaus\Plugins\Events;
use App\Dashboard\Widgets;
use App\Editorial\Editorial;
use App\Media\ImagePaths;
use App\Media\MediaUsages;
use App\Models\User;
@ -36,6 +37,24 @@ class EventsPlugin extends Plugin
], fn (callable $each) => Event::query()->chunkById(100, fn ($events) => $events->each($each)));
$usages->watch('events', Event::class, ['image_path', 'description_html', 'title', 'is_published']);
// Redaktion im Portal
$this->app->make(Editorial::class)->add('events', 'Termine', 'events::EditorialEvents', 30,
fn (User $user) => $user->can('events.manage'),
fn (User $user) => [
'events' => Event::query()->where(fn ($q) => $q->where('starts_at', '>=', now()->subDays(30))->orWhere('ends_at', '>=', now()))
->orderBy('starts_at')->limit(100)->get()
->map(fn (Event $event) => [
'id' => $event->id,
'title' => $event->title,
'starts_at' => $event->starts_at->toIso8601String(),
'all_day' => $event->all_day,
'location' => $event->location,
'is_published' => $event->is_published,
'is_past' => ($event->ends_at ?? $event->starts_at->copy()->endOfDay())->isPast(),
'edit_url' => route('events.edit', $event),
])->all(),
]);
$this->app->make(Widgets::class)->add('events.upcoming', 'events::Upcoming', 'aside', sort: 20, props: fn (User $user) => [
'events' => EventResource::collection(Event::query()->upcoming()->visibleTo($user)->limit(4)->get())->resolve(),
], label: 'Termine', mobileSort: 30);

View file

@ -23,6 +23,7 @@ class EventController extends Controller
),
// Seitenleiste der Startseite (ohne die Termin-Kachel selbst)
'sidebar' => $widgets->sidebar($request->user(), $request, except: ['events.upcoming']),
'canManage' => $request->user()->can('events.manage'),
]);
}
@ -35,6 +36,7 @@ class EventController extends Controller
...(new EventResource($event))->resolve(),
'description_html' => $event->description_html,
],
'editUrl' => request()->user()->can('update', $event) ? route('events.edit', $event) : null,
]);
}

View file

@ -0,0 +1,143 @@
<?php
namespace Inhaus\Plugins\Events\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Media\MediaLibrary;
use App\Support\Audit;
use App\Support\Images;
use App\Support\Permissions\Audiences;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Illuminate\Validation\Rules\File;
use Inertia\Inertia;
use Inertia\Response;
use Inhaus\Plugins\Events\Models\Event;
/**
* Termine im Portal pflegen („Redaktion → Termine“) – dasselbe wie im Backend.
*/
class EventEditorController extends Controller
{
public function create(Request $request): Response
{
Gate::authorize('create', Event::class);
return $this->editor(null);
}
public function edit(Request $request, Event $event): Response
{
Gate::authorize('update', $event);
return $this->editor($event);
}
public function store(Request $request): RedirectResponse
{
Gate::authorize('create', Event::class);
[$attributes, $audience] = $this->validated($request);
$event = Event::query()->create([...$attributes, 'author_id' => $request->user()->id]);
Audiences::sync('event', $event->id, $audience);
Audit::log('event.created', ['event' => $event->id, 'title' => $event->title]);
return to_route('events.show', $event)->with('status', 'Termin angelegt.');
}
public function update(Request $request, Event $event): RedirectResponse
{
Gate::authorize('update', $event);
[$attributes, $audience] = $this->validated($request);
$event->update($attributes);
Audiences::sync('event', $event->id, $audience);
Audit::log('event.updated', ['event' => $event->id, 'title' => $event->title]);
return ($event->is_published ? to_route('events.show', $event) : to_route('editorial'))->with('status', 'Termin gespeichert.');
}
public function destroy(Request $request, Event $event): RedirectResponse
{
Gate::authorize('delete', $event);
$event->delete();
Audiences::sync('event', $event->id, []);
Audit::log('event.deleted', ['event' => $event->id, 'title' => $event->title]);
return to_route('events.index')->with('status', 'Termin „'.$event->title.'“ gelöscht.');
}
public function uploadImage(Request $request, MediaLibrary $library): JsonResponse
{
Gate::authorize('create', Event::class);
$request->validate(['image' => ['required', File::image()->types(['jpg', 'jpeg', 'png', 'webp'])->max(15 * 1024)]]);
$media = $library->store($request->file('image'), 'events', $request->user());
return response()->json(['path' => $media->path, 'url' => app(Images::class)->url($media->path, null), 'media' => $media->toLibraryArray()]);
}
private function editor(?Event $event): Response
{
return Inertia::render('events::Editor', [
'event' => $event ? [
'id' => $event->id,
'title' => $event->title,
'all_day' => $event->all_day,
'starts_at' => $event->starts_at?->format('Y-m-d\TH:i'),
'ends_at' => $event->ends_at?->format('Y-m-d\TH:i'),
'location' => $event->location,
'online_url' => $event->online_url,
'description' => $event->description_html ?: $event->description,
'image_path' => $event->image_path,
'image_url' => $event->imageUrl('large'),
'is_published' => $event->is_published,
'audience' => Audiences::get('event', $event->id),
'url' => route('events.show', $event),
] : null,
'audienceOptions' => Audiences::options(),
]);
}
/**
* @return array{0: array<string, mixed>, 1: array<string, list<string>>}
*/
private function validated(Request $request): array
{
$data = $request->validate([
'title' => ['required', 'string', 'max:160'],
'all_day' => ['boolean'],
'starts_at' => ['required', 'date'],
'ends_at' => ['nullable', 'date', 'after_or_equal:starts_at'],
'location' => ['nullable', 'string', 'max:255'],
'online_url' => ['nullable', 'url:https,http', 'max:500'],
'description' => ['nullable', 'string', 'max:100000'],
'image_path' => ['nullable', 'string', 'max:500', 'regex:#^[A-Za-z0-9/_.-]+$#', 'not_regex:#\.\.#'],
'is_published' => ['boolean'],
'audience' => ['nullable', 'array'],
'audience.*' => ['array'],
'audience.*.*' => ['string', 'max:150'],
], ['ends_at.after_or_equal' => 'Das Ende darf nicht vor dem Beginn liegen.'], [
'title' => 'Titel', 'starts_at' => 'Beginn', 'ends_at' => 'Ende', 'location' => 'Ort', 'online_url' => 'Online-Link',
]);
$allDay = (bool) ($data['all_day'] ?? false);
$start = Carbon::parse($data['starts_at']);
$end = filled($data['ends_at'] ?? null) ? Carbon::parse($data['ends_at']) : null;
return [[
'title' => trim($data['title']),
'all_day' => $allDay,
'starts_at' => $allDay ? $start->startOfDay() : $start,
'ends_at' => $allDay && $end ? $end->endOfDay() : $end,
'location' => filled($data['location'] ?? null) ? trim($data['location']) : null,
'online_url' => $data['online_url'] ?? null,
'description' => filled($data['description'] ?? null) ? $data['description'] : null,
'image_path' => $data['image_path'] ?? null,
'is_published' => (bool) ($data['is_published'] ?? true),
], array_intersect_key((array) ($data['audience'] ?? []), array_flip(['role', 'department', 'location', 'exclude_role']))];
}
}