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
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:
parent
33a76458af
commit
b293d2e05a
139 changed files with 1030 additions and 336 deletions
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* Anmeldung zu Terminen: Plätze, Warteliste, Anmeldeschluss.
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('events', function (Blueprint $table) {
|
||||
$table->boolean('registration_enabled')->default(false)->after('is_published');
|
||||
$table->unsignedInteger('capacity')->nullable()->after('registration_enabled');
|
||||
$table->boolean('waitlist')->default(true)->after('capacity');
|
||||
$table->timestamp('registration_deadline')->nullable()->after('waitlist');
|
||||
$table->boolean('participants_public')->default(false)->after('registration_deadline');
|
||||
});
|
||||
|
||||
Schema::create('event_registrations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('event_id')->constrained('events')->cascadeOnDelete();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('status', 20);
|
||||
$table->string('note', 500)->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['event_id', 'user_id']);
|
||||
$table->index(['event_id', 'status', 'created_at']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('event_registrations');
|
||||
|
||||
Schema::table('events', function (Blueprint $table) {
|
||||
$table->dropColumn(['registration_enabled', 'capacity', 'waitlist', 'registration_deadline', 'participants_public']);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -15,6 +15,7 @@ defineProps({
|
|||
<h3 class="line-clamp-2 text-sm leading-snug font-semibold group-hover:underline">{{ event.title }}</h3>
|
||||
<p class="mt-0.5 text-xs text-muted-foreground">{{ formatEventRange(event) }}</p>
|
||||
<p v-if="event.location" class="truncate text-xs text-muted-foreground">{{ event.location }}</p>
|
||||
<span v-if="event.registration_enabled" class="mt-1 inline-block rounded bg-brand-soft px-1.5 py-0.5 text-[11px] font-medium text-brand-text">Mit Anmeldung</span>
|
||||
</div>
|
||||
</Link>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -41,6 +41,11 @@ const form = useForm({
|
|||
description: e?.description ?? '',
|
||||
image_path: e?.image_path ?? null,
|
||||
is_published: e?.is_published ?? true,
|
||||
registration_enabled: e?.registration_enabled ?? false,
|
||||
capacity: e?.capacity ?? '',
|
||||
waitlist: e?.waitlist ?? true,
|
||||
registration_deadline: e?.registration_deadline ?? '',
|
||||
participants_public: e?.participants_public ?? false,
|
||||
audience: e?.audience ?? {},
|
||||
});
|
||||
|
||||
|
|
@ -137,6 +142,39 @@ function remove() {
|
|||
<Link v-if="e?.url && e.is_published" :href="e.url" class="mt-3 inline-flex items-center gap-1 text-[13px] text-brand-text hover:underline"><ArrowLeft class="size-3.5" /> Zum Termin</Link>
|
||||
</Panel>
|
||||
|
||||
<Panel title="Anmeldung">
|
||||
<label class="flex items-center justify-between gap-3 text-sm">
|
||||
<span>
|
||||
<span class="font-medium">Anmeldung erforderlich</span>
|
||||
<span class="block text-xs text-muted-foreground">Mitarbeitende melden sich im Portal oder in der App an.</span>
|
||||
</span>
|
||||
<Switch v-model="form.registration_enabled" />
|
||||
</label>
|
||||
<div v-if="form.registration_enabled" class="mt-4 grid gap-4 border-t pt-4">
|
||||
<FormField id="ev-capacity" label="Plätze" :error="form.errors.capacity" hint="Leer lassen für unbegrenzt.">
|
||||
<Input id="ev-capacity" v-model="form.capacity" type="number" min="1" inputmode="numeric" />
|
||||
</FormField>
|
||||
<label v-if="form.capacity" class="flex items-center justify-between gap-3 text-sm">
|
||||
<span>
|
||||
<span class="font-medium">Warteliste</span>
|
||||
<span class="block text-xs text-muted-foreground">Wird ein Platz frei, rückt die nächste Person automatisch nach.</span>
|
||||
</span>
|
||||
<Switch v-model="form.waitlist" />
|
||||
</label>
|
||||
<FormField id="ev-deadline" label="Anmeldeschluss (optional)" :error="form.errors.registration_deadline" hint="Ohne Angabe bis zum Beginn.">
|
||||
<Input id="ev-deadline" v-model="form.registration_deadline" type="datetime-local" />
|
||||
</FormField>
|
||||
<label class="flex items-center justify-between gap-3 text-sm">
|
||||
<span>
|
||||
<span class="font-medium">Teilnehmende zeigen</span>
|
||||
<span class="block text-xs text-muted-foreground">Angemeldete sehen, wer noch kommt.</span>
|
||||
</span>
|
||||
<Switch v-model="form.participants_public" />
|
||||
</label>
|
||||
<p v-if="e?.registrations" class="text-[13px] text-muted-foreground">Bisher {{ e.registrations }} {{ e.registrations === 1 ? 'Anmeldung' : 'Anmeldungen' }} – die Liste steht beim Termin.</p>
|
||||
</div>
|
||||
</Panel>
|
||||
|
||||
<Panel title="Titelbild">
|
||||
<div v-if="form.image_path" class="relative overflow-hidden rounded-md border">
|
||||
<img :src="previewUrl" alt="" class="aspect-video w-full object-cover" />
|
||||
|
|
|
|||
|
|
@ -1,19 +1,49 @@
|
|||
<script setup>
|
||||
import { watch } from 'vue';
|
||||
import { Link, usePage } from '@inertiajs/vue3';
|
||||
import { ArrowLeft, CalendarPlus, Clock, MapPin, PencilLine, Video } from '@lucide/vue';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { Link, router, useForm, usePage } from '@inertiajs/vue3';
|
||||
import { ArrowLeft, CalendarCheck, CalendarPlus, Clock, Download, Hourglass, LoaderCircle, MapPin, PencilLine, Trash2, Users, Video } from '@lucide/vue';
|
||||
import { toast } from 'vue-sonner';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import EventDateBlock from '../components/EventDateBlock.vue';
|
||||
import Panel from '@/components/Panel.vue';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
import { formatEventRange } from '@/lib/format';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import PersonAvatar from '@/components/PersonAvatar.vue';
|
||||
import { formatDate, formatEventRange, formatShortDate, formatTime } from '@/lib/format';
|
||||
|
||||
defineProps({
|
||||
const props = defineProps({
|
||||
event: { type: Object, required: true },
|
||||
editUrl: { type: String, default: null },
|
||||
canManage: { type: Boolean, default: false },
|
||||
registration: { type: Object, default: null },
|
||||
participants: { type: Array, default: null },
|
||||
});
|
||||
|
||||
// Anmeldung
|
||||
const reg = computed(() => props.registration);
|
||||
const regForm = useForm({ note: props.registration?.note ?? '' });
|
||||
const showNote = ref(false);
|
||||
const full = computed(() => reg.value && reg.value.free === 0);
|
||||
|
||||
function register() {
|
||||
regForm.post(`/termine/${props.event.id}/anmeldung`, { preserveScroll: true, onSuccess: () => (showNote.value = false) });
|
||||
}
|
||||
|
||||
function unregister() {
|
||||
if (window.confirm('Wirklich abmelden? Ihr Platz geht an die nächste Person.')) {
|
||||
router.delete(`/termine/${props.event.id}/anmeldung`, { preserveScroll: true });
|
||||
}
|
||||
}
|
||||
|
||||
function removeParticipant(participant) {
|
||||
if (window.confirm(`Anmeldung von ${participant.name} entfernen?`)) {
|
||||
router.delete(`/termine/${props.event.id}/anmeldungen/${participant.id}`, { preserveScroll: true });
|
||||
}
|
||||
}
|
||||
|
||||
const confirmedList = computed(() => (props.participants ?? []).filter((p) => p.status === 'confirmed'));
|
||||
const waitingList = computed(() => (props.participants ?? []).filter((p) => p.status === 'waitlist'));
|
||||
|
||||
const page = usePage();
|
||||
watch(() => page.props.flash.status, (status) => status && toast.success(status), { immediate: true });
|
||||
</script>
|
||||
|
|
@ -69,6 +99,86 @@ watch(() => page.props.flash.status, (status) => status && toast.success(status)
|
|||
<a :href="`/termine/${event.id}/kalender.ics`"><CalendarPlus /> In meinen Kalender</a>
|
||||
</Button>
|
||||
</Panel>
|
||||
|
||||
<!-- Anmeldung -->
|
||||
<Panel v-if="reg" title="Anmeldung" class="self-start lg:col-start-3">
|
||||
<div class="grid gap-4 text-sm">
|
||||
<div v-if="reg.capacity" class="grid gap-1.5">
|
||||
<div class="flex items-baseline justify-between">
|
||||
<span class="text-muted-foreground">Belegt</span>
|
||||
<span class="font-medium tabular-nums">{{ reg.confirmed }} von {{ reg.capacity }}</span>
|
||||
</div>
|
||||
<div class="h-2 overflow-hidden rounded-full bg-muted">
|
||||
<div class="h-full rounded-full bg-brand" :style="{ width: `${Math.min(100, (reg.confirmed / reg.capacity) * 100)}%` }" />
|
||||
</div>
|
||||
<span v-if="reg.waiting" class="text-xs text-muted-foreground">{{ reg.waiting }} auf der Warteliste</span>
|
||||
</div>
|
||||
<p v-else class="text-muted-foreground">{{ reg.confirmed }} {{ reg.confirmed === 1 ? 'Person ist' : 'Personen sind' }} angemeldet.</p>
|
||||
|
||||
<div v-if="reg.status === 'confirmed'" class="flex items-start gap-2.5 rounded-md bg-brand-soft p-3 text-brand-text">
|
||||
<CalendarCheck class="mt-0.5 size-4 shrink-0" />
|
||||
<span><span class="font-semibold">Sie sind angemeldet.</span><span v-if="reg.note" class="block text-[13px] opacity-80">Anmerkung: {{ reg.note }}</span></span>
|
||||
</div>
|
||||
<div v-else-if="reg.status === 'waitlist'" class="flex items-start gap-2.5 rounded-md bg-muted p-3">
|
||||
<Hourglass class="mt-0.5 size-4 shrink-0 text-muted-foreground" />
|
||||
<span><span class="font-semibold">Warteliste, Platz {{ reg.position }}.</span><span class="block text-[13px] text-muted-foreground">Wird ein Platz frei, rücken Sie automatisch nach und bekommen Bescheid.</span></span>
|
||||
</div>
|
||||
|
||||
<p v-if="reg.deadline && reg.open" class="text-xs text-muted-foreground">Anmeldeschluss: {{ formatDate(reg.deadline) }}, {{ formatTime(reg.deadline) }} Uhr</p>
|
||||
|
||||
<template v-if="reg.open && !reg.status">
|
||||
<div v-if="showNote" class="grid gap-1.5">
|
||||
<label for="reg-note" class="text-[13px] font-medium">Anmerkung (optional)</label>
|
||||
<Textarea id="reg-note" v-model="regForm.note" rows="2" maxlength="500" placeholder="z. B. vegetarisch, Begleitung …" />
|
||||
</div>
|
||||
<p v-if="regForm.errors.registration" class="text-[13px] text-destructive">{{ regForm.errors.registration }}</p>
|
||||
<Button v-if="!full || reg.waitlist" :disabled="regForm.processing" class="w-full" @click="register">
|
||||
<LoaderCircle v-if="regForm.processing" class="animate-spin" />
|
||||
{{ full ? 'Auf die Warteliste' : 'Jetzt anmelden' }}
|
||||
</Button>
|
||||
<p v-else class="font-medium">Leider ausgebucht.</p>
|
||||
<button v-if="!showNote && (!full || reg.waitlist)" type="button" class="text-[13px] text-muted-foreground hover:text-foreground hover:underline" @click="showNote = true">Anmerkung hinzufügen</button>
|
||||
</template>
|
||||
<p v-else-if="!reg.open && !reg.status" class="text-muted-foreground">Die Anmeldung ist geschlossen.</p>
|
||||
|
||||
<Button v-if="reg.status && new Date(event.starts_at) > new Date()" variant="ghost" size="sm" class="justify-self-start text-destructive hover:text-destructive" @click="unregister">
|
||||
{{ reg.status === 'waitlist' ? 'Von der Warteliste nehmen' : 'Abmelden' }}
|
||||
</Button>
|
||||
</div>
|
||||
</Panel>
|
||||
|
||||
<!-- Teilnehmende -->
|
||||
<Panel v-if="participants" :title="canManage ? 'Teilnehmende' : 'Wer kommt?'" class="lg:col-span-2 lg:row-start-2">
|
||||
<template v-if="canManage" #actions>
|
||||
<Button variant="outline" size="sm" as-child><a :href="`/termine/${event.id}/teilnehmende.csv`"><Download /> Liste (CSV)</a></Button>
|
||||
</template>
|
||||
<p v-if="!participants.length" class="text-sm text-muted-foreground">Noch keine Anmeldungen.</p>
|
||||
<ul v-if="confirmedList.length" class="-mx-5 divide-y border-y">
|
||||
<li v-for="p in confirmedList" :key="p.id" class="flex items-center gap-3 px-5 py-2">
|
||||
<PersonAvatar :person="p" class="size-8" />
|
||||
<div class="min-w-0 flex-1 text-sm">
|
||||
<Link :href="`/personen/${p.user_id}`" class="font-medium hover:underline">{{ p.name }}</Link>
|
||||
<p v-if="canManage && (p.department || p.note)" class="truncate text-xs text-muted-foreground">{{ [p.department, p.note].filter(Boolean).join(' · ') }}</p>
|
||||
</div>
|
||||
<span v-if="canManage" class="text-xs text-muted-foreground tabular-nums">{{ formatShortDate(p.date) }}</span>
|
||||
<Button v-if="canManage" variant="ghost" size="icon" class="size-7 text-muted-foreground hover:text-destructive" :aria-label="`${p.name} entfernen`" @click="removeParticipant(p)"><Trash2 class="size-3.5" /></Button>
|
||||
</li>
|
||||
</ul>
|
||||
<template v-if="canManage && waitingList.length">
|
||||
<h3 class="mt-5 mb-2 flex items-center gap-1.5 text-xs font-semibold tracking-wider text-muted-foreground uppercase"><Users class="size-3.5" /> Warteliste</h3>
|
||||
<ol class="-mx-5 divide-y border-y">
|
||||
<li v-for="(p, i) in waitingList" :key="p.id" class="flex items-center gap-3 px-5 py-2">
|
||||
<span class="w-5 text-right text-xs text-muted-foreground tabular-nums">{{ i + 1 }}.</span>
|
||||
<PersonAvatar :person="p" class="size-8" />
|
||||
<div class="min-w-0 flex-1 text-sm">
|
||||
<span class="font-medium">{{ p.name }}</span>
|
||||
<p v-if="p.department || p.note" class="truncate text-xs text-muted-foreground">{{ [p.department, p.note].filter(Boolean).join(' · ') }}</p>
|
||||
</div>
|
||||
<Button variant="ghost" size="icon" class="size-7 text-muted-foreground hover:text-destructive" :aria-label="`${p.name} entfernen`" @click="removeParticipant(p)"><Trash2 class="size-3.5" /></Button>
|
||||
</li>
|
||||
</ol>
|
||||
</template>
|
||||
</Panel>
|
||||
</div>
|
||||
</div>
|
||||
</AppLayout>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@
|
|||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Inhaus\Plugins\Events\Http\Controllers\EventApiController;
|
||||
use Inhaus\Plugins\Events\Http\Controllers\RegistrationController;
|
||||
|
||||
// /api/v1/events … (Token nötig, siehe docs/API.md)
|
||||
Route::get('/events', [EventApiController::class, 'index']);
|
||||
Route::get('/events/{event}', [EventApiController::class, 'show'])->whereNumber('event');
|
||||
Route::post('/events/{event}/registration', [RegistrationController::class, 'store'])->whereNumber('event')->middleware('throttle:30,1');
|
||||
Route::delete('/events/{event}/registration', [RegistrationController::class, 'destroy'])->whereNumber('event')->middleware('throttle:30,1');
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
use Illuminate\Support\Facades\Route;
|
||||
use Inhaus\Plugins\Events\Http\Controllers\EventController;
|
||||
use Inhaus\Plugins\Events\Http\Controllers\EventEditorController;
|
||||
use Inhaus\Plugins\Events\Http\Controllers\RegistrationController;
|
||||
|
||||
Route::middleware('auth')->group(function () {
|
||||
Route::get('/termine', [EventController::class, 'index'])->name('events.index');
|
||||
|
|
@ -17,5 +18,9 @@ Route::middleware('auth')->group(function () {
|
|||
Route::delete('/{event}', 'destroy')->name('destroy');
|
||||
});
|
||||
Route::get('/termine/{event}', [EventController::class, 'show'])->name('events.show');
|
||||
Route::post('/termine/{event}/anmeldung', [RegistrationController::class, 'store'])->middleware('throttle:30,1')->name('events.register');
|
||||
Route::delete('/termine/{event}/anmeldung', [RegistrationController::class, 'destroy'])->middleware('throttle:30,1')->name('events.unregister');
|
||||
Route::delete('/termine/{event}/anmeldungen/{registration}', [RegistrationController::class, 'remove'])->name('events.registrations.remove');
|
||||
Route::get('/termine/{event}/teilnehmende.csv', [RegistrationController::class, 'export'])->name('events.registrations.export');
|
||||
Route::get('/termine/{event}/kalender.ics', [EventController::class, 'ics'])->name('events.ics');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -98,6 +98,19 @@ class EventResource extends Resource
|
|||
->automaticallyCropImagesToAspectRatio()
|
||||
->maxSize(10 * 1024),
|
||||
]),
|
||||
Section::make('Anmeldung')
|
||||
->columnSpan(1)
|
||||
->schema([
|
||||
Toggle::make('registration_enabled')->label('Anmeldung erforderlich')->live(),
|
||||
TextInput::make('capacity')->label('Plätze')->helperText('Leer = unbegrenzt.')->numeric()->minValue(1)->maxValue(100000)
|
||||
->visible(fn (Get $get) => $get('registration_enabled'))->live(),
|
||||
Toggle::make('waitlist')->label('Warteliste')->default(true)
|
||||
->visible(fn (Get $get) => $get('registration_enabled') && filled($get('capacity'))),
|
||||
DateTimePicker::make('registration_deadline')->label('Anmeldeschluss')->seconds(false)
|
||||
->visible(fn (Get $get) => $get('registration_enabled')),
|
||||
Toggle::make('participants_public')->label('Angemeldete sehen, wer noch kommt')
|
||||
->visible(fn (Get $get) => $get('registration_enabled')),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,15 @@ namespace Inhaus\Plugins\Events\Filament\Resources\Events\Pages;
|
|||
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Inhaus\Plugins\Events\Filament\Resources\Events\EventResource;
|
||||
use Inhaus\Plugins\Events\Registrations;
|
||||
|
||||
class EditEvent extends EditRecord
|
||||
{
|
||||
protected static string $resource = EventResource::class;
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
// Mehr Plätze → Warteliste rückt nach
|
||||
app(Registrations::class)->fillFromWaitlist($this->record);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
]]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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']))];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,11 +11,13 @@ use Illuminate\Database\Eloquent\Builder;
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Inhaus\Plugins\Events\Database\Factories\EventFactory;
|
||||
|
||||
#[Fillable([
|
||||
'author_id', 'title', 'description', 'location', 'online_url',
|
||||
'starts_at', 'ends_at', 'all_day', 'image_path', 'is_published',
|
||||
'registration_enabled', 'capacity', 'waitlist', 'registration_deadline', 'participants_public',
|
||||
])]
|
||||
class Event extends Model
|
||||
{
|
||||
|
|
@ -54,6 +56,11 @@ class Event extends Model
|
|||
'ends_at' => 'datetime',
|
||||
'all_day' => 'boolean',
|
||||
'is_published' => 'boolean',
|
||||
'registration_enabled' => 'boolean',
|
||||
'capacity' => 'integer',
|
||||
'waitlist' => 'boolean',
|
||||
'registration_deadline' => 'datetime',
|
||||
'participants_public' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -65,6 +72,14 @@ class Event extends Model
|
|||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<EventRegistration, $this>
|
||||
*/
|
||||
public function registrations(): HasMany
|
||||
{
|
||||
return $this->hasMany(EventRegistration::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Veröffentlichte Termine, die noch nicht vorbei sind (laufende eingeschlossen).
|
||||
*
|
||||
|
|
|
|||
32
plugins-core/events/src/Models/EventRegistration.php
Normal file
32
plugins-core/events/src/Models/EventRegistration.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Events\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable(['event_id', 'user_id', 'status', 'note'])]
|
||||
class EventRegistration extends Model
|
||||
{
|
||||
public const CONFIRMED = 'confirmed';
|
||||
|
||||
public const WAITLIST = 'waitlist';
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Event, $this>
|
||||
*/
|
||||
public function event(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Event::class);
|
||||
}
|
||||
}
|
||||
152
plugins-core/events/src/Registrations.php
Normal file
152
plugins-core/events/src/Registrations.php
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Events;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Notifications\PortalNotification;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inhaus\Plugins\Events\Models\Event;
|
||||
use Inhaus\Plugins\Events\Models\EventRegistration;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Anmeldungen zu Terminen: feste Plätze, danach Warteliste. Wird ein Platz frei,
|
||||
* rückt die erste Person der Warteliste nach und bekommt Bescheid.
|
||||
*/
|
||||
class Registrations
|
||||
{
|
||||
public function isOpen(Event $event): bool
|
||||
{
|
||||
return $event->registration_enabled && $event->is_published
|
||||
&& $event->starts_at->isFuture()
|
||||
&& ($event->registration_deadline === null || $event->registration_deadline->isFuture());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RuntimeException wenn keine Anmeldung möglich ist
|
||||
*/
|
||||
public function register(Event $event, User $user, ?string $note = null): EventRegistration
|
||||
{
|
||||
if (! $this->isOpen($event)) {
|
||||
throw new RuntimeException('Für diesen Termin ist keine Anmeldung (mehr) möglich.');
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($event, $user, $note) {
|
||||
// Sperre auf den Termin, damit bei gleichzeitigen Anmeldungen niemand über die Grenze rutscht
|
||||
$event = Event::query()->lockForUpdate()->findOrFail($event->id);
|
||||
$existing = EventRegistration::query()->where('event_id', $event->id)->where('user_id', $user->id)->first();
|
||||
|
||||
if ($existing) {
|
||||
$existing->update(['note' => $note]);
|
||||
|
||||
return $existing;
|
||||
}
|
||||
|
||||
$status = $this->hasSpace($event) ? EventRegistration::CONFIRMED : ($event->waitlist ? EventRegistration::WAITLIST : null);
|
||||
|
||||
if ($status === null) {
|
||||
throw new RuntimeException('Der Termin ist leider ausgebucht.');
|
||||
}
|
||||
|
||||
return EventRegistration::query()->create(['event_id' => $event->id, 'user_id' => $user->id, 'status' => $status, 'note' => $note]);
|
||||
});
|
||||
}
|
||||
|
||||
public function cancel(Event $event, User $user): void
|
||||
{
|
||||
$this->remove(EventRegistration::query()->where('event_id', $event->id)->where('user_id', $user->id)->first());
|
||||
}
|
||||
|
||||
public function remove(?EventRegistration $registration): void
|
||||
{
|
||||
if (! $registration) {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($registration) {
|
||||
Event::query()->lockForUpdate()->find($registration->event_id);
|
||||
$registration->delete();
|
||||
});
|
||||
|
||||
$this->fillFromWaitlist($registration->event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Freie Plätze an die Warteliste vergeben (nach Abmeldung oder mehr Plätzen).
|
||||
*/
|
||||
public function fillFromWaitlist(Event $event): void
|
||||
{
|
||||
$promoted = DB::transaction(function () use ($event) {
|
||||
$event = Event::query()->lockForUpdate()->findOrFail($event->id);
|
||||
$promoted = collect();
|
||||
|
||||
while ($this->hasSpace($event)) {
|
||||
$next = EventRegistration::query()->where('event_id', $event->id)->where('status', EventRegistration::WAITLIST)->oldest()->oldest('id')->first();
|
||||
|
||||
if (! $next) {
|
||||
break;
|
||||
}
|
||||
|
||||
$next->update(['status' => EventRegistration::CONFIRMED]);
|
||||
$promoted->push($next);
|
||||
}
|
||||
|
||||
return $promoted;
|
||||
});
|
||||
|
||||
if ($event->starts_at->isPast()) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($promoted as $registration) {
|
||||
$registration->user?->notify(new PortalNotification(
|
||||
'Sie sind nachgerückt: '.$event->title,
|
||||
'Ein Platz ist frei geworden – Ihre Anmeldung ist jetzt bestätigt.',
|
||||
route('events.show', $event),
|
||||
'calendar-check',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function confirmedCount(Event $event): int
|
||||
{
|
||||
return EventRegistration::query()->where('event_id', $event->id)->where('status', EventRegistration::CONFIRMED)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stand für die Anzeige: eigene Anmeldung, Plätze, Warteliste.
|
||||
*
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function summary(Event $event, User $user): ?array
|
||||
{
|
||||
if (! $event->registration_enabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$mine = EventRegistration::query()->where('event_id', $event->id)->where('user_id', $user->id)->first();
|
||||
$confirmed = $this->confirmedCount($event);
|
||||
$waiting = EventRegistration::query()->where('event_id', $event->id)->where('status', EventRegistration::WAITLIST);
|
||||
|
||||
return [
|
||||
'enabled' => true,
|
||||
'open' => $this->isOpen($event),
|
||||
'deadline' => $event->registration_deadline?->toIso8601String(),
|
||||
'capacity' => $event->capacity,
|
||||
'confirmed' => $confirmed,
|
||||
'free' => $event->capacity === null ? null : max(0, $event->capacity - $confirmed),
|
||||
'waitlist' => $event->waitlist,
|
||||
'waiting' => (clone $waiting)->count(),
|
||||
'status' => $mine?->status,
|
||||
'note' => $mine?->note,
|
||||
'position' => $mine?->status === EventRegistration::WAITLIST
|
||||
? (clone $waiting)->where(fn ($q) => $q->where('created_at', '<', $mine->created_at)->orWhere(fn ($q) => $q->where('created_at', $mine->created_at)->where('id', '<', $mine->id)))->count() + 1
|
||||
: null,
|
||||
];
|
||||
}
|
||||
|
||||
private function hasSpace(Event $event): bool
|
||||
{
|
||||
return $event->capacity === null || $this->confirmedCount($event) < $event->capacity;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue