Baue die Verwaltung Kommunikation, die öffentliche Anfrageschnittstelle und das CMS-Widget Anfrage
Anliegen, Feldkatalog, Feldgruppen, Anfragevorlagen mit Fassungen, Anfrage-Einstiege, Posteingang mit Status und Notizen, Einstellungen mit Empfängern. Das Widget speichert nur die Kennung eines veröffentlichten Einstiegs; Formular, Bedingungen und Annahme kommen zur Laufzeit vom Server (Kompaktformular und mehrstufiger Dialog aus derselben Beschreibung). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2ee1fc9866
commit
c6a8167601
45 files changed
+5415
No files matched your search
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Communication\Inquiries;
|
||||
|
||||
use App\Domain\Communication\CommunicationAccess;
|
||||
use App\Domain\Communication\Inquiry;
|
||||
use App\Filament\Resources\Communication\Inquiries\Pages\ListInquiries;
|
||||
use App\Filament\Resources\Communication\Inquiries\Pages\ViewInquiry;
|
||||
use Filament\Infolists\Components\RepeatableEntry;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Infolists\Components\ViewEntry;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Zentraler Posteingang aller Anfragen (ADR-60). Anfragen enthalten personenbezogene Daten: Zugriff nur für
|
||||
* Kundenbetreuung und Systemverwaltung.
|
||||
*/
|
||||
class InquiryResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Inquiry::class;
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Kommunikation';
|
||||
|
||||
protected static ?string $navigationLabel = 'Anfragen';
|
||||
|
||||
protected static ?string $modelLabel = 'Anfrage';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Anfragen';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'reference';
|
||||
|
||||
protected static ?string $slug = 'anfragen';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
public static function canViewAny(): bool
|
||||
{
|
||||
return CommunicationAccess::inbox();
|
||||
}
|
||||
|
||||
public static function canView(Model $record): bool
|
||||
{
|
||||
return CommunicationAccess::inbox();
|
||||
}
|
||||
|
||||
public static function canCreate(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function canEdit(Model $record): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function canDelete(Model $record): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function canDeleteAny(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getNavigationBadge(): ?string
|
||||
{
|
||||
if (! CommunicationAccess::inbox()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$new = Inquiry::query()->where('status', 'neu')->count();
|
||||
|
||||
return $new > 0 ? (string) $new : null;
|
||||
}
|
||||
|
||||
public static function getNavigationBadgeTooltip(): ?string
|
||||
{
|
||||
return 'Neue Anfragen';
|
||||
}
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Section::make('Ansprechpartner')->columns(2)->schema([
|
||||
TextEntry::make('contact_name')->label('Name')->placeholder('Nicht angegeben'),
|
||||
TextEntry::make('organisation')->label('Organisation')->placeholder('Nicht angegeben'),
|
||||
TextEntry::make('contact_email')->label('E-Mail-Adresse')->placeholder('Nicht angegeben')->copyable(),
|
||||
TextEntry::make('contact_phone')->label('Telefon')->placeholder('Nicht angegeben'),
|
||||
]),
|
||||
Section::make('Anliegen')->columns(2)->schema([
|
||||
TextEntry::make('issue')->label('Anliegen')->state(fn (Inquiry $record): string => $record->issueTitle() ?: 'Nicht erfragt'),
|
||||
TextEntry::make('status')->label('Bearbeitungsstatus')->badge()
|
||||
->formatStateUsing(fn ($state): string => $state->label())
|
||||
->color(fn ($state): string => $state->color()),
|
||||
TextEntry::make('entry.name')->label('Anfrage-Einstieg')->placeholder('Gelöscht'),
|
||||
TextEntry::make('source_path')->label('Quellseite')->placeholder('Unbekannt'),
|
||||
TextEntry::make('created_at')->label('Eingegangen')->dateTime('d.m.Y H:i'),
|
||||
TextEntry::make('reference')->label('Kennzeichen')->copyable(),
|
||||
TextEntry::make('version')->label('Formularfassung')
|
||||
->state(fn (Inquiry $record): string => 'Vorlage „'.($record->templateVersion->template->name ?? '').'“, Fassung '.($record->templateVersion->version ?? '')),
|
||||
TextEntry::make('notification')->label('Benachrichtigung')
|
||||
->state(fn (Inquiry $record): string => $record->notified_at !== null ? 'Gesendet am '.$record->notified_at->format('d.m.Y H:i') : ($record->notification_error ?: 'Noch nicht gesendet'))
|
||||
->color(fn (Inquiry $record): ?string => $record->notified_at === null && $record->notification_error !== null ? 'danger' : null),
|
||||
]),
|
||||
Section::make('Antworten')->schema([
|
||||
ViewEntry::make('answers')->hiddenLabel()->view('filament.communication.answers'),
|
||||
]),
|
||||
Section::make('Nachricht')->visible(fn (Inquiry $record): bool => filled($record->message))->schema([
|
||||
TextEntry::make('message')->hiddenLabel()->extraAttributes(['style' => 'white-space: pre-line']),
|
||||
]),
|
||||
Section::make('Interne Notizen')->schema([
|
||||
RepeatableEntry::make('notes')->hiddenLabel()->placeholder('Noch keine Notizen.')->schema([
|
||||
TextEntry::make('body')->hiddenLabel()->extraAttributes(['style' => 'white-space: pre-line']),
|
||||
TextEntry::make('meta')->hiddenLabel()->color('gray')
|
||||
->state(fn ($record): string => ($record->author->name ?? 'Unbekannt').' · '.$record->created_at->format('d.m.Y H:i')),
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema;
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table->columns([TextColumn::make('reference')->label('Kennzeichen')]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListInquiries::route('/'),
|
||||
'view' => ViewInquiry::route('/{record}'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Communication\Inquiries\Pages;
|
||||
|
||||
use App\Domain\Communication\Inquiry;
|
||||
use App\Domain\Communication\InquiryStatus;
|
||||
use App\Filament\Resources\Communication\Inquiries\InquiryResource;
|
||||
use App\Filament\Support\Bestand;
|
||||
use App\Filament\Support\ListsCatalog;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Attributes\Url;
|
||||
|
||||
class ListInquiries extends ListRecords
|
||||
{
|
||||
use ListsCatalog {
|
||||
bestand as protected baseBestand;
|
||||
}
|
||||
|
||||
protected static string $resource = InquiryResource::class;
|
||||
|
||||
#[Url(as: 'anliegen', except: 'alle')]
|
||||
public string $anliegen = 'alle';
|
||||
|
||||
#[Url(as: 'sortierung', except: 'neu')]
|
||||
public string $sortierung = 'neu';
|
||||
|
||||
public function getSubheading(): string|Htmlable|null
|
||||
{
|
||||
return 'Alle eingegangenen Anfragen aus allen Anfrage-Einstiegen. Der Status wird von Hand gesetzt; Notizen sind nur intern sichtbar.';
|
||||
}
|
||||
|
||||
protected function bestandFilterEigenschaften(): array
|
||||
{
|
||||
return ['suche', 'zustand', 'anliegen', 'sortierung'];
|
||||
}
|
||||
|
||||
public function resetFilters(): void
|
||||
{
|
||||
$this->suche = '';
|
||||
$this->zustand = 'alle';
|
||||
$this->anliegen = 'alle';
|
||||
$this->sortierung = 'neu';
|
||||
$this->bestandGrenze = Bestand::SCHRITT;
|
||||
}
|
||||
|
||||
public function bestand(): array
|
||||
{
|
||||
$b = $this->baseBestand();
|
||||
$issues = Inquiry::query()->whereNotNull('issue_key')->select('issue_key', 'issue_label')->distinct()->orderBy('issue_label')->pluck('issue_label', 'issue_key')->all();
|
||||
|
||||
$b['filter'][] = ['eigenschaft' => 'anliegen', 'label' => 'Anliegen', 'vorgabe' => 'alle', 'optionen' => ['alle' => 'Alle Anliegen'] + $issues];
|
||||
$b['sortierung'] = ['eigenschaft' => 'sortierung', 'label' => 'Sortierung', 'optionen' => ['neu' => 'Neueste zuerst', 'alt' => 'Älteste zuerst', 'name' => 'Name', 'status' => 'Status']];
|
||||
|
||||
return $b;
|
||||
}
|
||||
|
||||
protected function catalogRows(): array
|
||||
{
|
||||
$query = Inquiry::query()->with('entry');
|
||||
|
||||
if ($this->anliegen !== 'alle') {
|
||||
$query->where('issue_key', $this->anliegen);
|
||||
}
|
||||
|
||||
$inquiries = match ($this->sortierung) {
|
||||
'alt' => $query->orderBy('created_at')->orderBy('id')->get(),
|
||||
'name' => $query->get()->sortBy(fn (Inquiry $i): string => mb_strtolower($i->contactTitle()), SORT_NATURAL)->values(),
|
||||
'status' => $query->get()->sortBy(fn (Inquiry $i): string => array_search($i->status, InquiryStatus::cases(), true).'-'.(PHP_INT_MAX - $i->created_at->getTimestamp()))->values(),
|
||||
default => $query->orderByDesc('created_at')->orderByDesc('id')->get(),
|
||||
};
|
||||
|
||||
$rows = [];
|
||||
|
||||
foreach ($inquiries as $inquiry) {
|
||||
$url = InquiryResource::getUrl('view', ['record' => $inquiry]);
|
||||
$failed = $inquiry->notified_at === null && $inquiry->notification_error !== null;
|
||||
$rows[] = [
|
||||
'schluessel' => 'q'.$inquiry->id,
|
||||
'titel' => $inquiry->contactTitle().($inquiry->organisation ? ' · '.$inquiry->organisation : ''),
|
||||
'meta' => $inquiry->created_at->format('d.m.Y H:i').' · '.($inquiry->issueTitle() ?: 'Ohne Anliegen').' · '.($inquiry->entry->name ?? 'Einstieg gelöscht'),
|
||||
'text' => Str::limit((string) $inquiry->message, 180),
|
||||
'suchtext' => implode(' ', array_filter([$inquiry->contact_email, $inquiry->reference, $inquiry->contact_phone])),
|
||||
'symbol' => 'modul',
|
||||
'url' => $url,
|
||||
'chips' => array_values(array_filter([
|
||||
['label' => $inquiry->status->label(), 'ton' => match ($inquiry->status) {
|
||||
InquiryStatus::Neu => 'offen',
|
||||
InquiryStatus::RueckfrageOffen => 'achtung',
|
||||
InquiryStatus::Erledigt => 'gut',
|
||||
default => 'neutral',
|
||||
}],
|
||||
$failed ? ['label' => 'Benachrichtigung fehlgeschlagen', 'ton' => 'achtung'] : null,
|
||||
])),
|
||||
'zustand' => array_values(array_filter([$inquiry->status->value, $inquiry->status !== InquiryStatus::Erledigt ? 'offen' : null, $failed ? 'mailfehler' : null])),
|
||||
'aktionen' => [['label' => 'Öffnen', 'href' => $url]],
|
||||
];
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
protected function zustandOptionen(): array
|
||||
{
|
||||
return [
|
||||
'alle' => 'Jeder Status',
|
||||
'offen' => 'Nicht erledigt',
|
||||
...InquiryStatus::options(),
|
||||
'mailfehler' => 'Benachrichtigung fehlgeschlagen',
|
||||
];
|
||||
}
|
||||
|
||||
protected function suchPlatzhalter(): string
|
||||
{
|
||||
return 'Name, E-Mail, Organisation, Nachricht oder Kennzeichen';
|
||||
}
|
||||
|
||||
protected function einheit(): array
|
||||
{
|
||||
return ['Anfrage', 'Anfragen'];
|
||||
}
|
||||
|
||||
protected function leer(): array
|
||||
{
|
||||
return ['titel' => 'Noch keine Anfragen', 'text' => 'Sobald jemand über einen Anfrage-Einstieg eine Anfrage sendet, erscheint sie hier.'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Communication\Inquiries\Pages;
|
||||
|
||||
use App\Domain\Communication\CommunicationAccess;
|
||||
use App\Domain\Communication\Inquiry;
|
||||
use App\Domain\Communication\InquiryNote;
|
||||
use App\Domain\Communication\InquiryStatus;
|
||||
use App\Filament\Resources\Communication\Inquiries\InquiryResource;
|
||||
use App\Jobs\SendInquiryNotification;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class ViewInquiry extends ViewRecord
|
||||
{
|
||||
protected static string $resource = InquiryResource::class;
|
||||
|
||||
public function getTitle(): string|Htmlable
|
||||
{
|
||||
/** @var Inquiry $inquiry */
|
||||
$inquiry = $this->getRecord();
|
||||
|
||||
return $inquiry->contactTitle();
|
||||
}
|
||||
|
||||
public function getSubheading(): string|Htmlable|null
|
||||
{
|
||||
/** @var Inquiry $inquiry */
|
||||
$inquiry = $this->getRecord();
|
||||
|
||||
return 'Anfrage '.$inquiry->reference.' vom '.$inquiry->created_at->format('d.m.Y H:i');
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('status')
|
||||
->label('Status ändern')
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->modalHeading('Bearbeitungsstatus')
|
||||
->modalSubmitActionLabel('Status speichern')
|
||||
->fillForm(fn (): array => ['status' => $this->getRecord()->status->value])
|
||||
->schema([Select::make('status')->label('Neuer Status')->options(InquiryStatus::options())->required()])
|
||||
->action(function (array $data): void {
|
||||
$this->getRecord()->forceFill(['status' => $data['status']])->save();
|
||||
Notification::make()->title('Der Status ist geändert.')->success()->send();
|
||||
$this->refreshFormData(['status']);
|
||||
}),
|
||||
Action::make('note')
|
||||
->label('Notiz hinzufügen')
|
||||
->icon('heroicon-o-pencil-square')
|
||||
->color('gray')
|
||||
->modalHeading('Interne Notiz')
|
||||
->modalDescription('Nur für das Team sichtbar, nie für den Anfragenden.')
|
||||
->modalSubmitActionLabel('Notiz speichern')
|
||||
->schema([Textarea::make('body')->label('Notiz')->required()->rows(4)->maxLength(4000)])
|
||||
->action(function (array $data): void {
|
||||
InquiryNote::query()->create([
|
||||
'inquiry_id' => $this->getRecord()->id,
|
||||
'user_id' => CommunicationAccess::user()?->id,
|
||||
'body' => $data['body'],
|
||||
]);
|
||||
|
||||
$this->getRecord()->load('notes');
|
||||
Notification::make()->title('Die Notiz ist gespeichert.')->success()->send();
|
||||
$this->redirect(InquiryResource::getUrl('view', ['record' => $this->getRecord()]));
|
||||
}),
|
||||
Action::make('resend')
|
||||
->label('Benachrichtigung erneut senden')
|
||||
->icon('heroicon-o-envelope')
|
||||
->color('gray')
|
||||
->visible(fn (): bool => $this->getRecord()->notified_at === null)
|
||||
->requiresConfirmation()
|
||||
->modalDescription('Sendet die interne Benachrichtigung an die in den Einstellungen hinterlegten Empfänger noch einmal.')
|
||||
->action(function (): void {
|
||||
SendInquiryNotification::dispatchSync($this->getRecord()->id);
|
||||
$inquiry = $this->getRecord()->fresh();
|
||||
|
||||
if ($inquiry->notified_at !== null) {
|
||||
Notification::make()->title('Die Benachrichtigung ist gesendet.')->success()->send();
|
||||
} else {
|
||||
Notification::make()->title('Die Benachrichtigung ist weiterhin fehlgeschlagen.')->body((string) $inquiry->notification_error)->danger()->send();
|
||||
}
|
||||
|
||||
$this->redirect(InquiryResource::getUrl('view', ['record' => $inquiry]));
|
||||
}),
|
||||
Action::make('erase')
|
||||
->label('Anfrage löschen')
|
||||
->icon('heroicon-o-trash')
|
||||
->color('danger')
|
||||
->visible(fn (): bool => CommunicationAccess::erase())
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Anfrage endgültig löschen?')
|
||||
->modalDescription('Die Anfrage mit allen Antworten und Notizen wird unwiderruflich gelöscht, zum Beispiel auf Wunsch der betroffenen Person. Das lässt sich nicht rückgängig machen.')
|
||||
->action(function (): void {
|
||||
$this->getRecord()->delete();
|
||||
Notification::make()->title('Die Anfrage ist gelöscht.')->success()->send();
|
||||
$this->redirect(InquiryResource::getUrl('index'));
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user