statistic wip
This commit is contained in:
1 parent
1b5282d61d
commit
ad36ba555f
2 files changed
+30
-193
No files matched your search
+1
-1
@@ -24,7 +24,7 @@ class StatisticEventsResource extends Resource
|
|||||||
|
|
||||||
protected static ?int $navigationSort = 1;
|
protected static ?int $navigationSort = 1;
|
||||||
|
|
||||||
protected static string|\UnitEnum|null $navigationGroup = 'Statistic Events';
|
protected static string|\UnitEnum|null $navigationGroup = 'Events';
|
||||||
|
|
||||||
protected static ?string $cluster = StatisticCluster::class;
|
protected static ?string $cluster = StatisticCluster::class;
|
||||||
|
|
||||||
|
|||||||
+29
-192
@@ -2,11 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Filament\Clusters\Statistic\Resources\StatisticEvents\Tables;
|
namespace App\Filament\Clusters\Statistic\Resources\StatisticEvents\Tables;
|
||||||
|
|
||||||
use App\Models\CompetitionGroup;
|
|
||||||
use App\Models\Country;
|
use App\Models\Country;
|
||||||
use App\Models\Event;
|
use App\Models\Event;
|
||||||
use App\Models\Sport;
|
use App\Models\Sport;
|
||||||
use CodeWithKyrian\FilamentDateRange\Forms\Components\DateRangePicker;
|
|
||||||
use Filament\Actions\BulkActionGroup;
|
use Filament\Actions\BulkActionGroup;
|
||||||
use Filament\Actions\DeleteBulkAction;
|
use Filament\Actions\DeleteBulkAction;
|
||||||
use Filament\Actions\EditAction;
|
use Filament\Actions\EditAction;
|
||||||
@@ -38,10 +36,10 @@ class StatisticEventsTable
|
|||||||
'3' => 'icon-basketball',
|
'3' => 'icon-basketball',
|
||||||
'5' => 'icon-tennisball',
|
'5' => 'icon-tennisball',
|
||||||
}),
|
}),
|
||||||
TextColumn::make('league.name'),
|
TextColumn::make('league.name')->searchable(),
|
||||||
TextColumn::make('starttime')->dateTime('M j, Y')->label('Date'),
|
TextColumn::make('starttime')->dateTime('M j, Y')->label('Date'),
|
||||||
TextColumn::make('home.name')->color('primary'),
|
TextColumn::make('home.name')->color('primary')->searchable(),
|
||||||
TextColumn::make('away.name')->color('success'),
|
TextColumn::make('away.name')->color('success')->searchable(),
|
||||||
])
|
])
|
||||||
->filters([
|
->filters([
|
||||||
Filter::make('events')
|
Filter::make('events')
|
||||||
@@ -50,22 +48,16 @@ class StatisticEventsTable
|
|||||||
Select::make('sport_id')
|
Select::make('sport_id')
|
||||||
->default(1)
|
->default(1)
|
||||||
->hiddenLabel()
|
->hiddenLabel()
|
||||||
->label('')
|
|
||||||
->label('Sport')
|
|
||||||
->options(Sport::whereIn('id', [1, 2, 3, 5])->pluck('name', 'id')),
|
->options(Sport::whereIn('id', [1, 2, 3, 5])->pluck('name', 'id')),
|
||||||
Select::make(name: 'country_id')
|
Select::make(name: 'country_id')
|
||||||
->hidden(fn (Get $get) => $get('sport_id') == 5)
|
->hidden(fn (Get $get) => $get('sport_id') == 5)
|
||||||
->placeholder('Country')
|
->placeholder('Country')
|
||||||
->prefixIcon('phosphor-flag')
|
->prefixIcon('phosphor-flag')
|
||||||
->hiddenLabel()
|
->hiddenLabel()
|
||||||
->label('')
|
|
||||||
->multiple()
|
|
||||||
->searchable()
|
->searchable()
|
||||||
->preload()
|
|
||||||
->options(function (Get $get) {
|
->options(function (Get $get) {
|
||||||
$res = Event::where('has_markets', 1)
|
$res = Event::where('has_markets', 1)
|
||||||
->where('sport_id', $get('sport_id'))
|
->where('sport_id', $get('sport_id'))
|
||||||
->where('starttime', '>=', Carbon::now())
|
|
||||||
->groupBy('country_id')
|
->groupBy('country_id')
|
||||||
->pluck('country_id')->toArray();
|
->pluck('country_id')->toArray();
|
||||||
|
|
||||||
@@ -77,63 +69,30 @@ class StatisticEventsTable
|
|||||||
$set('competition_group_id', null);
|
$set('competition_group_id', null);
|
||||||
}),
|
}),
|
||||||
Select::make('competition_group_id')
|
Select::make('competition_group_id')
|
||||||
->hidden(fn (Get $get) => $get('sport_id') == 5)
|
->placeholder(fn (Get $get) => $get('sport_id') == 5 ? 'Tournament' : 'League')
|
||||||
->placeholder('League')
|
|
||||||
->prefixIcon('phosphor-trophy')
|
->prefixIcon('phosphor-trophy')
|
||||||
->hiddenLabel()
|
->hiddenLabel()
|
||||||
->label('')
|
// ->multiple()
|
||||||
->multiple()
|
|
||||||
->searchable()
|
->searchable()
|
||||||
->options(function (Get $get) {
|
->options(function (Get $get) {
|
||||||
$country_id = $get('country_id') ?? 0;
|
$country_id = $get('country_id') ?? 0;
|
||||||
if ($country_id) {
|
$res = Event::with('country')
|
||||||
$res = Event::with('country')
|
->with('competition_group')
|
||||||
->with('competition_group')
|
->where('sport_id', $get('sport_id'))
|
||||||
->where('sport_id', $get('sport_id'))
|
->when($country_id, function ($query, $country_id) {
|
||||||
->whereIn('country_id', $country_id)
|
$query->where('country_id', $country_id);
|
||||||
->where('starttime', '>', Carbon::now())
|
})->groupBy('competition_group_id')->get();
|
||||||
->groupBy('competition_group_id')->get();
|
|
||||||
} else {
|
|
||||||
$res = Event::with('country')
|
|
||||||
->with('competition_group')
|
|
||||||
->where('sport_id', $get('sport_id'))
|
|
||||||
->where('starttime', '>', Carbon::now())
|
|
||||||
->groupBy('competition_group_id')->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
$arr = [];
|
$arr = [];
|
||||||
foreach ($res as $val) {
|
foreach ($res as $val) {
|
||||||
$arr[$val->competition_group_id] = $val->country?->name.' '.$val->competition_group?->name;
|
$arr[(int) $val->competition_group_id] = $val->country?->name.' '.$val->competition_group?->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
asort($arr);
|
asort($arr);
|
||||||
|
|
||||||
return $arr;
|
return $arr;
|
||||||
})
|
})
|
||||||
->live(),
|
->live(),
|
||||||
Select::make('competition_group_id')
|
|
||||||
->visible(fn (Get $get) => $get('sport_id') == 5)
|
|
||||||
->placeholder('Tournament')
|
|
||||||
->prefixIcon('phosphor-trophy')
|
|
||||||
->hiddenLabel()
|
|
||||||
->label('')
|
|
||||||
->multiple()
|
|
||||||
->searchable()
|
|
||||||
->options(function () {
|
|
||||||
$res = Event::with('competition_group')
|
|
||||||
->where('sport_id', 5)
|
|
||||||
->where('starttime', '>', Carbon::now())
|
|
||||||
->groupBy('competition_group_id')
|
|
||||||
->get();
|
|
||||||
$arr = [];
|
|
||||||
foreach ($res as $val) {
|
|
||||||
$arr[$val->competition_group_id] = $val->competition_group->name;
|
|
||||||
}
|
|
||||||
// asort($arr);
|
|
||||||
|
|
||||||
return $arr;
|
|
||||||
})
|
|
||||||
->live(),
|
|
||||||
|
|
||||||
DatePicker::make('starttime_from')
|
DatePicker::make('starttime_from')
|
||||||
->prefix(fn () => new HtmlString('<string class="text-info-500">From</string>'))
|
->prefix(fn () => new HtmlString('<string class="text-info-500">From</string>'))
|
||||||
->displayFormat('d M Y')
|
->displayFormat('d M Y')
|
||||||
@@ -151,6 +110,12 @@ class StatisticEventsTable
|
|||||||
function (Builder $query, $sport_id) {
|
function (Builder $query, $sport_id) {
|
||||||
$query->where('sport_id', (int) $sport_id);
|
$query->where('sport_id', (int) $sport_id);
|
||||||
}
|
}
|
||||||
|
)->when(
|
||||||
|
$data['competition_group_id'],
|
||||||
|
function (Builder $query, $competition_group_id) {
|
||||||
|
// dd($competition_group_id);
|
||||||
|
$query->where('league_id', (int) $competition_group_id);
|
||||||
|
}
|
||||||
)->when(
|
)->when(
|
||||||
$data['starttime_from'],
|
$data['starttime_from'],
|
||||||
function (Builder $query, $starttime_from) {
|
function (Builder $query, $starttime_from) {
|
||||||
@@ -188,6 +153,14 @@ class StatisticEventsTable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($data['country_id'] ?? null) {
|
||||||
|
$country_id = $data['country_id'];
|
||||||
|
if ($country_id ?? null) {
|
||||||
|
$text = Country::where('id', $country_id)->value('name');
|
||||||
|
$indicators[] = Indicator::make('Country: '.$text)->removeField('country_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if ($data['competition_group_id'] ?? null) {
|
// if ($data['competition_group_id'] ?? null) {
|
||||||
// $competition_groups = CompetitionGroup::whereIn('id', $data['competition_group_id'])->pluck('name')->toArray();
|
// $competition_groups = CompetitionGroup::whereIn('id', $data['competition_group_id'])->pluck('name')->toArray();
|
||||||
// if (count($competition_groups) > 1) {
|
// if (count($competition_groups) > 1) {
|
||||||
@@ -202,144 +175,8 @@ class StatisticEventsTable
|
|||||||
|
|
||||||
], layout: FiltersLayout::AboveContent)
|
], layout: FiltersLayout::AboveContent)
|
||||||
->deferFilters(false)
|
->deferFilters(false)
|
||||||
// ->filters([
|
->hiddenFilterIndicators(false)
|
||||||
// Filter::make('events')
|
->persistFiltersInSession()
|
||||||
// ->columns(7)->columnSpan(7)
|
|
||||||
// ->schema([
|
|
||||||
// Select::make('sport_id')
|
|
||||||
// ->default(1)
|
|
||||||
// ->hiddenLabel()
|
|
||||||
// ->label('')
|
|
||||||
// ->label('Sport')
|
|
||||||
// ->options(Sport::where('is_active', 1)->pluck('name', 'id')),
|
|
||||||
// // Select::make('competition_group_id')
|
|
||||||
// // ->hidden(fn (Get $get) => $get('sport_id') == 5)
|
|
||||||
// // ->placeholder('League')
|
|
||||||
// // ->prefixIcon('phosphor-trophy')
|
|
||||||
// // ->hiddenLabel()
|
|
||||||
// // ->label('')
|
|
||||||
// // ->multiple()
|
|
||||||
// // ->searchable()
|
|
||||||
// // ->options(function (Get $get) {
|
|
||||||
// // $res = Event::where('has_markets', 1)
|
|
||||||
// // ->with('country')
|
|
||||||
// // ->with('competition_group')
|
|
||||||
// // ->where('sport_id', $get('sport_id'))
|
|
||||||
// // ->where('starttime', '>', Carbon::now())
|
|
||||||
// // ->whereIn('country_id', $get('country_id'))
|
|
||||||
// // ->groupBy('competition_group_id')->get();
|
|
||||||
|
|
||||||
// // $arr = [];
|
|
||||||
// // foreach ($res as $val) {
|
|
||||||
// // $arr[$val->competition_group_id] = $val->country?->name.' '.$val->competition_group?->name;
|
|
||||||
// // }
|
|
||||||
// // asort($arr);
|
|
||||||
|
|
||||||
// // return $arr;
|
|
||||||
// // })
|
|
||||||
// // ->live(),
|
|
||||||
// // Select::make('competition_group_id')
|
|
||||||
// // ->visible(fn (Get $get) => $get('sport_id') == 5)
|
|
||||||
// // ->placeholder('Tournament')
|
|
||||||
// // ->prefixIcon('phosphor-trophy')
|
|
||||||
// // ->hiddenLabel()
|
|
||||||
// // ->label('')
|
|
||||||
// // ->multiple()
|
|
||||||
// // ->searchable()
|
|
||||||
// // ->options(function () {
|
|
||||||
// // $res = Event::where('has_markets', 1)
|
|
||||||
// // ->with('competition_group')
|
|
||||||
// // ->where('sport_id', auth()->user()->sport_id)
|
|
||||||
// // ->where('starttime', '>', Carbon::now())
|
|
||||||
// // ->groupBy('competition_group_id')
|
|
||||||
// // ->get();
|
|
||||||
// // $arr = [];
|
|
||||||
// // foreach ($res as $val) {
|
|
||||||
// // $arr[$val->competition_group_id] = $val->competition_group->name;
|
|
||||||
// // }
|
|
||||||
// // asort($arr);
|
|
||||||
|
|
||||||
// // return $arr;
|
|
||||||
// // })
|
|
||||||
// // ->live(),
|
|
||||||
|
|
||||||
// // DateRangePicker::make('starttime_period')
|
|
||||||
// // ->columnSpan(2)
|
|
||||||
// // ->displayFormat('d M Y')
|
|
||||||
// // ->minDate(now())
|
|
||||||
// // ->hiddenLabel()
|
|
||||||
// // ->label('')
|
|
||||||
// // ->live(),
|
|
||||||
// ]),
|
|
||||||
// // ->query(function (Builder $query, array $data): Builder {
|
|
||||||
// // return $query->when(
|
|
||||||
// // $data['sport_id'],
|
|
||||||
// // function (Builder $query, $sport_id) {
|
|
||||||
// // $query->where('sport_id', $sport_id);
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// // )->when(
|
|
||||||
// // $data['competition_group_id'],
|
|
||||||
// // fn (Builder $query, $competition_group_id) => $query->whereIn('sport_id', $competition_group_id)
|
|
||||||
|
|
||||||
// // )->when(
|
|
||||||
// // $data['starttime_period'],
|
|
||||||
// // function (Builder $query, $starttime_period) {
|
|
||||||
|
|
||||||
// // // dd($starttime_period);
|
|
||||||
|
|
||||||
// // if (isset($starttime_period['start']) && isset($starttime_period['end'])) {
|
|
||||||
// // $from = Carbon::createFromDate($starttime_period['start']);
|
|
||||||
// // $end = Carbon::createFromDate($starttime_period['end']);
|
|
||||||
|
|
||||||
// // return $query
|
|
||||||
// // ->where('starttime', '>=', $from)
|
|
||||||
// // ->where('starttime', '<=', $end);
|
|
||||||
// // } elseif (isset($starttime_period['start'])) {
|
|
||||||
// // $from = Carbon::createFromDate($starttime_period['start']);
|
|
||||||
|
|
||||||
// // return $query
|
|
||||||
// // ->where('starttime', '>=', $from);
|
|
||||||
// // } elseif (isset($starttime_period['end'])) {
|
|
||||||
// // $end = Carbon::createFromDate($starttime_period['end']);
|
|
||||||
|
|
||||||
// // return $query
|
|
||||||
// // ->where('starttime', '<=', $end);
|
|
||||||
// // }
|
|
||||||
// // }
|
|
||||||
// // );
|
|
||||||
// // })->indicateUsing(function (array $data): array {
|
|
||||||
// // $indicators = [];
|
|
||||||
|
|
||||||
// // if ($data['starttime_period'] ?? null) {
|
|
||||||
// // $span = $data['starttime_period'];
|
|
||||||
// // $text = '';
|
|
||||||
// // if ($span['start'] ?? null) {
|
|
||||||
// // $text .= Carbon::parse($span['start'])->format('d. M.');
|
|
||||||
// // }
|
|
||||||
// // if ($span['end'] ?? null) {
|
|
||||||
// // $text .= ' - '.Carbon::parse($span['end'])->format('d. M.');
|
|
||||||
// // }
|
|
||||||
// // if ($text) {
|
|
||||||
// // $indicators[] = Indicator::make($text)->removeField('starttime_period.start')->color('info');
|
|
||||||
// // }
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// // if ($data['competition_group_id'] ?? null) {
|
|
||||||
// // $competition_groups = CompetitionGroup::whereIn('id', $data['competition_group_id'])->pluck('name')->toArray();
|
|
||||||
// // if (count($competition_groups) > 1) {
|
|
||||||
// // $indicators[] = Indicator::make(implode(', ', $competition_groups))->removeField('competition_group_id')->color('info');
|
|
||||||
// // } else {
|
|
||||||
// // $indicators[] = Indicator::make($competition_groups[0])->removeField('competition_group_id')->color('info')->color('info');
|
|
||||||
// // }
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// // return $indicators;
|
|
||||||
// // }),
|
|
||||||
// ], layout: FiltersLayout::AboveContent)
|
|
||||||
// ->deferFilters(false)
|
|
||||||
// ->hiddenFilterIndicators(false)
|
|
||||||
// ->persistFiltersInSession()
|
|
||||||
->recordActions([
|
->recordActions([
|
||||||
EditAction::make(),
|
EditAction::make(),
|
||||||
])
|
])
|
||||||
|
|||||||
Reference in new issue
Block a user