- Gäste: Markierungen, Aufenthalte & Umsatz, Stammgast-/Einwilligungsfilter, CSV-Export, Anonymisierung (manuell + automatisch nach Aufbewahrungsfrist) - Werbe-Einwilligung per Double-Opt-in aus dem Anfrageformular, signierte Bestätigungs-/Abmeldelinks - Bewertungen: automatische Einladung nach Abreise, Bewertungsformular mit Kategorien und internem Feedback, Freigabe und öffentliche Antwort im Admin - Konzept: Rollen, Inhalte, Customer Voice, Architektur Portal-Sync/Buchungshoheit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
70 lines
2.4 KiB
PHP
70 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Guests\Pages;
|
|
|
|
use App\Filament\Resources\Guests\GuestResource;
|
|
use App\Models\Guest;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\CreateAction;
|
|
use Filament\Forms\Components\Toggle;
|
|
use Filament\Resources\Pages\ListRecords;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
|
|
class ListGuests extends ListRecords
|
|
{
|
|
protected static string $resource = GuestResource::class;
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Action::make('export')
|
|
->label('Export (Excel/CSV)')
|
|
->icon(Heroicon::OutlinedArrowDownTray)
|
|
->color('gray')
|
|
->schema([
|
|
Toggle::make('consent_only')->label('Nur Gäste mit Einwilligung für Angebote'),
|
|
])
|
|
->action(fn (array $data): StreamedResponse => $this->export($data['consent_only'])),
|
|
CreateAction::make(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Semicolon-separated UTF-8 with BOM so that Excel opens umlauts correctly.
|
|
*/
|
|
private function export(bool $consentOnly): StreamedResponse
|
|
{
|
|
$guests = Guest::query()
|
|
->whereNull('anonymized_at')
|
|
->when($consentOnly, fn ($query) => $query->withMarketingConsent())
|
|
->withCount('bookings')
|
|
->orderBy('last_name')
|
|
->get();
|
|
|
|
return response()->streamDownload(function () use ($guests): void {
|
|
$out = fopen('php://output', 'w');
|
|
fwrite($out, "\xEF\xBB\xBF");
|
|
fputcsv($out, ['Vorname', 'Nachname', 'E-Mail', 'Telefon', 'Straße', 'PLZ', 'Ort', 'Land', 'Markierungen', 'Buchungen', 'Einwilligung Angebote'], ';');
|
|
|
|
foreach ($guests as $guest) {
|
|
fputcsv($out, [
|
|
$guest->first_name,
|
|
$guest->last_name,
|
|
$guest->email,
|
|
$guest->phone,
|
|
$guest->street,
|
|
$guest->postal_code,
|
|
$guest->city,
|
|
$guest->country,
|
|
implode(', ', $guest->tags ?? []),
|
|
$guest->bookings_count,
|
|
$guest->marketing_consent_at?->format('d.m.Y'),
|
|
], ';');
|
|
}
|
|
|
|
fclose($out);
|
|
}, 'gaeste-'.now()->format('Y-m-d').'.csv', ['Content-Type' => 'text/csv; charset=UTF-8']);
|
|
}
|
|
}
|