105 lines
3.8 KiB
PHP
105 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Imports;
|
|
|
|
use App\Models\StatistikoEvent;
|
|
use Filament\Actions\Imports\ImportColumn;
|
|
use Filament\Actions\Imports\Importer;
|
|
use Filament\Actions\Imports\Models\Import;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Number;
|
|
|
|
class StatistikoEventImporter extends Importer
|
|
{
|
|
protected static ?string $model = StatistikoEvent::class;
|
|
|
|
public function resolveRecord(): StatistikoEvent
|
|
{
|
|
$res = StatistikoEvent::query()
|
|
->where('sport_id', $this->data['sport_id'])
|
|
->where('league_id', $this->data['league_id'])
|
|
->where('home_id', $this->data['home_id'])
|
|
->where('away_id', $this->data['away_id'])
|
|
->where('starttime', $this->data['starttime'])
|
|
->first();
|
|
if ($res) {
|
|
return StatistikoEvent::find($res->id);
|
|
} else {
|
|
return new StatistikoEvent;
|
|
}
|
|
}
|
|
|
|
public static function getColumns(): array
|
|
{
|
|
return [
|
|
ImportColumn::make('sport_id')->numeric()->guess(['SPORT']),
|
|
ImportColumn::make('league_id')->numeric()->guess(['LEAGUE']),
|
|
ImportColumn::make('home_id')->numeric()->guess(['HOME']),
|
|
ImportColumn::make('away_id')->numeric()->guess(['AWAY']),
|
|
ImportColumn::make('starttime')
|
|
->guess(['STARTTIME'])
|
|
->castStateUsing(function ($state) {
|
|
return Carbon::parse($state);
|
|
}),
|
|
ImportColumn::make('season')->guess(['SEASON']),
|
|
ImportColumn::make('gls_h')->numeric(),
|
|
ImportColumn::make('gls_a')->numeric(),
|
|
ImportColumn::make('crn_h')->numeric(),
|
|
ImportColumn::make('fls_h')->numeric(),
|
|
ImportColumn::make('ofs_h')->numeric(),
|
|
ImportColumn::make('snt_h')->numeric(),
|
|
ImportColumn::make('tsh_h')->numeric(),
|
|
ImportColumn::make('crd_h')->numeric(),
|
|
ImportColumn::make('crn_a')->numeric(),
|
|
ImportColumn::make('fls_a')->numeric(),
|
|
ImportColumn::make('ofs_a')->numeric(),
|
|
ImportColumn::make('snt_a')->numeric(),
|
|
ImportColumn::make('tsh_a')->numeric(),
|
|
ImportColumn::make('crd_a')->numeric(),
|
|
ImportColumn::make('expgoalshome_value')
|
|
->castStateUsing(function (string $state) {
|
|
if (blank($state)) {
|
|
return null;
|
|
}
|
|
|
|
return (float) str_replace(',', '.', $state);
|
|
}),
|
|
ImportColumn::make('expgoalsaway_value')
|
|
->castStateUsing(function (string $state) {
|
|
if (blank($state)) {
|
|
return null;
|
|
}
|
|
|
|
return str_replace(',', '.', $state);
|
|
}),
|
|
ImportColumn::make('exp_handicap')
|
|
->castStateUsing(function (string $state) {
|
|
if (blank($state)) {
|
|
return null;
|
|
}
|
|
|
|
return str_replace(',', '.', $state);
|
|
}),
|
|
ImportColumn::make('exp_total')
|
|
->castStateUsing(function (string $state) {
|
|
if (blank($state)) {
|
|
return null;
|
|
}
|
|
|
|
return str_replace(',', '.', $state);
|
|
}),
|
|
];
|
|
}
|
|
|
|
public static function getCompletedNotificationBody(Import $import): string
|
|
{
|
|
$body = 'Your events import has completed and '.Number::format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
|
|
|
|
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
|
$body .= ' '.Number::format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
|
|
}
|
|
|
|
return $body;
|
|
}
|
|
}
|