Feste Profilfelder in Formularen, Geburtstage, anpassbare Startseite
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m18s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m21s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m40s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m34s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 3m8s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 3m6s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m43s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m47s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m1s

- Formulare: Felder fest aus dem Profil (nicht änderbar, Server setzt den
  Profilwert ein), Hinweis bei fehlender Profilangabe
- Geburtstage (optionales Plugin, standardmäßig aus): Tag und Monat freiwillig
  im Profil, Kachel, Liste /geburtstage, Pagebuilder-Block, Glückwunsch am
  eigenen Geburtstag; Sichtbarkeit alle/Abteilung/Standort
- Startseite: Kacheln je Bereich sortieren und ausblenden; eigene Kacheln
  (Bild mit Link, Text, Hinweis) mit Zeitraum und Zielgruppe
- Kern: optionale mitgelieferte Plugins, Startseitenbereich „top“,
  Profilabschnitte für Plugins, Kachel-Bezeichnungen

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 09:51:19 +00:00
parent 435960725d
commit ee8dde93c0
262 changed files with 2385 additions and 692 deletions

View file

@ -0,0 +1,95 @@
<?php
namespace Inhaus\Plugins\Birthdays;
use App\Http\Resources\PersonResource;
use App\Models\User;
use App\Support\Settings;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Inhaus\Plugins\Birthdays\Models\Birthday;
/**
* Anstehende Geburtstage für eine Person – je nach Einstellung aus dem ganzen
* Haus, der eigenen Abteilung oder dem eigenen Standort.
*/
class BirthdayList
{
public const SCOPES = [
'all' => 'Alle Mitarbeitenden',
'department' => 'Nur die eigene Abteilung',
'location' => 'Nur der eigene Standort',
];
public function __construct(private readonly Settings $settings) {}
public function scope(): string
{
return array_key_exists($s = (string) $this->settings->get('birthdays.scope', 'all'), self::SCOPES) ? $s : 'all';
}
public function daysAhead(): int
{
return max(0, min(60, (int) $this->settings->get('birthdays.days', 7)));
}
public function greetingEnabled(): bool
{
return (bool) $this->settings->get('birthdays.greeting', true);
}
/**
* @return list<array{date: string, today: bool, person: array<string, mixed>}>
*/
public function upcoming(User $viewer, ?int $days = null, ?string $scope = null, int $limit = 200): array
{
$days ??= $this->daysAhead();
$scope ??= $this->scope();
$today = Carbon::today();
$end = $today->copy()->addDays($days);
// Nur die betroffenen Monate laden (höchstens drei), dann genau filtern.
$months = collect(range(0, (int) $today->copy()->startOfMonth()->diffInMonths($end->copy()->startOfMonth())))
->map(fn ($i) => $today->copy()->startOfMonth()->addMonths($i)->month)->unique()->values()->all();
$birthdays = Birthday::query()
->whereIn('month', $months)
->whereHas('user', function ($q) use ($viewer, $scope) {
$q->where('is_active', true);
if ($scope === 'department') {
$viewer->department ? $q->where('department', $viewer->department) : $q->whereKey($viewer->id);
} elseif ($scope === 'location') {
$viewer->location ? $q->where('location', $viewer->location) : $q->whereKey($viewer->id);
}
})
->with('user')
->get();
return $birthdays
->map(fn (Birthday $b) => ['birthday' => $b, 'date' => $b->nextOccurrence($today)])
->filter(fn ($row) => $row['date']->lte($end))
->sortBy(fn ($row) => $row['date']->format('Ymd').mb_strtolower($row['birthday']->user->last_name.' '.$row['birthday']->user->first_name))
->take($limit)
->map(fn ($row) => [
'date' => $row['date']->toDateString(),
'today' => $row['date']->isSameDay($today),
'person' => (new PersonResource($row['birthday']->user))->resolve(),
])
->values()
->all();
}
public function isBirthdayToday(User $user): bool
{
return (bool) Birthday::query()->where('user_id', $user->id)->first()?->isOn(Carbon::today());
}
/**
* @return Collection<int, string>
*/
public static function months(): Collection
{
return collect(range(1, 12))->mapWithKeys(fn ($m) => [$m => Carbon::create(2000, $m, 1)->locale('de')->translatedFormat('F')]);
}
}

