Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m49s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m19s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m29s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m39s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 9m38s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 9m25s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 7m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 8m4s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 46s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m9s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
98 lines
4 KiB
PHP
98 lines
4 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Pages;
|
||
|
||
use App\Digest\Digest;
|
||
use App\Models\User;
|
||
use App\Support\Audit;
|
||
use App\Support\Settings;
|
||
use BackedEnum;
|
||
use Filament\Actions\Action;
|
||
use Filament\Forms\Components\Select;
|
||
use Filament\Forms\Components\Toggle;
|
||
use Filament\Notifications\Notification;
|
||
use Filament\Pages\Page;
|
||
use Filament\Schemas\Components\Section;
|
||
use Filament\Schemas\Components\Text;
|
||
use Filament\Schemas\Schema;
|
||
use Filament\Support\Icons\Heroicon;
|
||
use UnitEnum;
|
||
|
||
/**
|
||
* Wochenüberblick per E-Mail: Versandtag und -uhrzeit. Bekommen nur Personen, die ihn
|
||
* im Profil einschalten.
|
||
*/
|
||
class DigestSettings extends Page
|
||
{
|
||
protected string $view = 'filament.pages.settings-form';
|
||
|
||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedNewspaper;
|
||
|
||
protected static string|UnitEnum|null $navigationGroup = 'Portal';
|
||
|
||
protected static ?int $navigationSort = 30;
|
||
|
||
protected static ?string $navigationLabel = 'Wochenüberblick';
|
||
|
||
protected static ?string $title = 'Wochenüberblick per E-Mail';
|
||
|
||
protected static ?string $slug = 'wochenueberblick';
|
||
|
||
/** @var array<string, mixed>|null */
|
||
public ?array $data = [];
|
||
|
||
public static function canAccess(): bool
|
||
{
|
||
return auth()->user()?->can('appearance.manage') ?? false;
|
||
}
|
||
|
||
public function mount(Digest $digest): void
|
||
{
|
||
$this->form->fill(['enabled' => $digest->enabled(), 'weekday' => $digest->weekday(), 'hour' => $digest->hour()]);
|
||
}
|
||
|
||
public function form(Schema $schema): Schema
|
||
{
|
||
$subscribers = User::query()->active()->where('weekly_digest', true)->count();
|
||
|
||
return $schema
|
||
->components([
|
||
Section::make('Versand')
|
||
->columns(2)
|
||
->schema([
|
||
Text::make('Eine E-Mail mit Neuigkeiten, Terminen, offenen Umfragen, neuen Ideen und Stellen der letzten Woche – jeweils nur, was die Person im Portal sehen darf. Sie geht nur an Personen, die den Wochenüberblick in ihrem Profil einschalten (derzeit '.$subscribers.'). Ohne Neues in der Woche wird nichts verschickt.')->columnSpanFull(),
|
||
Toggle::make('enabled')->label('Wochenüberblick anbieten')->helperText('Ausgeschaltet verschwindet die Option im Profil, es wird nichts verschickt.')->columnSpanFull(),
|
||
Select::make('weekday')->label('Tag')->options(Digest::WEEKDAYS)->required()->native(false)->selectablePlaceholder(false),
|
||
Select::make('hour')->label('Ab Uhrzeit')->required()->native(false)->selectablePlaceholder(false)
|
||
->options(collect(range(5, 20))->mapWithKeys(fn ($h) => [$h => sprintf('%02d:00 Uhr', $h)])->all())
|
||
->helperText('Mit Cronjob pünktlich, ohne Cron beim nächsten Seitenaufruf danach.'),
|
||
]),
|
||
])
|
||
->statePath('data');
|
||
}
|
||
|
||
public function save(Settings $settings): void
|
||
{
|
||
$state = $this->form->getState();
|
||
$settings->setMany(['digest.enabled' => (bool) $state['enabled'], 'digest.weekday' => (int) $state['weekday'], 'digest.hour' => (int) $state['hour']]);
|
||
Audit::log('digest.settings_updated', $state);
|
||
|
||
Notification::make()->success()->title('Gespeichert')->send();
|
||
}
|
||
|
||
protected function getHeaderActions(): array
|
||
{
|
||
return [
|
||
Action::make('preview')
|
||
->label('Vorschau an mich senden')
|
||
->icon(Heroicon::OutlinedPaperAirplane)
|
||
->color('gray')
|
||
->action(function (Digest $digest) {
|
||
$user = auth()->user();
|
||
$digest->sendTo($user, now()->toImmutable()->subDays(7))
|
||
? Notification::make()->success()->title('Vorschau an '.$user->email.' verschickt')->send()
|
||
: Notification::make()->warning()->title('In der letzten Woche gab es nichts Neues – es wurde nichts verschickt.')->send();
|
||
}),
|
||
];
|
||
}
|
||
}
|