wip
This commit is contained in:
1 parent
d6a13837c5
commit
9cfa60de30
5 files changed
+55
-1
No files matched your search
+1
@@ -21,6 +21,7 @@ class StatistikoImportForm
|
||||
'player' => '<span class="text-pink-600">Player History</span>',
|
||||
'fixtures' => '<span class="text-orange-500">Fixtures Upcoming</span>',
|
||||
'events' => '<span class="text-green-500">Events History</span>',
|
||||
'teams_tornaments' => '<span class="text-fuchsia-500">Teams in Tornaments</span>',
|
||||
]),
|
||||
|
||||
FileUpload::make('file_name')
|
||||
|
||||
+3
-1
@@ -32,6 +32,7 @@ class StatistikoImportsTable
|
||||
'player' => '<span class="text-pink-600">Player History</span>',
|
||||
'fixtures' => '<span class="text-orange-500">Fixtures Upcoming</span>',
|
||||
'events' => '<span class="text-green-500">Events History</span>',
|
||||
'teams_tornaments' => '<span class="text-fuchsia-500">Teams in Tornaments</span>',
|
||||
]),
|
||||
TextColumn::make('file_name_original')
|
||||
->sortable()
|
||||
@@ -55,6 +56,7 @@ class StatistikoImportsTable
|
||||
'events' => 'Events',
|
||||
'fixtures' => 'Fixtures',
|
||||
'player' => 'Player',
|
||||
'teams_tornaments' => 'Teams in Tornaments',
|
||||
]),
|
||||
], layout: FiltersLayout::AboveContent)
|
||||
->filtersFormColumns(6)
|
||||
@@ -67,7 +69,7 @@ class StatistikoImportsTable
|
||||
->color('success')
|
||||
->tooltip('Update or create')
|
||||
->icon('phosphor-database')
|
||||
->action(fn($record) => StatistikoImporter::run($record))
|
||||
->action(fn ($record) => StatistikoImporter::run($record))
|
||||
->successNotification(
|
||||
Notification::make()
|
||||
->info()
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Imports\Helper;
|
||||
|
||||
use App\Models\SofaScoreRosaTournament;
|
||||
use Illuminate\Support\LazyCollection;
|
||||
use Spatie\SimpleExcel\SimpleExcelReader;
|
||||
|
||||
class ImportTeamsTournaments
|
||||
{
|
||||
public static $active_tournament = [];
|
||||
|
||||
public static function run(string $filePath): void
|
||||
{
|
||||
SofaScoreRosaTournament::query()->update(['in_update' => 0]);
|
||||
|
||||
SimpleExcelReader::create(storage_path('app/public/'.$filePath))
|
||||
->getRows()
|
||||
->chunk(100)
|
||||
->each(function (LazyCollection $chunk) {
|
||||
|
||||
foreach ($chunk as $row) {
|
||||
|
||||
$row = array_values($row);
|
||||
|
||||
self::$active_tournament[] = $row[0];
|
||||
|
||||
dd($row);
|
||||
SofaScoreRosaTournament::updateOrCreate(
|
||||
[
|
||||
'ss_tournament_id' => (int) $row[0],
|
||||
],
|
||||
[
|
||||
'ss_team_id' => (int) $row[1],
|
||||
'in_update' => 1,
|
||||
]
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$tournaments = array_unique(self::$active_tournament);
|
||||
|
||||
SofaScoreRosaTournament::where('in_update', 0)->whereIn('torunament_id', $tournaments)->delete();
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use App\Filament\Imports\Helper\ImportDetails;
|
||||
use App\Filament\Imports\Helper\ImportEvents;
|
||||
use App\Filament\Imports\Helper\ImportFixtures;
|
||||
use App\Filament\Imports\Helper\ImportPlayer;
|
||||
use App\Filament\Imports\Helper\ImportTeamsTournaments;
|
||||
use App\Models\StatistikoImport;
|
||||
|
||||
class StatistikoImporter
|
||||
@@ -44,6 +45,10 @@ class StatistikoImporter
|
||||
case 'player':
|
||||
ImportPlayer::run($filePath);
|
||||
break;
|
||||
case 'teams_tornaments':
|
||||
ImportTeamsTournaments::run($filePath);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
StatistikoImport::query()->where('id', $record->id)->update(['has_run' => 1]);
|
||||
|
||||
@@ -17,6 +17,7 @@ return new class extends Migration
|
||||
$table->integer('ss_tournament_id')->default(0)->nullable()->index();
|
||||
$table->boolean('disabled')->default(false);
|
||||
$table->boolean('grapped')->default(false);
|
||||
$table->boolean('in_update')->default(false);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user