View file

@ -0,0 +1,60 @@
<?php
namespace Inhaus\Plugins\Birthdays;
use App\Dashboard\Widgets;
use App\Models\User;
use App\Pagebuilder\Blocks;
use App\Pagebuilder\BlockType;
use App\Pagebuilder\Field;
use App\Plugins\Plugin;
use App\Profile\ProfileSections;
use Inhaus\Plugins\Birthdays\Models\Birthday;
/**
* Freiwillige Geburtstagsliste. Standardmäßig aus – im Admin unter „Plugins“ aktivierbar.
*/
class BirthdaysPlugin extends Plugin
{
public function register(): void
{
$this->app->singleton(BirthdayList::class);
$this->app->make(ProfileSections::class)->add('birthday', 'birthdays::ProfileBirthday', 10, function (User $user) {
$birthday = Birthday::query()->where('user_id', $user->id)->first();
return [
'birthday' => $birthday ? ['day' => $birthday->day, 'month' => $birthday->month] : null,
'months' => BirthdayList::months()->map(fn ($label, $value) => ['value' => $value, 'label' => $label])->values(),
'scope' => app(BirthdayList::class)->scope(),
];
});
$widgets = $this->app->make(Widgets::class);
// Glückwunsch oben auf der Startseite – nur am eigenen Geburtstag.
$widgets->add('birthdays.greeting', 'birthdays::Greeting', 'top', sort: 0, props: function (User $user) {
$list = app(BirthdayList::class);
return $list->greetingEnabled() && $list->isBirthdayToday($user) ? ['name' => $user->first_name ?: $user->name] : null;
}, label: 'Geburtstagsgruß (am eigenen Geburtstag)', mobileSort: -100);
$widgets->add('birthdays.upcoming', 'birthdays::Upcoming', 'aside', sort: 30, props: function (User $user) {
$list = app(BirthdayList::class);
$upcoming = $list->upcoming($user, limit: 8);
return $upcoming === [] ? null : ['birthdays' => $upcoming, 'days' => $list->daysAhead()];
}, label: 'Geburtstage', mobileSort: 35);
$this->app->make(Blocks::class)->add(BlockType::make('birthdays.list', 'Geburtstage', 'cake', 'dynamic', 'birthdays::BirthdaysBlock')
->description('Anstehende Geburtstage – z. B. auf der Seite einer Abteilung.')
->fields([
Field::text('title', 'Überschrift', 150, 'Geburtstage'),
Field::select('scope', 'Wessen Geburtstage', ['' => 'Wie in den Einstellungen'] + BirthdayList::SCOPES, ''),
Field::number('days', 'Tage im Voraus', 0, 60, 14),
])
->resolveUsing(fn (array $data, ?User $user) => $user ? [
'birthdays' => app(BirthdayList::class)->upcoming($user, $data['days'], $data['scope'] ?: null, 30),
] : null));
}
}

View file

