From 10baadb780bad01de24f70bfea701aae9d1d5fd5 Mon Sep 17 00:00:00 2001 From: salam Date: Mon, 10 Aug 2026 17:01:19 +0200 Subject: [PATCH] add download button for evenrs and players history --- .../Pages/ListStatistikoEvents.php | 10 ++ .../Pages/ListStatistikoPlayers.php | 9 ++ .../Exports/EventsHistoryExporter.php | 57 +++++++++++ .../Exports/PlayerHistoryExporter.php | 99 +++++++++++++++++++ 4 files changed, 175 insertions(+) create mode 100644 app/Filament/Exports/EventsHistoryExporter.php create mode 100644 app/Filament/Exports/PlayerHistoryExporter.php diff --git a/app/Filament/Clusters/StaticData/Resources/StatistikoEvents/Pages/ListStatistikoEvents.php b/app/Filament/Clusters/StaticData/Resources/StatistikoEvents/Pages/ListStatistikoEvents.php index cd4fe707..ee2d2d9c 100644 --- a/app/Filament/Clusters/StaticData/Resources/StatistikoEvents/Pages/ListStatistikoEvents.php +++ b/app/Filament/Clusters/StaticData/Resources/StatistikoEvents/Pages/ListStatistikoEvents.php @@ -3,10 +3,13 @@ namespace App\Filament\Clusters\StaticData\Resources\StatistikoEvents\Pages; use App\Filament\Clusters\StaticData\Resources\StatistikoEvents\StatistikoEventsResource; +use App\Filament\Exports\EventsHistoryExporter; use App\Models\StatistikoEvent; use DateTime; use Filament\Actions\Action; use Filament\Actions\CreateAction; +use Filament\Actions\ExportAction; +use Filament\Actions\Exports\Models\Export; use Filament\Resources\Pages\ListRecords; class ListStatistikoEvents extends ListRecords @@ -16,6 +19,12 @@ class ListStatistikoEvents extends ListRecords protected function getHeaderActions(): array { return [ + ExportAction::make('download_betfair') + ->columnMapping(false) + ->exporter(EventsHistoryExporter::class) + ->label('Download') + ->fileName(fn (Export $export): string => 'events-history-'.date('d.m.Y-H.i')."-{$export->getKey()}") + ->icon('phosphor-download'), Action::make('starttime') ->color('gray') ->tooltip('Find events with wrong starttime') @@ -25,6 +34,7 @@ class ListStatistikoEvents extends ListRecords ->icon('heroicon-o-trash')) ->modalContent(function () { $events = StatistikoEvent::with('league')->with('home')->with('away')->where('starttime', '<', new DateTime('-10 years'))->get(); + return view('filament.pages.list-fixtures-starttime', ['events' => $events]); })->action(function () { $events = StatistikoEvent::with('league')->with('home')->with('away')->where('starttime', '<', new DateTime('-10 years'))->get(); diff --git a/app/Filament/Clusters/StaticData/Resources/StatistikoPlayers/Pages/ListStatistikoPlayers.php b/app/Filament/Clusters/StaticData/Resources/StatistikoPlayers/Pages/ListStatistikoPlayers.php index 2dc103be..0a509581 100644 --- a/app/Filament/Clusters/StaticData/Resources/StatistikoPlayers/Pages/ListStatistikoPlayers.php +++ b/app/Filament/Clusters/StaticData/Resources/StatistikoPlayers/Pages/ListStatistikoPlayers.php @@ -3,10 +3,13 @@ namespace App\Filament\Clusters\StaticData\Resources\StatistikoPlayers\Pages; use App\Filament\Clusters\StaticData\Resources\StatistikoPlayers\StatistikoPlayerResource; +use App\Filament\Exports\PlayerHistoryExporter; use App\Models\StatistikoPlayer; use DateTime; use Filament\Actions\Action; use Filament\Actions\CreateAction; +use Filament\Actions\ExportAction; +use Filament\Actions\Exports\Models\Export; use Filament\Resources\Pages\ListRecords; class ListStatistikoPlayers extends ListRecords @@ -16,6 +19,12 @@ class ListStatistikoPlayers extends ListRecords protected function getHeaderActions(): array { return [ + ExportAction::make('download_betfair') + ->columnMapping(false) + ->exporter(PlayerHistoryExporter::class) + ->label('Download') + ->fileName(fn (Export $export): string => 'player-history-'.date('d.m.Y-H.i')."-{$export->getKey()}") + ->icon('phosphor-download'), Action::make('starttime') ->color('gray') ->tooltip('Find events with wrong starttime') diff --git a/app/Filament/Exports/EventsHistoryExporter.php b/app/Filament/Exports/EventsHistoryExporter.php new file mode 100644 index 00000000..a37535f4 --- /dev/null +++ b/app/Filament/Exports/EventsHistoryExporter.php @@ -0,0 +1,57 @@ +successful_rows).' '.str('row')->plural($export->successful_rows).' exported.'; + + if ($failedRowsCount = $export->getFailedRowsCount()) { + $body .= ' '.Number::format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.'; + } + + return $body; + } +} diff --git a/app/Filament/Exports/PlayerHistoryExporter.php b/app/Filament/Exports/PlayerHistoryExporter.php new file mode 100644 index 00000000..c375f91f --- /dev/null +++ b/app/Filament/Exports/PlayerHistoryExporter.php @@ -0,0 +1,99 @@ +successful_rows).' '.str('row')->plural($export->successful_rows).' exported.'; + + if ($failedRowsCount = $export->getFailedRowsCount()) { + $body .= ' '.Number::format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.'; + } + + return $body; + } +}