|null */ public ?array $data = []; public static function canAccess(): bool { return CommunicationAccess::inbox(); } public function getTitle(): string|Htmlable { return 'Kommunikation: Einstellungen'; } public function getSubheading(): string|Htmlable|null { return 'Wer bei einer neuen Anfrage benachrichtigt wird und wie lange Anfragen aufbewahrt werden.'; } public function mount(): void { $settings = CommunicationSettings::current(); $this->form->fill([ 'recipients' => implode("\n", (array) $settings->recipients), 'retention_months' => $settings->retention_months, ]); } public function form(Schema $schema): Schema { return $schema ->components([ Section::make('Benachrichtigung')->schema([ Textarea::make('recipients')->label('Empfänger der internen Benachrichtigung')->rows(4) ->helperText('Eine E-Mail-Adresse je Zeile. Die Benachrichtigung nennt nur Kennzeichen und Anliegen, nie Kontaktdaten oder Antworten. Ohne Empfänger werden Anfragen trotzdem gespeichert; der Posteingang weist dann auf die fehlende Benachrichtigung hin.') ->rule(fn (): \Closure => function (string $attribute, mixed $value, \Closure $fail): void { foreach (self::lines((string) $value) as $address) { if (filter_var($address, FILTER_VALIDATE_EMAIL) === false) { $fail('„'.$address.'“ ist keine gültige E-Mail-Adresse.'); return; } } if (count(self::lines((string) $value)) > 10) { $fail('Bitte höchstens zehn Empfänger.'); } }), ]), Section::make('Weitere Bausteine')->description('Anliegen und der gemeinsame Feldkatalog gehören zu den Formularen. Im Formular-Editor müssen sie nicht geöffnet werden; hier lassen sie sich einsehen und ordnen.') ->visible(fn (): bool => CommunicationAccess::configure()) ->collapsed() ->schema([ Actions::make([ Action::make('issues')->label('Anliegen')->url(InquiryIssueResource::getUrl('index'))->color('gray'), Action::make('fields')->label('Feldkatalog')->url(InquiryFieldResource::getUrl('index'))->color('gray'), Action::make('groups')->label('Feldgruppen')->url(InquiryFieldGroupResource::getUrl('index'))->color('gray'), Action::make('entries')->label('Anfrage-Einstiege (ältere Seiten)')->url(InquiryEntryResource::getUrl('index'))->color('gray'), ]), ]), Section::make('Aufbewahrung')->schema([ TextInput::make('retention_months')->label('Anfragen löschen nach … Monaten')->numeric()->minValue(1)->maxValue(120) ->helperText('Leer: Anfragen werden nicht automatisch gelöscht. Der Befehl „php artisan communication:purge“ löscht Anfragen, die älter sind. Einzelne Anfragen lassen sich jederzeit im Posteingang löschen. Die Dauer ist mit dem Datenschutzkonzept abzustimmen.'), ]), ]) ->statePath('data'); } public function content(Schema $schema): Schema { return $schema->components([ Form::make([EmbeddedSchema::make('form')]) ->id('form') ->livewireSubmitHandler('save') ->footer([Actions::make([Action::make('save')->label('Einstellungen speichern')->submit('save')->keyBindings(['mod+s'])])]), ]); } public function save(): void { $data = $this->form->getState(); CommunicationSettings::current()->update([ 'recipients' => self::lines((string) ($data['recipients'] ?? '')), 'retention_months' => filled($data['retention_months'] ?? null) ? (int) $data['retention_months'] : null, ]); Notification::make()->title('Die Einstellungen sind gespeichert.')->success()->send(); } protected function getHeaderActions(): array { return [ Action::make('test') ->label('Testnachricht senden') ->icon('heroicon-o-envelope') ->color('gray') ->requiresConfirmation() ->modalDescription('Sendet eine Testnachricht an die gespeicherten Empfänger. Sie enthält keine Anfragedaten.') ->action(function (): void { $recipients = CommunicationSettings::current()->recipientList(); if ($recipients === []) { Notification::make()->title('Es sind noch keine Empfänger gespeichert.')->warning()->send(); return; } try { Mail::to($recipients)->send(new CommunicationTestMail); } catch (Throwable $e) { report($e); Notification::make()->title('Der Versand ist fehlgeschlagen.')->body($e->getMessage())->danger()->send(); return; } Notification::make()->title('Die Testnachricht ist abgesendet.')->body('Der Mailserver hat sie angenommen. Ob sie ankommt, zeigt dein Postfach.')->success()->send(); }), Action::make('example') ->label('Beispielkonfiguration anlegen') ->icon('heroicon-o-sparkles') ->color('gray') ->visible(fn (): bool => ExampleConfiguration::isEmpty()) ->requiresConfirmation() ->modalHeading('Beispielkonfiguration anlegen?') ->modalDescription('Legt Anliegen, Felder, Feldgruppen, vier Anfragevorlagen und fünf Anfrage-Einstiege (Allgemeiner Kontakt, Kurse & Workshops, Schul-AG, Programme & Materialien, Kooperation) an und veröffentlicht sie. Alles lässt sich danach ändern. Das geht nur, solange die Kommunikationsverwaltung noch leer ist.') ->action(function (): void { try { app(ExampleConfiguration::class)->install(CommunicationAccess::user()); } catch (RuntimeException $e) { Notification::make()->title($e->getMessage())->danger()->send(); return; } Notification::make()->title('Die Beispielkonfiguration ist angelegt und veröffentlicht.')->success()->send(); $this->redirect(static::getUrl()); }), ]; } /** * @return list */ private static function lines(string $text): array { return array_values(array_unique(array_filter(array_map('trim', preg_split('/[\r\n,;]+/', $text) ?: []), fn (string $line): bool => $line !== ''))); } }