Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 6m51s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m48s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m16s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m21s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 9m30s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 9m44s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 8m49s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 8m37s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 44s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m8s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
88 lines
4.7 KiB
PHP
88 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace Inhaus\Plugins\Events;
|
|
|
|
use App\Dashboard\Widgets;
|
|
use App\Digest\Digest;
|
|
use App\Editorial\Editorial;
|
|
use App\Media\ImagePaths;
|
|
use App\Media\MediaUsages;
|
|
use App\Models\User;
|
|
use App\Pagebuilder\Blocks;
|
|
use App\Pagebuilder\BlockType;
|
|
use App\Pagebuilder\Field;
|
|
use App\Plugins\Plugin;
|
|
use App\Search\GlobalSearch;
|
|
use App\Support\Abilities;
|
|
use App\Support\Navigation;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Inhaus\Plugins\Events\Http\Resources\EventResource;
|
|
use Inhaus\Plugins\Events\Models\Event;
|
|
use Inhaus\Plugins\Events\Policies\EventPolicy;
|
|
|
|
class EventsPlugin extends Plugin
|
|
{
|
|
public function register(): void
|
|
{
|
|
// Wochenüberblick: Termine der nächsten zwei Wochen
|
|
$this->app->make(Digest::class)->add('events', 'Termine', 20, fn (User $user) => Event::query()
|
|
->upcoming()->visibleTo($user)->where('starts_at', '<=', now()->addDays(14))->limit(8)->get()
|
|
->map(fn (Event $event) => [
|
|
'title' => $event->title,
|
|
'url' => route('events.show', $event),
|
|
'meta' => collect([
|
|
$event->starts_at->timezone(config('app.timezone'))->translatedFormat($event->all_day ? 'D, d.m.' : 'D, d.m., H:i \\U\\h\\r'),
|
|
$event->location,
|
|
$event->registration_enabled ? 'mit Anmeldung' : null,
|
|
])->filter()->implode(' · '),
|
|
])->all());
|
|
|
|
$this->app->make(GlobalSearch::class)->add('events', 'Termine', 'calendar-days', fn (...$args) => app(EventSearch::class)(...$args), sort: 20);
|
|
|
|
$this->app->make(Navigation::class)->add('events', 'Termine', '/termine', active: 'events.*', sort: 30, icon: 'calendar-days');
|
|
$this->app->make(Abilities::class)->define('events.manage', 'Termine verwalten', 'Termine', portal: true);
|
|
Gate::policy(Event::class, EventPolicy::class);
|
|
|
|
// Mediathek „Eingebunden in“
|
|
$usages = $this->app->make(MediaUsages::class);
|
|
$usages->add('events', 'Termine', fn (Event $event) => [
|
|
['context' => 'Titelbild', 'label' => $event->title, 'url' => route('events.show', $event, false), 'draft' => $event->is_published === false, 'paths' => [$event->image_path]],
|
|
['context' => ImagePaths::HTML_CONTEXT, 'label' => $event->title, 'url' => route('events.show', $event, false), 'draft' => $event->is_published === false, 'paths' => ImagePaths::fromHtml($event->description_html)],
|
|
], 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(Editorial::class)->meta('events', icon: 'calendar-days',
|
|
create: fn (User $user) => $user->can('events.manage') ? ['label' => 'Neuer Termin', 'href' => route('events.create')] : null);
|
|
|
|
$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);
|
|
|
|
$this->app->make(Blocks::class)->add(BlockType::make('events.upcoming', 'Termine', 'calendar-days', 'dynamic', 'events::UpcomingEvents')
|
|
->description('Die nächsten Termine.')
|
|
->fields([
|
|
Field::text('title', 'Überschrift', 150, 'Termine'),
|
|
Field::number('count', 'Anzahl', 1, 12, 4),
|
|
])
|
|
->resolveUsing(fn (array $data, ?User $user) => [
|
|
'events' => EventResource::collection(Event::query()->upcoming()->visibleTo($user)->limit($data['count'])->get())->resolve(),
|
|
]));
|
|
}
|
|
}
|