Terminanmeldung mit Plätzen und Warteliste (0.31.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 5m10s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 5m16s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m42s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m29s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m35s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m36s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m27s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m19s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 44s
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 12:37:28 +00:00
parent 33a76458af
commit b293d2e05a
139 changed files with 1030 additions and 336 deletions

View file

@ -7,6 +7,7 @@ use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Inhaus\Plugins\Events\Http\Resources\EventResource;
use Inhaus\Plugins\Events\Models\Event;
use Inhaus\Plugins\Events\Registrations;
/**
* Anstehende Termine für Apps – dieselben Zielgruppen wie im Portal.
@ -15,9 +16,14 @@ class EventApiController extends Controller
{
public function index(Request $request): JsonResponse
{
return response()->json(['data' => EventResource::collection(
Event::query()->upcoming()->visibleTo($request->user())->limit(200)->get()
)->resolve()]);
$registrations = app(Registrations::class);
// Mit eigenem Anmeldestatus (für „Angemeldet“ bzw. „Warteliste“ in der Liste)
return response()->json(['data' => Event::query()->upcoming()->visibleTo($request->user())->limit(200)->get()
->map(fn (Event $event) => [
...(new EventResource($event))->resolve(),
'registration' => $registrations->summary($event, $request->user()),
])->all()]);
}
public function show(Request $request, Event $event): JsonResponse
@ -29,6 +35,7 @@ class EventApiController extends Controller
'description_html' => $event->description_html,
'url' => route('events.show', $event),
'ics_url' => route('events.ics', $event),
'registration' => app(Registrations::class)->summary($event, $request->user()),
]]);
}
}

View file

@ -12,6 +12,8 @@ use Inertia\Response;
use Inhaus\Plugins\Events\Calendar;
use Inhaus\Plugins\Events\Http\Resources\EventResource;
use Inhaus\Plugins\Events\Models\Event;
use Inhaus\Plugins\Events\Models\EventRegistration;
use Inhaus\Plugins\Events\Registrations;
class EventController extends Controller
{
@ -27,16 +29,35 @@ class EventController extends Controller
]);
}
public function show(Event $event): Response
public function show(Event $event, Registrations $registrations): Response
{
abort_unless($event->is_published && $event->isVisibleTo(request()->user()), 404);
$user = request()->user();
abort_unless($event->is_published && $event->isVisibleTo($user), 404);
$canEdit = $user->can('update', $event);
$summary = $registrations->summary($event, $user);
return Inertia::render('events::Show', [
'registration' => $summary,
// Liste für die Terminpflege; alle anderen sehen – falls freigegeben – nur die Namen der Angemeldeten
'participants' => $summary && ($canEdit || ($event->participants_public && $summary['status'] === EventRegistration::CONFIRMED))
? $event->registrations()->with('user')->orderByRaw('status = ? DESC', [EventRegistration::CONFIRMED])->oldest()->oldest('id')->limit(1000)->get()
->filter(fn (EventRegistration $r) => $canEdit || $r->status === EventRegistration::CONFIRMED)
->map(fn (EventRegistration $r) => [
'id' => $r->id,
'status' => $r->status,
'name' => $r->user?->name,
'user_id' => $r->user_id,
'avatar_url' => $r->user?->avatarUrl(64),
'initials' => $r->user?->initials,
...$canEdit ? ['department' => $r->user?->department, 'note' => $r->note, 'date' => $r->created_at?->toIso8601String()] : [],
])->values()->all()
: null,
'event' => [
...(new EventResource($event))->resolve(),
'description_html' => $event->description_html,
],
'editUrl' => request()->user()->can('update', $event) ? route('events.edit', $event) : null,
'editUrl' => $canEdit ? route('events.edit', $event) : null,
'canManage' => $canEdit,
]);
}

View file

@ -16,6 +16,7 @@ use Illuminate\Validation\Rules\File;
use Inertia\Inertia;
use Inertia\Response;
use Inhaus\Plugins\Events\Models\Event;
use Inhaus\Plugins\Events\Registrations;
/**
* Termine im Portal pflegen („Redaktion → Termine“) – dasselbe wie im Backend.
@ -55,6 +56,7 @@ class EventEditorController extends Controller
$event->update($attributes);
Audiences::sync('event', $event->id, $audience);
app(Registrations::class)->fillFromWaitlist($event);
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.');
@ -95,6 +97,12 @@ class EventEditorController extends Controller
'image_path' => $event->image_path,
'image_url' => $event->imageUrl('large'),
'is_published' => $event->is_published,
'registration_enabled' => $event->registration_enabled,
'capacity' => $event->capacity,
'waitlist' => $event->waitlist,
'registration_deadline' => $event->registration_deadline?->format('Y-m-d\TH:i'),
'participants_public' => $event->participants_public,
'registrations' => $event->registrations()->count(),
'audience' => Audiences::get('event', $event->id),
'url' => route('events.show', $event),
] : null,
@ -117,11 +125,17 @@ class EventEditorController extends Controller
'description' => ['nullable', 'string', 'max:100000'],
'image_path' => ['nullable', 'string', 'max:500', 'regex:#^[A-Za-z0-9/_.-]+$#', 'not_regex:#\.\.#'],
'is_published' => ['boolean'],
'registration_enabled' => ['boolean'],
'capacity' => ['nullable', 'integer', 'min:1', 'max:100000'],
'waitlist' => ['boolean'],
'registration_deadline' => ['nullable', 'date'],
'participants_public' => ['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',
'capacity' => 'Plätze', 'registration_deadline' => 'Anmeldeschluss',
]);
$allDay = (bool) ($data['all_day'] ?? false);
@ -138,6 +152,11 @@ class EventEditorController extends Controller
'description' => filled($data['description'] ?? null) ? $data['description'] : null,
'image_path' => $data['image_path'] ?? null,
'is_published' => (bool) ($data['is_published'] ?? true),
'registration_enabled' => (bool) ($data['registration_enabled'] ?? false),
'capacity' => $data['capacity'] ?? null,
'waitlist' => (bool) ($data['waitlist'] ?? true),
'registration_deadline' => filled($data['registration_deadline'] ?? null) ? Carbon::parse($data['registration_deadline']) : null,
'participants_public' => (bool) ($data['participants_public'] ?? false),
], array_intersect_key((array) ($data['audience'] ?? []), array_flip(['role', 'department', 'location', 'exclude_role']))];
}
}

View file

@ -0,0 +1,103 @@
<?php
namespace Inhaus\Plugins\Events\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Support\Csv;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Illuminate\Validation\ValidationException;
use Inhaus\Plugins\Events\Models\Event;
use Inhaus\Plugins\Events\Models\EventRegistration;
use Inhaus\Plugins\Events\Registrations;
use RuntimeException;
use Symfony\Component\HttpFoundation\StreamedResponse;
/**
* An- und Abmelden zu Terminen – im Portal und über die App-Schnittstelle –
* sowie die Teilnehmendenliste für die Terminpflege.
*/
class RegistrationController extends Controller
{
public function __construct(private readonly Registrations $registrations) {}
public function store(Request $request, Event $event): RedirectResponse|JsonResponse
{
$this->ensureVisible($request, $event);
$data = $request->validate(['note' => ['nullable', 'string', 'max:500']]);
try {
$registration = $this->registrations->register($event, $request->user(), filled($data['note'] ?? null) ? trim($data['note']) : null);
} catch (RuntimeException $e) {
throw ValidationException::withMessages(['registration' => $e->getMessage()]);
}
return $this->respond($request, $event, $registration->status === EventRegistration::CONFIRMED
? 'Sie sind angemeldet.'
: 'Der Termin ist ausgebucht – Sie stehen auf der Warteliste.');
}
public function destroy(Request $request, Event $event): RedirectResponse|JsonResponse
{
$this->ensureVisible($request, $event);
if ($event->starts_at->isPast()) {
throw ValidationException::withMessages(['registration' => 'Der Termin hat bereits begonnen.']);
}
$this->registrations->cancel($event, $request->user());
return $this->respond($request, $event, 'Sie sind abgemeldet.');
}
/** Terminpflege: eine Anmeldung entfernen */
public function remove(Request $request, Event $event, EventRegistration $registration): RedirectResponse
{
Gate::authorize('update', $event);
abort_unless($registration->event_id === $event->id, 404);
$this->registrations->remove($registration);
return back()->with('status', 'Anmeldung entfernt.');
}
public function export(Request $request, Event $event): StreamedResponse
{
Gate::authorize('update', $event);
$rows = EventRegistration::query()->where('event_id', $event->id)->with('user')
->orderByRaw('status = ? DESC', [EventRegistration::CONFIRMED])->oldest()->get();
return response()->streamDownload(function () use ($rows) {
$out = fopen('php://output', 'w');
fwrite($out, "\xEF\xBB\xBF");
fputcsv($out, ['Name', 'E-Mail', 'Abteilung', 'Standort', 'Status', 'Anmerkung', 'Angemeldet am'], ';');
foreach ($rows as $row) {
fputcsv($out, array_map(Csv::cell(...), [
$row->user?->name, $row->user?->email, $row->user?->department, $row->user?->location,
$row->status === EventRegistration::CONFIRMED ? 'Angemeldet' : 'Warteliste',
$row->note, $row->created_at?->timezone(config('app.timezone'))->format('d.m.Y H:i'),
]), ';');
}
fclose($out);
}, 'teilnehmende-termin-'.$event->id.'.csv', ['Content-Type' => 'text/csv; charset=utf-8']);
}
private function ensureVisible(Request $request, Event $event): void
{
abort_unless($event->is_published && $event->isVisibleTo($request->user()), 404);
}
private function respond(Request $request, Event $event, string $message): RedirectResponse|JsonResponse
{
if ($request->expectsJson() && ! $request->header('X-Inertia')) {
return response()->json(['message' => $message, 'data' => $this->registrations->summary($event->fresh(), $request->user())]);
}
return back()->with('status', $message);
}
}

View file

@ -26,6 +26,7 @@ class EventResource extends JsonResource
'all_day' => $this->all_day,
'image_url' => $this->imageUrl('large'),
'thumb_url' => $this->imageUrl('thumb'),
'registration_enabled' => (bool) $this->registration_enabled,
];
}
}