@ -0,0 +1,69 @@
<?php
namespace Inhaus\Plugins\Birthdays\Filament\Pages;
use App\Support\Settings;
use BackedEnum;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Inhaus\Plugins\Birthdays\BirthdayList;
use Inhaus\Plugins\Birthdays\Models\Birthday;
use UnitEnum;
class BirthdaySettings extends Page
{
protected string $view = 'filament.pages.settings-form';
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCake;
protected static string|UnitEnum|null $navigationGroup = 'Portal';
protected static ?int $navigationSort = 30;
protected static ?string $navigationLabel = 'Geburtstage';
protected static ?string $title = 'Geburtstage';
protected static ?string $slug = 'geburtstage';
/** @var array<string, mixed>|null */
public ?array $data = [];
public static function canAccess(): bool
{
return auth()->user()?->can('appearance.manage') ?? false;
}
public function mount(BirthdayList $list): void
{
$this->form->fill(['scope' => $list->scope(), 'days' => $list->daysAhead(), 'greeting' => $list->greetingEnabled()]);
}
public function form(Schema $schema): Schema
{
return $schema->statePath('data')->components([
Section::make('Geburtstagsliste')
->description(fn () => 'Mitarbeitende tragen sich freiwillig im Profil ein (nur Tag und Monat). Derzeit eingetragen: '.Birthday::query()->count().'.')
->columns(2)
->schema([
Select::make('scope')->label('Wer sieht wessen Geburtstag')->options(BirthdayList::SCOPES)->required()->native(false),
TextInput::make('days')->label('Tage im Voraus auf der Startseite')->numeric()->minValue(0)->maxValue(60)->required(),
Toggle::make('greeting')->label('Am eigenen Geburtstag auf der Startseite gratulieren')->columnSpanFull(),
]),
]);
}
public function save(Settings $settings): void
{
$state = $this->form->getState();
$settings->setMany(['birthdays.scope' => $state['scope'], 'birthdays.days' => (int) $state['days'], 'birthdays.greeting' => (bool) $state['greeting']]);
Notification::make()->success()->title('Gespeichert')->send();
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace Inhaus\Plugins\Birthdays\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Inertia\Inertia;
use Inertia\Response;
use Inhaus\Plugins\Birthdays\BirthdayList;
use Inhaus\Plugins\Birthdays\Models\Birthday;
class BirthdayController extends Controller
{
public function index(Request $request, BirthdayList $list): Response
{
return Inertia::render('birthdays::Index', [
'birthdays' => $list->upcoming($request->user(), 30),
'scope' => BirthdayList::SCOPES[$list->scope()],
'registered' => Birthday::query()->where('user_id', $request->user()->id)->exists(),
]);
}
public function update(Request $request): RedirectResponse
{
$data = $request->validate([
'day' => ['required', 'integer', 'between:1,31'],
'month' => ['required', 'integer', 'between:1,12'],
], [], ['day' => 'Tag', 'month' => 'Monat']);
// Gültiger Tag im Monat (29. Februar erlaubt).
if (! checkdate($data['month'], $data['day'], 2000)) {
throw ValidationException::withMessages(['day' => 'Diesen Tag gibt es im gewählten Monat nicht.']);
}
Birthday::query()->updateOrCreate(['user_id' => $request->user()->id], $data);
return back()->with('status', 'birthday-saved');
}
public function destroy(Request $request): RedirectResponse
{
Birthday::query()->where('user_id', $request->user()->id)->delete();
return back()->with('status', 'birthday-removed');
}
}

View file

@ -0,0 +1,46 @@
<?php
namespace Inhaus\Plugins\Birthdays\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;
#[Fillable(['user_id', 'month', 'day'])]
class Birthday extends Model
{
/**
* @return BelongsTo<User, $this>
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* Nächster Geburtstag ab $from (heute eingeschlossen). Der 29. Februar
* wird in Nicht-Schaltjahren am 28. Februar gefeiert.
*/
public function nextOccurrence(Carbon $from): Carbon
{
$date = self::inYear($from->year, $this->month, $this->day);
return $date->lt($from->copy()->startOfDay()) ? self::inYear($from->year + 1, $this->month, $this->day) : $date;
}
public function isOn(Carbon $date): bool
{
return self::inYear($date->year, $this->month, $this->day)->isSameDay($date);
}
private static function inYear(int $year, int $month, int $day): Carbon
{
if ($month === 2 && $day === 29 && ! Carbon::create($year)->isLeapYear()) {
$day = 28;
}
return Carbon::create($year, $month, $day)->startOfDay();
}
}