Plugin-System; Neuigkeiten und Termine als mitgelieferte Plugins
- Plugins nach WordPress-Prinzip: plugin.json-Manifest mit Versions- und Abhängigkeitsprüfung, eigenes PSR-4-Autoloading, register()/boot(), activate()/deactivate()/uninstall(), Migrationen, Routen und Views je Plugin - plugins-core/ (mitgeliefert, aktiv bis zur Deaktivierung) und plugins/ (Kunden-Plugins, geschützt vor Updates, inaktiv bis zur Aktivierung) - Zustand in storage/app/plugins.json – Laden ohne Datenbankabfrage - Wiederherstellungsmodus: Ausnahmen und Fatal Errors beim Laden deaktivieren das Plugin, das Portal bleibt erreichbar - Hooks (Actions/Filter mit Prioritäten) und Registries für Navigation, Startseiten-Kacheln, Rechte und Admin-Seiten (Filament-Discovery) - Admin-Seite „Plugins“: aktivieren, deaktivieren, per ZIP installieren (ZIP-Slip-Schutz), löschen mit oder ohne Daten; abschaltbar per INHAUS_DISALLOW_FILE_MODS - Startseite komplett aus Kacheln; Plugin-Seiten als „slug::Seite“ - Version 0.3.0 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
cc0020458f
commit
28ef1e4a20
155 changed files with 2762 additions and 573 deletions
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('events', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('author_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->string('title');
|
||||
$table->longText('description')->nullable();
|
||||
$table->longText('description_html')->nullable();
|
||||
$table->string('location')->nullable();
|
||||
$table->string('online_url', 500)->nullable();
|
||||
$table->timestamp('starts_at');
|
||||
$table->timestamp('ends_at')->nullable();
|
||||
$table->boolean('all_day')->default(false);
|
||||
$table->string('image_path')->nullable();
|
||||
$table->boolean('is_published')->default(true);
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['is_published', 'starts_at']);
|
||||
$table->index(['is_published', 'ends_at']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('events');
|
||||
}
|
||||
};
|
||||
13
plugins-core/events/plugin.json
Normal file
13
plugins-core/events/plugin.json
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"slug": "events",
|
||||
"name": "Termine",
|
||||
"version": "1.0.0",
|
||||
"description": "Veranstaltungen und Fortbildungen mit Kalender-Export.",
|
||||
"author": "Inhaus",
|
||||
"namespace": "Inhaus\\Plugins\\Events\\",
|
||||
"class": "Inhaus\\Plugins\\Events\\EventsPlugin",
|
||||
"requires": {
|
||||
"core": ">=0.3.0",
|
||||
"php": ">=8.3"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
import { dateBlock } from '@/lib/format';
|
||||
|
||||
const props = defineProps({
|
||||
date: { type: String, required: true },
|
||||
});
|
||||
|
||||
const block = computed(() => dateBlock(props.date));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="grid w-12 shrink-0 place-items-center rounded-md bg-muted py-1.5 leading-none">
|
||||
<span class="text-xl font-semibold">{{ block.day }}</span>
|
||||
<span class="mt-1 text-[10px] font-semibold tracking-wide text-muted-foreground">{{ block.month }}</span>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<script setup>
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import EventDateBlock from './EventDateBlock.vue';
|
||||
import { formatEventRange } from '@/lib/format';
|
||||
|
||||
defineProps({
|
||||
event: { type: Object, required: true },
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Link :href="`/termine/${event.id}`" class="group flex items-start gap-3.5 py-3">
|
||||
<EventDateBlock :date="event.starts_at" />
|
||||
<div class="min-w-0 pt-0.5">
|
||||
<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>
|
||||
</div>
|
||||
</Link>
|
||||
</template>
|
||||
68
plugins-core/events/resources/js/pages/Index.vue
Normal file
68
plugins-core/events/resources/js/pages/Index.vue
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import { CalendarDays, MapPin, Video } from '@lucide/vue';
|
||||
import EmptyState from '@/components/EmptyState.vue';
|
||||
import EventDateBlock from '../components/EventDateBlock.vue';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
import { formatEventRange, formatMonthYear } from '@/lib/format';
|
||||
|
||||
const props = defineProps({
|
||||
events: { type: Object, required: true },
|
||||
});
|
||||
|
||||
// Nach Monaten gruppieren – laufende Termine erscheinen im aktuellen Monat.
|
||||
const groups = computed(() => {
|
||||
const result = [];
|
||||
|
||||
for (const event of props.events.data) {
|
||||
const start = new Date(event.starts_at);
|
||||
const shown = start < new Date() ? new Date() : start;
|
||||
const label = formatMonthYear(shown.toISOString());
|
||||
const last = result[result.length - 1];
|
||||
|
||||
if (last?.label === label) {
|
||||
last.events.push(event);
|
||||
} else {
|
||||
result.push({ label, events: [event] });
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout title="Termine">
|
||||
<div class="mb-6">
|
||||
<h1 class="text-2xl font-semibold tracking-tight">Termine</h1>
|
||||
<p class="mt-1 text-sm text-muted-foreground">Veranstaltungen, Fortbildungen und Treffen.</p>
|
||||
</div>
|
||||
|
||||
<div v-if="groups.length" class="grid max-w-4xl gap-8">
|
||||
<section v-for="group in groups" :key="group.label">
|
||||
<h2 class="mb-3 text-sm font-semibold text-muted-foreground">{{ group.label }}</h2>
|
||||
<ul class="divide-y rounded-lg border bg-card">
|
||||
<li v-for="event in group.events" :key="event.id">
|
||||
<Link :href="`/termine/${event.id}`" class="group flex items-center gap-4 p-4 transition-colors hover:bg-accent/60">
|
||||
<EventDateBlock :date="event.starts_at" class="w-14" />
|
||||
<div class="min-w-0 flex-1">
|
||||
<h3 class="text-[15px] font-semibold group-hover:underline">{{ event.title }}</h3>
|
||||
<p class="mt-0.5 text-[13px] text-muted-foreground">{{ formatEventRange(event) }}</p>
|
||||
<p v-if="event.location || event.online_url" class="mt-0.5 flex items-center gap-1.5 text-[13px] text-muted-foreground">
|
||||
<MapPin v-if="event.location" class="size-3.5" />
|
||||
<Video v-else class="size-3.5" />
|
||||
{{ event.location || 'Online' }}
|
||||
</p>
|
||||
</div>
|
||||
<img v-if="event.thumb_url" :src="event.thumb_url" alt="" loading="lazy" class="hidden h-16 w-28 shrink-0 rounded-md object-cover sm:block" />
|
||||
</Link>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
<div v-else class="max-w-4xl rounded-lg border border-dashed bg-card">
|
||||
<EmptyState :icon="CalendarDays" title="Keine anstehenden Termine" text="Neue Termine erscheinen hier, sobald sie eingetragen sind." />
|
||||
</div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
66
plugins-core/events/resources/js/pages/Show.vue
Normal file
66
plugins-core/events/resources/js/pages/Show.vue
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<script setup>
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import { ArrowLeft, CalendarPlus, Clock, MapPin, Video } from '@lucide/vue';
|
||||
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';
|
||||
|
||||
defineProps({
|
||||
event: { type: Object, required: true },
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout :title="event.title">
|
||||
<div class="mx-auto max-w-4xl">
|
||||
<Link href="/termine" class="mb-6 inline-flex items-center gap-1.5 text-sm font-medium text-muted-foreground hover:text-foreground">
|
||||
<ArrowLeft class="size-4" /> Alle Termine
|
||||
</Link>
|
||||
|
||||
<div class="flex items-start gap-4">
|
||||
<EventDateBlock :date="event.starts_at" class="w-16 py-2" />
|
||||
<h1 class="pt-1 text-2xl leading-tight font-semibold tracking-tight sm:text-3xl">{{ event.title }}</h1>
|
||||
</div>
|
||||
|
||||
<img v-if="event.image_url" :src="event.image_url" :alt="event.title" class="mt-6 aspect-video w-full rounded-lg object-cover" />
|
||||
|
||||
<div class="mt-6 grid gap-6 lg:grid-cols-3">
|
||||
<Panel title="Beschreibung" class="lg:col-span-2">
|
||||
<div v-if="event.description_html" class="prose prose-neutral max-w-none text-[15px]" v-html="event.description_html" />
|
||||
<p v-else class="text-sm text-muted-foreground">Keine weiteren Informationen.</p>
|
||||
</Panel>
|
||||
|
||||
<Panel title="Details" class="content-start">
|
||||
<dl class="grid gap-4 text-sm">
|
||||
<div class="flex gap-3">
|
||||
<Clock class="mt-0.5 size-4 shrink-0 text-muted-foreground" />
|
||||
<div>
|
||||
<dt class="text-xs text-muted-foreground">Wann</dt>
|
||||
<dd>{{ formatEventRange(event) }}</dd>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="event.location" class="flex gap-3">
|
||||
<MapPin class="mt-0.5 size-4 shrink-0 text-muted-foreground" />
|
||||
<div>
|
||||
<dt class="text-xs text-muted-foreground">Ort</dt>
|
||||
<dd>{{ event.location }}</dd>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="event.online_url" class="flex gap-3">
|
||||
<Video class="mt-0.5 size-4 shrink-0 text-muted-foreground" />
|
||||
<div class="min-w-0">
|
||||
<dt class="text-xs text-muted-foreground">Online</dt>
|
||||
<dd class="truncate"><a :href="event.online_url" target="_blank" rel="noopener" class="text-brand-text hover:underline">Zur Teilnahme</a></dd>
|
||||
</div>
|
||||
</div>
|
||||
</dl>
|
||||
<Button variant="outline" class="mt-5 w-full" as-child>
|
||||
<a :href="`/termine/${event.id}/kalender.ics`"><CalendarPlus /> In meinen Kalender</a>
|
||||
</Button>
|
||||
</Panel>
|
||||
</div>
|
||||
</div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
19
plugins-core/events/resources/js/widgets/Upcoming.vue
Normal file
19
plugins-core/events/resources/js/widgets/Upcoming.vue
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<script setup>
|
||||
import { CalendarDays } from '@lucide/vue';
|
||||
import EmptyState from '@/components/EmptyState.vue';
|
||||
import Panel from '@/components/Panel.vue';
|
||||
import EventListItem from '../components/EventListItem.vue';
|
||||
|
||||
defineProps({
|
||||
events: { type: Array, required: true },
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Panel title="Termine" action-label="Alle Termine" action-href="/termine">
|
||||
<div v-if="events.length" class="-my-3 divide-y">
|
||||
<EventListItem v-for="event in events" :key="event.id" :event="event" />
|
||||
</div>
|
||||
<EmptyState v-else :icon="CalendarDays" title="Keine anstehenden Termine" class="py-6" />
|
||||
</Panel>
|
||||
</template>
|
||||
10
plugins-core/events/routes/web.php
Normal file
10
plugins-core/events/routes/web.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Inhaus\Plugins\Events\Http\Controllers\EventController;
|
||||
|
||||
Route::middleware('auth')->group(function () {
|
||||
Route::get('/termine', [EventController::class, 'index'])->name('events.index');
|
||||
Route::get('/termine/{event}', [EventController::class, 'show'])->name('events.show');
|
||||
Route::get('/termine/{event}/kalender.ics', [EventController::class, 'ics'])->name('events.ics');
|
||||
});
|
||||
86
plugins-core/events/src/Calendar.php
Normal file
86
plugins-core/events/src/Calendar.php
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Events;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Inhaus\Plugins\Events\Models\Event;
|
||||
|
||||
/**
|
||||
* iCalendar-Export (RFC 5545) für einzelne Termine – zum Übernehmen in Outlook & Co.
|
||||
*/
|
||||
class Calendar
|
||||
{
|
||||
public function toIcs(Event $event, string $organizer): string
|
||||
{
|
||||
$end = $event->ends_at ?? ($event->all_day ? $event->starts_at : $event->starts_at->copy()->addHour());
|
||||
|
||||
$lines = [
|
||||
'BEGIN:VCALENDAR',
|
||||
'VERSION:2.0',
|
||||
'PRODID:-//'.$this->escape($organizer).'//Inhaus//DE',
|
||||
'CALSCALE:GREGORIAN',
|
||||
'METHOD:PUBLISH',
|
||||
'BEGIN:VEVENT',
|
||||
'UID:event-'.$event->id.'@'.(parse_url(config('app.url'), PHP_URL_HOST) ?: 'inhaus'),
|
||||
'DTSTAMP:'.now()->utc()->format('Ymd\THis\Z'),
|
||||
];
|
||||
|
||||
if ($event->all_day) {
|
||||
$lines[] = 'DTSTART;VALUE=DATE:'.$event->starts_at->format('Ymd');
|
||||
// DTEND ist bei ganztägigen Terminen exklusiv: der Tag nach dem letzten Tag.
|
||||
$lines[] = 'DTEND;VALUE=DATE:'.$end->copy()->startOfDay()->addDay()->format('Ymd');
|
||||
} else {
|
||||
$lines[] = 'DTSTART:'.$event->starts_at->copy()->utc()->format('Ymd\THis\Z');
|
||||
$lines[] = 'DTEND:'.$end->copy()->utc()->format('Ymd\THis\Z');
|
||||
}
|
||||
|
||||
$lines[] = 'SUMMARY:'.$this->escape($event->title);
|
||||
|
||||
if ($event->location) {
|
||||
$lines[] = 'LOCATION:'.$this->escape($event->location);
|
||||
}
|
||||
|
||||
$description = trim(html_entity_decode(strip_tags(str_replace(['</p>', '<br>'], "\n", (string) $event->description_html))));
|
||||
|
||||
if ($description !== '') {
|
||||
$lines[] = 'DESCRIPTION:'.$this->escape(Str::limit($description, 2000));
|
||||
}
|
||||
|
||||
if ($event->online_url) {
|
||||
$lines[] = 'URL:'.$this->escape($event->online_url);
|
||||
}
|
||||
|
||||
$lines[] = 'END:VEVENT';
|
||||
$lines[] = 'END:VCALENDAR';
|
||||
|
||||
return implode("\r\n", array_map($this->fold(...), $lines))."\r\n";
|
||||
}
|
||||
|
||||
private function escape(string $value): string
|
||||
{
|
||||
return str_replace(['\\', ';', ',', "\r\n", "\n"], ['\\\\', '\;', '\\,', '\\n', '\\n'], $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeilen nach 75 Oktetts umbrechen (Folgezeilen beginnen mit einem Leerzeichen,
|
||||
* das mitzählt), ohne UTF-8-Zeichen zu zerschneiden.
|
||||
*/
|
||||
private function fold(string $line): string
|
||||
{
|
||||
$folded = '';
|
||||
$current = '';
|
||||
$limit = 75;
|
||||
|
||||
foreach (mb_str_split($line) as $char) {
|
||||
if (strlen($current.$char) > $limit) {
|
||||
$folded .= $current."\r\n ";
|
||||
$current = '';
|
||||
$limit = 74;
|
||||
}
|
||||
|
||||
$current .= $char;
|
||||
}
|
||||
|
||||
return $folded.$current;
|
||||
}
|
||||
}
|
||||
29
plugins-core/events/src/Database/Factories/EventFactory.php
Normal file
29
plugins-core/events/src/Database/Factories/EventFactory.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Events\Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Inhaus\Plugins\Events\Models\Event;
|
||||
|
||||
/**
|
||||
* @extends Factory<Event>
|
||||
*/
|
||||
class EventFactory extends Factory
|
||||
{
|
||||
protected $model = Event::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
$start = now()->addDays(fake()->numberBetween(1, 30))->setTime(10, 0);
|
||||
|
||||
return [
|
||||
'title' => fake()->sentence(4),
|
||||
'description' => '<p>'.fake()->paragraph().'</p>',
|
||||
'location' => fake()->city(),
|
||||
'starts_at' => $start,
|
||||
'ends_at' => $start->copy()->addHours(2),
|
||||
'all_day' => false,
|
||||
'is_published' => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
24
plugins-core/events/src/EventsPlugin.php
Normal file
24
plugins-core/events/src/EventsPlugin.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Events;
|
||||
|
||||
use App\Dashboard\Widgets;
|
||||
use App\Models\User;
|
||||
use App\Plugins\Plugin;
|
||||
use App\Support\Abilities;
|
||||
use App\Support\Navigation;
|
||||
use Inhaus\Plugins\Events\Http\Resources\EventResource;
|
||||
use Inhaus\Plugins\Events\Models\Event;
|
||||
|
||||
class EventsPlugin extends Plugin
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->make(Navigation::class)->add('events', 'Termine', '/termine', active: 'events.*', sort: 30);
|
||||
$this->app->make(Abilities::class)->define('events.manage', 'Termine verwalten', 'Termine');
|
||||
|
||||
$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(),
|
||||
], mobileSort: 30);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Events\Filament\Resources\Events;
|
||||
|
||||
use BackedEnum;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\TernaryFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Inhaus\Plugins\Events\Filament\Resources\Events\Pages\CreateEvent;
|
||||
use Inhaus\Plugins\Events\Filament\Resources\Events\Pages\EditEvent;
|
||||
use Inhaus\Plugins\Events\Filament\Resources\Events\Pages\ListEvents;
|
||||
use Inhaus\Plugins\Events\Models\Event;
|
||||
use UnitEnum;
|
||||
|
||||
class EventResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Event::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCalendarDays;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Inhalte';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
protected static ?string $modelLabel = 'Termin';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Termine';
|
||||
|
||||
protected static ?string $slug = 'termine';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'title';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(3)
|
||||
->components([
|
||||
Section::make('Termin')
|
||||
->columnSpan(2)
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('title')->label('Titel')->required()->maxLength(160)->columnSpanFull(),
|
||||
Toggle::make('all_day')->label('Ganztägig')->live()->columnSpanFull(),
|
||||
DateTimePicker::make('starts_at')
|
||||
->label('Beginn')
|
||||
->required()
|
||||
->seconds(false)
|
||||
->native(false)
|
||||
->time(fn (Get $get) => ! $get('all_day'))
|
||||
->displayFormat(fn (Get $get) => $get('all_day') ? 'd.m.Y' : 'd.m.Y H:i'),
|
||||
DateTimePicker::make('ends_at')
|
||||
->label('Ende')
|
||||
->seconds(false)
|
||||
->native(false)
|
||||
->time(fn (Get $get) => ! $get('all_day'))
|
||||
->displayFormat(fn (Get $get) => $get('all_day') ? 'd.m.Y' : 'd.m.Y H:i')
|
||||
->afterOrEqual('starts_at'),
|
||||
TextInput::make('location')->label('Ort')->maxLength(255),
|
||||
TextInput::make('online_url')->label('Online-Link')->url()->maxLength(500)->placeholder('https://…'),
|
||||
RichEditor::make('description')
|
||||
->label('Beschreibung')
|
||||
->toolbarButtons([
|
||||
['bold', 'italic', 'link'],
|
||||
['bulletList', 'orderedList'],
|
||||
['undo', 'redo'],
|
||||
])
|
||||
->columnSpanFull(),
|
||||
]),
|
||||
Section::make('Anzeige')
|
||||
->columnSpan(1)
|
||||
->schema([
|
||||
Toggle::make('is_published')->label('Veröffentlicht')->default(true),
|
||||
FileUpload::make('image_path')
|
||||
->label('Bild')
|
||||
->helperText('Optional, Querformat.')
|
||||
->image()
|
||||
->disk('uploads')
|
||||
->directory('events')
|
||||
->visibility('public')
|
||||
->imageAspectRatio('16:9')
|
||||
->automaticallyCropImagesToAspectRatio()
|
||||
->maxSize(10 * 1024),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('starts_at')
|
||||
->columns([
|
||||
TextColumn::make('starts_at')
|
||||
->label('Datum')
|
||||
->formatStateUsing(fn (Event $record) => $record->starts_at->format($record->all_day ? 'd.m.Y' : 'd.m.Y H:i'))
|
||||
->sortable(),
|
||||
TextColumn::make('title')->label('Titel')->searchable()->limit(60)->weight('medium'),
|
||||
TextColumn::make('location')->label('Ort')->limit(40)->toggleable(),
|
||||
IconColumn::make('is_published')->label('Veröffentlicht')->boolean(),
|
||||
])
|
||||
->filters([
|
||||
TernaryFilter::make('upcoming')
|
||||
->label('Zeitraum')
|
||||
->placeholder('Alle')
|
||||
->trueLabel('Anstehende')
|
||||
->falseLabel('Vergangene')
|
||||
->default(true)
|
||||
->queries(
|
||||
true: fn (Builder $query) => $query->where(fn ($q) => $q->where('ends_at', '>=', now())->orWhere(fn ($q) => $q->whereNull('ends_at')->where('starts_at', '>=', now()->startOfDay()))),
|
||||
false: fn (Builder $query) => $query->where(fn ($q) => $q->where('ends_at', '<', now())->orWhere(fn ($q) => $q->whereNull('ends_at')->where('starts_at', '<', now()->startOfDay()))),
|
||||
),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListEvents::route('/'),
|
||||
'create' => CreateEvent::route('/neu'),
|
||||
'edit' => EditEvent::route('/{record}/bearbeiten'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Events\Filament\Resources\Events\Pages;
|
||||
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Inhaus\Plugins\Events\Filament\Resources\Events\EventResource;
|
||||
|
||||
class CreateEvent extends CreateRecord
|
||||
{
|
||||
protected static string $resource = EventResource::class;
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$data['author_id'] = auth()->id();
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Events\Filament\Resources\Events\Pages;
|
||||
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Inhaus\Plugins\Events\Filament\Resources\Events\EventResource;
|
||||
|
||||
class EditEvent extends EditRecord
|
||||
{
|
||||
protected static string $resource = EventResource::class;
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Events\Filament\Resources\Events\Pages;
|
||||
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Inhaus\Plugins\Events\Filament\Resources\Events\EventResource;
|
||||
|
||||
class ListEvents extends ListRecords
|
||||
{
|
||||
protected static string $resource = EventResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make()->label('Neuer Termin'),
|
||||
];
|
||||
}
|
||||
}
|
||||
46
plugins-core/events/src/Http/Controllers/EventController.php
Normal file
46
plugins-core/events/src/Http/Controllers/EventController.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Events\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\Branding;
|
||||
use Illuminate\Http\Response as HttpResponse;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Inhaus\Plugins\Events\Calendar;
|
||||
use Inhaus\Plugins\Events\Http\Resources\EventResource;
|
||||
use Inhaus\Plugins\Events\Models\Event;
|
||||
|
||||
class EventController extends Controller
|
||||
{
|
||||
public function index(): Response
|
||||
{
|
||||
return Inertia::render('events::Index', [
|
||||
'events' => EventResource::collection(
|
||||
Event::query()->upcoming()->limit(200)->get()
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Event $event): Response
|
||||
{
|
||||
abort_unless($event->is_published, 404);
|
||||
|
||||
return Inertia::render('events::Show', [
|
||||
'event' => [
|
||||
...(new EventResource($event))->resolve(),
|
||||
'description_html' => $event->description_html,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function ics(Event $event, Calendar $calendar, Branding $branding): HttpResponse
|
||||
{
|
||||
abort_unless($event->is_published, 404);
|
||||
|
||||
return response($calendar->toIcs($event, $branding->portalName()), 200, [
|
||||
'Content-Type' => 'text/calendar; charset=utf-8',
|
||||
'Content-Disposition' => 'attachment; filename="termin-'.$event->id.'.ics"',
|
||||
]);
|
||||
}
|
||||
}
|
||||
31
plugins-core/events/src/Http/Resources/EventResource.php
Normal file
31
plugins-core/events/src/Http/Resources/EventResource.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Events\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Inhaus\Plugins\Events\Models\Event;
|
||||
|
||||
/**
|
||||
* @mixin Event
|
||||
*/
|
||||
class EventResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'location' => $this->location,
|
||||
'online_url' => $this->online_url,
|
||||
'starts_at' => $this->starts_at->toIso8601String(),
|
||||
'ends_at' => $this->ends_at?->toIso8601String(),
|
||||
'all_day' => $this->all_day,
|
||||
'image_url' => $this->imageUrl('large'),
|
||||
'thumb_url' => $this->imageUrl('thumb'),
|
||||
];
|
||||
}
|
||||
}
|
||||
99
plugins-core/events/src/Models/Event.php
Normal file
99
plugins-core/events/src/Models/Event.php
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Events\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Support\Images;
|
||||
use App\Support\RichText;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
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',
|
||||
])]
|
||||
class Event extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected static function newFactory(): EventFactory
|
||||
{
|
||||
return EventFactory::new();
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saving(function (Event $event): void {
|
||||
if ($event->isDirty('description') || $event->description_html === null) {
|
||||
$event->description_html = app(RichText::class)->toSafeHtml($event->description);
|
||||
}
|
||||
});
|
||||
|
||||
// Bildvarianten erzeugen bzw. beim Austausch die alten Dateien entfernen.
|
||||
static::saved(function (Event $event): void {
|
||||
if (! $event->wasRecentlyCreated && ! $event->wasChanged('image_path')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$previous = $event->wasRecentlyCreated ? null : $event->getOriginal('image_path');
|
||||
|
||||
if ($previous && $previous !== $event->image_path) {
|
||||
app(Images::class)->deleteWithVariants($previous);
|
||||
}
|
||||
|
||||
if ($event->image_path) {
|
||||
app(Images::class)->createVariants($event->image_path);
|
||||
}
|
||||
});
|
||||
|
||||
static::deleted(fn (Event $event) => app(Images::class)->deleteWithVariants($event->image_path));
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'starts_at' => 'datetime',
|
||||
'ends_at' => 'datetime',
|
||||
'all_day' => 'boolean',
|
||||
'is_published' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function author(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Veröffentlichte Termine, die noch nicht vorbei sind (laufende eingeschlossen).
|
||||
*
|
||||
* @param Builder<Event> $query
|
||||
*/
|
||||
public function scopeUpcoming(Builder $query): void
|
||||
{
|
||||
$query->where('is_published', true)
|
||||
->where(fn (Builder $q) => $q
|
||||
->where('ends_at', '>=', now())
|
||||
->orWhere(fn (Builder $q) => $q->whereNull('ends_at')->where('starts_at', '>=', now()->startOfDay())))
|
||||
->orderBy('starts_at');
|
||||
}
|
||||
|
||||
public function imageUrl(string $variant = 'large'): ?string
|
||||
{
|
||||
return app(Images::class)->url($this->image_path, $variant);
|
||||
}
|
||||
|
||||
/**
|
||||
* Nur Einträge, die diese Person sehen darf (Zielgruppen). Platzhalter bis Phase 2c.
|
||||
*
|
||||
* @param Builder<Event> $query
|
||||
*/
|
||||
public function scopeVisibleTo(Builder $query, ?User $user): void {}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue