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
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:
parent
435960725d
commit
ee8dde93c0
262 changed files with 2385 additions and 692 deletions
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* Freiwillige Geburtstagsliste: nur Tag und Monat – kein Geburtsjahr, kein Alter.
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('birthdays', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->unique()->constrained('users')->cascadeOnDelete();
|
||||
$table->unsignedTinyInteger('month');
|
||||
$table->unsignedTinyInteger('day');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['month', 'day']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('birthdays');
|
||||
}
|
||||
};
|
||||
14
plugins-core/birthdays/plugin.json
Normal file
14
plugins-core/birthdays/plugin.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"slug": "birthdays",
|
||||
"name": "Geburtstage",
|
||||
"version": "1.0.0",
|
||||
"description": "Geburtstagsliste zum Mitmachen: Wer möchte, trägt Tag und Monat im Profil ein. Mit Kachel auf der Startseite und Glückwunsch am eigenen Geburtstag.",
|
||||
"author": "Inhaus",
|
||||
"namespace": "Inhaus\\Plugins\\Birthdays\\",
|
||||
"class": "Inhaus\\Plugins\\Birthdays\\BirthdaysPlugin",
|
||||
"enabled_by_default": false,
|
||||
"requires": {
|
||||
"core": ">=0.6.0",
|
||||
"php": ">=8.3"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<script setup>
|
||||
import BirthdayItem from '../components/BirthdayItem.vue';
|
||||
|
||||
defineProps({ block: { type: Object, required: true } });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section>
|
||||
<h3 v-if="block.data.title" class="mb-3 text-lg font-semibold">{{ block.data.title }}</h3>
|
||||
<div class="divide-y rounded-lg border bg-card px-4">
|
||||
<BirthdayItem v-for="item in block.props?.birthdays ?? []" :key="`${item.person.id}-${item.date}`" :item="item" />
|
||||
<p v-if="!(block.props?.birthdays ?? []).length" class="py-3 text-sm text-muted-foreground">Keine anstehenden Geburtstage.</p>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<script setup>
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import { Cake } from '@lucide/vue';
|
||||
import PersonAvatar from '@/components/PersonAvatar.vue';
|
||||
|
||||
defineProps({
|
||||
item: { type: Object, required: true },
|
||||
});
|
||||
|
||||
const day = (iso) => new Intl.DateTimeFormat('de-DE', { day: 'numeric', month: 'long' }).format(new Date(`${iso}T12:00:00`));
|
||||
const weekday = (iso) => new Intl.DateTimeFormat('de-DE', { weekday: 'short' }).format(new Date(`${iso}T12:00:00`));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Link :href="`/personen/${item.person.id}`" class="group flex items-center gap-3 py-2.5">
|
||||
<span class="relative shrink-0">
|
||||
<PersonAvatar :person="item.person" class="size-10" />
|
||||
<span v-if="item.today" class="absolute -right-1 -bottom-1 grid size-5 place-items-center rounded-full bg-brand text-brand-foreground ring-2 ring-card"><Cake class="size-3" /></span>
|
||||
</span>
|
||||
<span class="min-w-0 flex-1">
|
||||
<span class="block truncate text-sm font-medium group-hover:underline">{{ item.person.name }}</span>
|
||||
<span class="block truncate text-xs text-muted-foreground">{{ item.person.job_title || item.person.department }}</span>
|
||||
</span>
|
||||
<span class="shrink-0 text-right text-xs" :class="item.today ? 'font-semibold text-brand-text' : 'text-muted-foreground'">
|
||||
{{ item.today ? 'Heute' : `${weekday(item.date)}, ${day(item.date)}` }}
|
||||
</span>
|
||||
</Link>
|
||||
</template>
|
||||
52
plugins-core/birthdays/resources/js/pages/Index.vue
Normal file
52
plugins-core/birthdays/resources/js/pages/Index.vue
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import { Cake } from '@lucide/vue';
|
||||
import EmptyState from '@/components/EmptyState.vue';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
import BirthdayItem from '../components/BirthdayItem.vue';
|
||||
|
||||
const props = defineProps({
|
||||
birthdays: { type: Array, required: true },
|
||||
scope: { type: String, required: true },
|
||||
registered: { type: Boolean, default: false },
|
||||
});
|
||||
|
||||
// Nach Tagen gruppiert: „Heute“, dann die folgenden Tage
|
||||
const groups = computed(() => {
|
||||
const result = [];
|
||||
|
||||
for (const item of props.birthdays) {
|
||||
const last = result.at(-1);
|
||||
last && last.date === item.date ? last.items.push(item) : result.push({ date: item.date, today: item.today, items: [item] });
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
const label = (group) => group.today ? 'Heute' : new Intl.DateTimeFormat('de-DE', { weekday: 'long', day: 'numeric', month: 'long' }).format(new Date(`${group.date}T12:00:00`));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout title="Geburtstage">
|
||||
<div class="mx-auto max-w-3xl">
|
||||
<h1 class="text-2xl font-semibold tracking-tight">Geburtstage</h1>
|
||||
<p class="mt-1 text-sm text-muted-foreground">Die nächsten 30 Tage · {{ scope }}</p>
|
||||
|
||||
<p v-if="!registered" class="mt-5 rounded-lg border bg-card px-4 py-3 text-sm">
|
||||
Sie möchten auch in der Liste stehen? Tragen Sie Tag und Monat unter
|
||||
<Link href="/profil/bearbeiten" class="font-medium text-brand-text hover:underline">Profil bearbeiten</Link> ein.
|
||||
</p>
|
||||
|
||||
<div v-if="groups.length" class="mt-6 grid gap-5">
|
||||
<section v-for="group in groups" :key="group.date" class="rounded-lg border bg-card">
|
||||
<h2 class="border-b px-5 py-3 text-sm font-semibold" :class="group.today ? 'text-brand-text' : ''">{{ label(group) }}</h2>
|
||||
<div class="divide-y px-5">
|
||||
<BirthdayItem v-for="item in group.items" :key="item.person.id" :item="item" />
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<div v-else class="mt-6 rounded-lg border bg-card"><EmptyState :icon="Cake" title="Keine Geburtstage in den nächsten 30 Tagen" /></div>
|
||||
</div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
import { router, useForm } from '@inertiajs/vue3';
|
||||
import { Cake, LoaderCircle } from '@lucide/vue';
|
||||
import { toast } from 'vue-sonner';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import FormField from '@/components/FormField.vue';
|
||||
import NativeSelect from '@/components/NativeSelect.vue';
|
||||
import Panel from '@/components/Panel.vue';
|
||||
|
||||
const props = defineProps({
|
||||
birthday: { type: Object, default: null },
|
||||
months: { type: Array, required: true },
|
||||
scope: { type: String, default: 'all' },
|
||||
});
|
||||
|
||||
const form = useForm({ day: props.birthday?.day ?? null, month: props.birthday?.month ?? null });
|
||||
const days = computed(() => Array.from({ length: 31 }, (_, i) => ({ value: i + 1, label: String(i + 1) })));
|
||||
|
||||
const audience = { all: 'allen Mitarbeitenden', department: 'Ihrer Abteilung', location: 'Ihrem Standort' };
|
||||
|
||||
function save() {
|
||||
form.put('/profil/geburtstag', {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
form.defaults();
|
||||
toast.success('Geburtstag gespeichert');
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function remove() {
|
||||
router.delete('/profil/geburtstag', {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
form.day = null;
|
||||
form.month = null;
|
||||
form.defaults();
|
||||
toast.success('Aus der Geburtstagsliste entfernt');
|
||||
},
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Panel title="Geburtstag">
|
||||
<form class="grid gap-4" @submit.prevent="save">
|
||||
<p class="flex gap-2 text-sm text-muted-foreground">
|
||||
<Cake class="mt-0.5 size-4 shrink-0 text-brand-text" />
|
||||
<span>Freiwillig: Wenn Sie Tag und Monat eintragen, erscheint Ihr Geburtstag in der Geburtstagsliste und ist {{ audience[scope] }} sichtbar. Das Geburtsjahr wird nicht erfasst. Austragen ist jederzeit möglich.</span>
|
||||
</p>
|
||||
<div class="grid grid-cols-2 gap-4 sm:max-w-sm">
|
||||
<FormField id="birthday-day" label="Tag" :error="form.errors.day">
|
||||
<NativeSelect id="birthday-day" v-model="form.day" :options="days" placeholder="–" />
|
||||
</FormField>
|
||||
<FormField id="birthday-month" label="Monat" :error="form.errors.month">
|
||||
<NativeSelect id="birthday-month" v-model="form.month" :options="months" placeholder="–" />
|
||||
</FormField>
|
||||
</div>
|
||||
<div class="flex justify-end gap-2 border-t pt-4">
|
||||
<Button v-if="birthday" type="button" variant="ghost" class="text-destructive hover:text-destructive" @click="remove">Austragen</Button>
|
||||
<Button type="submit" :disabled="form.processing || !form.day || !form.month || !form.isDirty">
|
||||
<LoaderCircle v-if="form.processing" class="animate-spin" />
|
||||
{{ birthday ? 'Speichern' : 'Eintragen' }}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Panel>
|
||||
</template>
|
||||
55
plugins-core/birthdays/resources/js/widgets/Greeting.vue
Normal file
55
plugins-core/birthdays/resources/js/widgets/Greeting.vue
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { Cake, X } from '@lucide/vue';
|
||||
|
||||
/**
|
||||
* Glückwunsch am eigenen Geburtstag – lässt sich für heute ausblenden.
|
||||
*/
|
||||
const props = defineProps({
|
||||
name: { type: String, required: true },
|
||||
});
|
||||
|
||||
const key = `inhaus.birthday-greeting.${new Date().toISOString().slice(0, 10)}`;
|
||||
const hidden = ref(false);
|
||||
|
||||
try {
|
||||
hidden.value = localStorage.getItem(key) === '1';
|
||||
} catch {
|
||||
// Speicher nicht verfügbar – dann eben immer zeigen.
|
||||
}
|
||||
|
||||
function dismiss() {
|
||||
hidden.value = true;
|
||||
|
||||
try {
|
||||
localStorage.setItem(key, '1');
|
||||
} catch {
|
||||
// ignorieren
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section v-if="!hidden" class="relative overflow-hidden rounded-lg bg-brand text-brand-foreground" role="status">
|
||||
<!-- dezente Konfetti-Punkte -->
|
||||
<svg class="pointer-events-none absolute inset-0 size-full opacity-25" aria-hidden="true">
|
||||
<circle cx="8%" cy="30%" r="4" fill="currentColor" />
|
||||
<circle cx="15%" cy="75%" r="3" fill="currentColor" />
|
||||
<rect x="24%" y="18%" width="7" height="7" transform="rotate(20)" fill="currentColor" />
|
||||
<circle cx="62%" cy="20%" r="3" fill="currentColor" />
|
||||
<circle cx="78%" cy="70%" r="5" fill="currentColor" />
|
||||
<rect x="88%" y="30%" width="8" height="8" fill="currentColor" />
|
||||
<circle cx="94%" cy="80%" r="3" fill="currentColor" />
|
||||
</svg>
|
||||
<div class="relative flex items-center gap-4 px-5 py-5 sm:px-8">
|
||||
<span class="grid size-12 shrink-0 place-items-center rounded-full bg-white/15"><Cake class="size-6" /></span>
|
||||
<div class="min-w-0 flex-1">
|
||||
<p class="text-xl font-semibold tracking-tight">Alles Gute zum Geburtstag, {{ props.name }}!</p>
|
||||
<p class="mt-0.5 text-sm opacity-90">Wir wünschen Ihnen einen schönen Tag.</p>
|
||||
</div>
|
||||
<button type="button" class="grid size-9 shrink-0 place-items-center rounded-md hover:bg-white/15" aria-label="Glückwunsch ausblenden" @click="dismiss">
|
||||
<X class="size-5" />
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
17
plugins-core/birthdays/resources/js/widgets/Upcoming.vue
Normal file
17
plugins-core/birthdays/resources/js/widgets/Upcoming.vue
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<script setup>
|
||||
import Panel from '@/components/Panel.vue';
|
||||
import BirthdayItem from '../components/BirthdayItem.vue';
|
||||
|
||||
defineProps({
|
||||
birthdays: { type: Array, required: true },
|
||||
days: { type: Number, default: 7 },
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Panel title="Geburtstage" action-label="Alle" action-href="/geburtstage">
|
||||
<div class="-my-2 divide-y">
|
||||
<BirthdayItem v-for="item in birthdays" :key="`${item.person.id}-${item.date}`" :item="item" />
|
||||
</div>
|
||||
</Panel>
|
||||
</template>
|
||||
10
plugins-core/birthdays/routes/web.php
Normal file
10
plugins-core/birthdays/routes/web.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Inhaus\Plugins\Birthdays\Http\Controllers\BirthdayController;
|
||||
|
||||
Route::middleware('auth')->group(function () {
|
||||
Route::get('/geburtstage', [BirthdayController::class, 'index'])->name('birthdays.index');
|
||||
Route::put('/profil/geburtstag', [BirthdayController::class, 'update'])->name('birthdays.update');
|
||||
Route::delete('/profil/geburtstag', [BirthdayController::class, 'destroy'])->name('birthdays.destroy');
|
||||
});
|
||||
95
plugins-core/birthdays/src/BirthdayList.php
Normal file
95
plugins-core/birthdays/src/BirthdayList.php
Normal 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')]);
|
||||
}
|
||||
}
|
||||
60
plugins-core/birthdays/src/BirthdaysPlugin.php
Normal file
60
plugins-core/birthdays/src/BirthdaysPlugin.php
Normal 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));
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
46
plugins-core/birthdays/src/Models/Birthday.php
Normal file
46
plugins-core/birthdays/src/Models/Birthday.php
Normal 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();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue