Edit SofaScore Tasks add filter
This commit is contained in:
1 parent
210aed8c97
commit
b25cf15a9e
10 files changed
+120
-39
No files matched your search
@@ -7,7 +7,7 @@ use App\Console\Commands\Grapper\Sofascore\Helper\LoadDays;
|
||||
use App\Console\Commands\Grapper\Sofascore\Helper\Sleeper;
|
||||
use App\Console\Commands\Nuh;
|
||||
use App\Models\Country;
|
||||
use App\Models\SofaScoreCategorie;
|
||||
use App\Models\SofaScoreCategory;
|
||||
use App\Models\SofaScoreDayTournament;
|
||||
use App\Models\SofaScoreTournament;
|
||||
use App\Utilities\Notice;
|
||||
@@ -126,9 +126,9 @@ class DaysTournament
|
||||
// CATEGORY find <-> replace
|
||||
Log::channel('sofascore')->info($tournament);
|
||||
|
||||
$sofa_score_categorie_id = 10000000;
|
||||
$sofa_score_category_id = 10000000;
|
||||
} else {
|
||||
$call = SofaScoreCategorie::updateOrCreate([
|
||||
$call = SofaScoreCategory::updateOrCreate([
|
||||
'id' => (int) $category['id'],
|
||||
'country_id' => (int) $country_id,
|
||||
'slug' => $category['slug'],
|
||||
@@ -136,7 +136,7 @@ class DaysTournament
|
||||
'name' => $category['name'],
|
||||
]);
|
||||
|
||||
$sofa_score_categorie_id = $call->id;
|
||||
$sofa_score_category_id = $call->id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,7 +145,7 @@ class DaysTournament
|
||||
SofaScoreTournament::updateOrCreate([
|
||||
'sport_id' => (int) $sport_id,
|
||||
'tournament_id' => (int) $tournament['id'],
|
||||
'sofa_score_categorie_id' => (int) $sofa_score_categorie_id,
|
||||
'sofa_score_category_id' => (int) $sofa_score_category_id,
|
||||
], [
|
||||
'name' => $tournament['name'],
|
||||
'slug' => $tournament['slug'],
|
||||
|
||||
@@ -11,6 +11,7 @@ use App\Models\SofaScoreDayTournament;
|
||||
use App\Models\SofaScoreEventGrapped;
|
||||
use App\Models\SofaScoreTaskDay;
|
||||
use App\Models\SofaScoreTaskTournament;
|
||||
use App\Models\SofaScoreTournament;
|
||||
use App\Utilities\Notice;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\File;
|
||||
@@ -19,6 +20,7 @@ class Rose
|
||||
{
|
||||
public static function run()
|
||||
{
|
||||
|
||||
$debug = Nuh::$options['d'] ?? 0;
|
||||
|
||||
$task_id = Nuh::$options['task'] ?? 0;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Grapper\Sofascore;
|
||||
|
||||
use App\Models\SofaScoreTaskTournament;
|
||||
use App\Models\SofaScoreTournament;
|
||||
use App\Utilities\Notice;
|
||||
|
||||
class SqlMover
|
||||
{
|
||||
public static function run()
|
||||
{
|
||||
|
||||
$res = SofaScoreTaskTournament::get();
|
||||
|
||||
foreach ($res as $value) {
|
||||
$res2 = SofaScoreTournament::where('tournament_id', $value->sofa_score_tournament_id)->first();
|
||||
|
||||
SofaScoreTaskTournament::where('id', $value->id)->update(['sofa_score_category_id' => $res2->sofa_score_category_id]);
|
||||
}
|
||||
|
||||
Notice::note('done', 'bb', 1);
|
||||
}
|
||||
}
|
||||
+67
-19
@@ -2,12 +2,14 @@
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTasks\RelationManagers;
|
||||
|
||||
use App\Models\SofaScoreCategorie;
|
||||
use App\Models\SofaScoreCategory;
|
||||
use App\Models\SofaScoreTaskTournament;
|
||||
use App\Models\SofaScoreTournament;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
@@ -16,7 +18,10 @@ use Filament\Schemas\Schema;
|
||||
use Filament\Support\Enums\FontWeight;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
use Filament\Tables\Enums\FiltersLayout;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class SofaScoreTaskTournamentsRelationManager extends RelationManager
|
||||
{
|
||||
@@ -29,20 +34,20 @@ class SofaScoreTaskTournamentsRelationManager extends RelationManager
|
||||
protected static ?string $modelLabel = 'Tournament';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Tournaments';
|
||||
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Select::make('sofa_score_categorie_id')
|
||||
Select::make('sofa_score_category_id')
|
||||
->searchable()
|
||||
->label('Categorie')
|
||||
->options(function (Get $get) {
|
||||
->label('Category')
|
||||
->options(function () {
|
||||
$res = SofaScoreTournament::where('sport_id', $this->getOwnerRecord()['sport_id'])
|
||||
->groupBy('sofa_score_categorie_id')
|
||||
->pluck('sofa_score_categorie_id')
|
||||
->groupBy('sofa_score_category_id')
|
||||
->pluck('sofa_score_category_id')
|
||||
->toArray();
|
||||
return SofaScoreCategorie::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id');
|
||||
return SofaScoreCategory::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id');
|
||||
})
|
||||
->live(),
|
||||
Select::make('sofa_score_tournament_id')
|
||||
@@ -50,10 +55,10 @@ class SofaScoreTaskTournamentsRelationManager extends RelationManager
|
||||
->label('Tournament')
|
||||
->placeholder('Select a categorie first.')
|
||||
->noOptionsMessage('Select a categorie first.')
|
||||
->disabled(fn (Get $get):bool => (bool) $get('sofa_score_categorie_id') ? false : true)
|
||||
->options(fn (Get $get) => SofaScoreTournament::where('sport_id', $this->getOwnerRecord()['sport_id'])
|
||||
->disabled(fn(Get $get): bool => (bool) $get('sofa_score_category_id') ? false : true)
|
||||
->options(fn(Get $get) => SofaScoreTournament::where('sport_id', $this->getOwnerRecord()['sport_id'])
|
||||
->where('disabled', 0)
|
||||
->where('sofa_score_categorie_id', $get('sofa_score_categorie_id'))
|
||||
->where('sofa_score_category_id', $get('sofa_score_category_id'))
|
||||
->orderBY('name')
|
||||
->pluck('name', 'tournament_id')),
|
||||
]);
|
||||
@@ -63,30 +68,73 @@ class SofaScoreTaskTournamentsRelationManager extends RelationManager
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('tournament.sofascore_category.name')
|
||||
->label('Country')
|
||||
TextColumn::make('category.name')
|
||||
->label('Category')
|
||||
->searchable(),
|
||||
TextColumn::make('tournament.name')
|
||||
->weight(FontWeight::Bold)
|
||||
->searchable(),
|
||||
ToggleColumn::make('disabled')
|
||||
->onColor('danger')
|
||||
->alignCenter(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
SelectFilter::make('sofa_score_category_id')
|
||||
->searchable()
|
||||
->label('Categorie')
|
||||
->options(function () {
|
||||
$res = SofaScoreTaskTournament::where('sofa_score_task_id', $this->getOwnerRecord()['id'])
|
||||
->groupBy('sofa_score_category_id')
|
||||
->pluck('sofa_score_category_id')
|
||||
->toArray();
|
||||
return SofaScoreCategory::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id');
|
||||
})
|
||||
], layout: FiltersLayout::AboveContent)
|
||||
->deferFilters(false)
|
||||
->headerActions([
|
||||
Action::make('all_on')
|
||||
->icon('phosphor-toggle-right-fill')
|
||||
->action(function (): void {
|
||||
SofaScoreTaskTournament::where('sofa_score_task_id', $this->getOwnerRecord()['id'])->update(['disabled' => 0]);
|
||||
}),
|
||||
Action::make('all_off')
|
||||
->icon('phosphor-toggle-left-fill')
|
||||
->color('danger')
|
||||
->action(function (): void {
|
||||
SofaScoreTaskTournament::where('sofa_score_task_id', $this->getOwnerRecord()['id'])->update(['disabled' => 1]);
|
||||
}),
|
||||
CreateAction::make()
|
||||
->icon('phosphor-plus')
|
||||
->label('Tournament'),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
EditAction::make()->iconButton(),
|
||||
DeleteAction::make()->iconButton(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
BulkAction::make('Disable selected')
|
||||
->icon('phosphor-toggle-left-fill')
|
||||
->color('danger')
|
||||
->action(function (Collection $records): void {
|
||||
foreach ($records as $record) {
|
||||
SofaScoreTaskTournament::where('id', '=', $record->id)
|
||||
->update(
|
||||
['disabled' => 1]
|
||||
);
|
||||
}
|
||||
}),
|
||||
BulkAction::make('Enable selected')
|
||||
->icon('phosphor-toggle-right-fill')
|
||||
->action(function (Collection $records): void {
|
||||
foreach ($records as $record) {
|
||||
SofaScoreTaskTournament::where('id', '=', $record->id)
|
||||
->update(
|
||||
['disabled' => 0]
|
||||
);
|
||||
}
|
||||
}),
|
||||
// DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
+11
-11
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\Tables;
|
||||
|
||||
use App\Models\SofaScoreCategorie;
|
||||
use App\Models\SofaScoreCategory;
|
||||
use App\Models\SofaScoreTournament;
|
||||
use App\Models\Sport;
|
||||
use Filament\Actions\Action;
|
||||
@@ -54,21 +54,21 @@ class SofaScoreTournamentsTable
|
||||
->label('Sport')
|
||||
->options(Sport::where('is_active', 1)->pluck('name', 'id'))
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('sofa_score_categorie_id', null);
|
||||
$set('sofa_score_category_id', null);
|
||||
})
|
||||
->live(),
|
||||
Select::make('sofa_score_categorie_id')
|
||||
Select::make('sofa_score_category_id')
|
||||
->searchable()
|
||||
->multiple()
|
||||
->columnSpan(2)
|
||||
->label('Categorie')
|
||||
->options(function (Get $get) {
|
||||
$res = SofaScoreTournament::where('sport_id', $get('sport_id'))
|
||||
->groupBy('sofa_score_categorie_id')
|
||||
->pluck('sofa_score_categorie_id')
|
||||
->groupBy('sofa_score_category_id')
|
||||
->pluck('sofa_score_category_id')
|
||||
->toArray();
|
||||
|
||||
return SofaScoreCategorie::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id');
|
||||
return SofaScoreCategory::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id');
|
||||
})
|
||||
->live(),
|
||||
ToggleButtons::make('filter-disabled')
|
||||
@@ -86,12 +86,12 @@ class SofaScoreTournamentsTable
|
||||
$data['sport_id'],
|
||||
fn(Builder $query, $sport_id) => $query->where('sport_id', $sport_id)
|
||||
)->when(
|
||||
$data['sofa_score_categorie_id'],
|
||||
function (Builder $query, $sofa_score_categorie_id) {
|
||||
if (is_array($sofa_score_categorie_id)) {
|
||||
$query->whereIn('sofa_score_categorie_id', $sofa_score_categorie_id);
|
||||
$data['sofa_score_category_id'],
|
||||
function (Builder $query, $sofa_score_category_id) {
|
||||
if (is_array($sofa_score_category_id)) {
|
||||
$query->whereIn('sofa_score_category_id', $sofa_score_category_id);
|
||||
} else {
|
||||
$query->where('sofa_score_categorie_id', $sofa_score_categorie_id);
|
||||
$query->where('sofa_score_category_id', $sofa_score_category_id);
|
||||
}
|
||||
}
|
||||
// )->when(
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SofaScoreCategorie extends Model
|
||||
class SofaScoreCategory extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'id',
|
||||
@@ -9,6 +9,7 @@ class SofaScoreTaskTournament extends Model
|
||||
protected $fillable = [
|
||||
'sofa_score_task_id',
|
||||
'sofa_score_tournament_id',
|
||||
'sofa_score_category_id',
|
||||
'disabled',
|
||||
];
|
||||
|
||||
@@ -21,4 +22,9 @@ class SofaScoreTaskTournament extends Model
|
||||
{
|
||||
return $this->belongsTo(SofaScoreTournament::class, 'sofa_score_tournament_id', 'tournament_id');
|
||||
}
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(SofaScoreCategory::class, 'sofa_score_category_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class SofaScoreTournament extends Model
|
||||
'id',
|
||||
'sport_id',
|
||||
'tournament_id',
|
||||
'sofa_score_categorie_id',
|
||||
'sofa_score_category_id',
|
||||
'name',
|
||||
'slug',
|
||||
'enabled',
|
||||
@@ -23,6 +23,6 @@ class SofaScoreTournament extends Model
|
||||
|
||||
public function sofascore_category()
|
||||
{
|
||||
return $this->belongsTo(SofaScoreCategorie::class, 'sofa_score_categorie_id', 'id');
|
||||
return $this->belongsTo(SofaScoreCategory::class, 'sofa_score_category_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ return new class extends Migration
|
||||
$table->id();
|
||||
$table->integer('sport_id')->index()->references('id')->on('sports');
|
||||
$table->integer('tournament_id')->index();
|
||||
$table->integer('sofa_score_categorie_id')->index();
|
||||
$table->integer('sofa_score_category_id')->index();
|
||||
$table->string('slug')->index();
|
||||
$table->string('name');
|
||||
$table->boolean('enabled')->index()->default(0);
|
||||
|
||||
@@ -15,6 +15,7 @@ return new class extends Migration
|
||||
$table->id();
|
||||
$table->integer('sofa_score_task_id');
|
||||
$table->integer('sofa_score_tournament_id');
|
||||
$table->integer('sofa_score_category_id');
|
||||
$table->boolean('disabled')->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user