From 1b5282d61dc5af79863fb546a8cc0d7d0780f46f Mon Sep 17 00:00:00 2001 From: salam Date: Mon, 27 Apr 2026 07:42:30 +0200 Subject: [PATCH] statistiko dedicated page wip --- .../Pages/CreateStatisticEvents.php | 11 + .../Pages/EditStatisticEvents.php | 19 + .../Pages/ListStatisticEvents.php | 19 + .../Schemas/StatisticEventsForm.php | 16 + .../StatisticEventsResource.php | 47 +++ .../Tables/StatisticEventsTable.php | 352 ++++++++++++++++++ .../Clusters/Statistic/StatisticCluster.php | 16 + app/Filament/Clusters/User/UserCluster.php | 2 +- app/Filament/Pages/EventMapper.php | 2 +- .../Resources/Events/Tables/EventsTable.php | 4 - .../Tables/Columns/StatisticEventColumn.php | 10 - app/Livewire/StatisticEventChart.php | 164 -------- .../statistic-event-chart.blade.php | 26 -- .../columns/statistic-event-column.blade.php | 7 - 14 files changed, 482 insertions(+), 213 deletions(-) create mode 100644 app/Filament/Clusters/Statistic/Resources/StatisticEvents/Pages/CreateStatisticEvents.php create mode 100644 app/Filament/Clusters/Statistic/Resources/StatisticEvents/Pages/EditStatisticEvents.php create mode 100644 app/Filament/Clusters/Statistic/Resources/StatisticEvents/Pages/ListStatisticEvents.php create mode 100644 app/Filament/Clusters/Statistic/Resources/StatisticEvents/Schemas/StatisticEventsForm.php create mode 100644 app/Filament/Clusters/Statistic/Resources/StatisticEvents/StatisticEventsResource.php create mode 100644 app/Filament/Clusters/Statistic/Resources/StatisticEvents/Tables/StatisticEventsTable.php create mode 100644 app/Filament/Clusters/Statistic/StatisticCluster.php delete mode 100644 app/Filament/Tables/Columns/StatisticEventColumn.php delete mode 100644 app/Livewire/StatisticEventChart.php delete mode 100644 resources/views/components/statistic-event-chart.blade.php delete mode 100644 resources/views/filament/tables/columns/statistic-event-column.blade.php diff --git a/app/Filament/Clusters/Statistic/Resources/StatisticEvents/Pages/CreateStatisticEvents.php b/app/Filament/Clusters/Statistic/Resources/StatisticEvents/Pages/CreateStatisticEvents.php new file mode 100644 index 00000000..7771b26e --- /dev/null +++ b/app/Filament/Clusters/Statistic/Resources/StatisticEvents/Pages/CreateStatisticEvents.php @@ -0,0 +1,11 @@ +components([ + // + ]); + } +} diff --git a/app/Filament/Clusters/Statistic/Resources/StatisticEvents/StatisticEventsResource.php b/app/Filament/Clusters/Statistic/Resources/StatisticEvents/StatisticEventsResource.php new file mode 100644 index 00000000..2e368088 --- /dev/null +++ b/app/Filament/Clusters/Statistic/Resources/StatisticEvents/StatisticEventsResource.php @@ -0,0 +1,47 @@ + ListStatisticEvents::route('/'), + ]; + } +} diff --git a/app/Filament/Clusters/Statistic/Resources/StatisticEvents/Tables/StatisticEventsTable.php b/app/Filament/Clusters/Statistic/Resources/StatisticEvents/Tables/StatisticEventsTable.php new file mode 100644 index 00000000..ff8acc7b --- /dev/null +++ b/app/Filament/Clusters/Statistic/Resources/StatisticEvents/Tables/StatisticEventsTable.php @@ -0,0 +1,352 @@ +striped() + ->columns([ + IconColumn::make('sport_id') + ->label('') + ->icon(fn (string $state): string => match ($state) { + '1' => 'icon-soccerball', + '2' => 'icon-icehockey', + '3' => 'icon-basketball', + '5' => 'icon-tennisball', + }), + TextColumn::make('league.name'), + TextColumn::make('starttime')->dateTime('M j, Y')->label('Date'), + TextColumn::make('home.name')->color('primary'), + TextColumn::make('away.name')->color('success'), + ]) + ->filters([ + Filter::make('events') + ->columns(5)->columnSpan(5) + ->schema([ + Select::make('sport_id') + ->default(1) + ->hiddenLabel() + ->label('') + ->label('Sport') + ->options(Sport::whereIn('id', [1, 2, 3, 5])->pluck('name', 'id')), + Select::make(name: 'country_id') + ->hidden(fn (Get $get) => $get('sport_id') == 5) + ->placeholder('Country') + ->prefixIcon('phosphor-flag') + ->hiddenLabel() + ->label('') + ->multiple() + ->searchable() + ->preload() + ->options(function (Get $get) { + $res = Event::where('has_markets', 1) + ->where('sport_id', $get('sport_id')) + ->where('starttime', '>=', Carbon::now()) + ->groupBy('country_id') + ->pluck('country_id')->toArray(); + + return Country::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id'); + }) + ->live() + ->reactive() + ->afterStateUpdated(function (callable $set) { + $set('competition_group_id', null); + }), + 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) { + $country_id = $get('country_id') ?? 0; + if ($country_id) { + $res = Event::with('country') + ->with('competition_group') + ->where('sport_id', $get('sport_id')) + ->whereIn('country_id', $country_id) + ->where('starttime', '>', Carbon::now()) + ->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 = []; + 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::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') + ->prefix(fn () => new HtmlString('From')) + ->displayFormat('d M Y') + ->hiddenLabel() + ->label(''), + DatePicker::make('starttime_to') + ->prefix(fn () => new HtmlString('To:')) + ->displayFormat('d M Y') + ->hiddenLabel() + ->label(''), + ]) + ->query(function (Builder $query, array $data): Builder { + return $query->when( + $data['sport_id'], + function (Builder $query, $sport_id) { + $query->where('sport_id', (int) $sport_id); + } + )->when( + $data['starttime_from'], + function (Builder $query, $starttime_from) { + if (isset($starttime_from)) { + $from = Carbon::createFromDate($starttime_from); + + return $query->where('starttime', '>=', $starttime_from); + } + } + )->when( + $data['starttime_to'], + function (Builder $query, $starttime_to) { + if (isset($starttime_to)) { + $to = Carbon::createFromDate($starttime_to); + + return $query->where('starttime', '<=', $starttime_to); + } + } + ); + })->indicateUsing(function (array $data): array { + $indicators = []; + + if ($data['starttime_from'] ?? null) { + $starttime_from = $data['starttime_from']; + if ($starttime_from ?? null) { + $text = Carbon::parse($starttime_from)->format('d. M. Y'); + $indicators[] = Indicator::make('From: '.$text)->removeField('starttime_from')->color('info'); + } + } + if ($data['starttime_to'] ?? null) { + $starttime_to = $data['starttime_to']; + if ($starttime_to ?? null) { + $text = Carbon::parse($starttime_to)->format('d. M. Y'); + $indicators[] = Indicator::make('To: '.$text)->removeField('starttime_to')->color('success'); + } + } + + // 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) + // ->filters([ + // Filter::make('events') + // ->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([ + EditAction::make(), + ]) + ->toolbarActions([ + BulkActionGroup::make([ + DeleteBulkAction::make(), + ]), + ]); + } +} diff --git a/app/Filament/Clusters/Statistic/StatisticCluster.php b/app/Filament/Clusters/Statistic/StatisticCluster.php new file mode 100644 index 00000000..d4a19b81 --- /dev/null +++ b/app/Filament/Clusters/Statistic/StatisticCluster.php @@ -0,0 +1,16 @@ +description(fn ($record) => ucwords($record->group?->name)), EventColumn::make('event'), - StatisticEventColumn::make('statistic-event') - ->label('') - ->alignCenter(), TooltipOdds::make('ml')->bettype('odds_2ways')->label('')->visible(fn () => in_array('odds_2ways', self::$bettype_settings)), ColumnOdds::make('odds_2ways')->bettype('odds_2ways') diff --git a/app/Filament/Tables/Columns/StatisticEventColumn.php b/app/Filament/Tables/Columns/StatisticEventColumn.php deleted file mode 100644 index 83cd36df..00000000 --- a/app/Filament/Tables/Columns/StatisticEventColumn.php +++ /dev/null @@ -1,10 +0,0 @@ -'; - // $str .= '
'.$this->record->country->name.' '.$this->record->group->name.'
'; - // if ($this->record->home->betsapi_image_id) { - // $str .= ' '; - // } - // $str .= '
'.$this->record->home->name.'
'; - // $str .= '
vs
'; - // $str .= '
'.$this->record->away->name.'
'; - // if ($this->record->away->betsapi_image_id) { - // $str .= ' '; - // } - // $str .= ''; - - return new HtmlString($this->record->country->name.' '.$this->record->group->name); - } - - public function filtersSchema(Schema $schema): Schema - { - return $schema->schema([ - Select::make('data_mode') - ->default('gls') - ->options([ - 'gls' => 'Goals', - 'crn' => 'Corner', - 'fls' => 'Committed Fouls', - 'ofs' => 'Offsides', - 'crd' => 'Cards', - 'snt' => 'Shots on target', - 'tsh' => 'TotalShots', - ]), - Select::make('claculation_mode') - ->default('punctual') - ->options([ - 'punctual' => 'Punctual', - 'average' => 'Moving average', - ]), - ]); - } - - protected function getData(): array - { - $data_mode = $this->filters['data_mode'] ?? null; - $claculation_mode = $this->filters['claculation_mode'] ?? null; - - $res = StatistikoEvent::where('league_id', $this->record['competition_group_id']) - ->where('home_id', $this->record['home_id']) - // ->where('away_id', $this->record['away_id']) - ->get(); - - switch ($data_mode) { - case 'crn': - $h = 'crn_h'; - $a = 'crn_a'; - break; - case 'fls': - $h = 'fls_h'; - $a = 'fls_a'; - break; - case 'ofs': - $h = 'ofs_h'; - $a = 'ofs_a'; - break; - case 'crd': - $h = 'crd_h'; - $a = 'crd_a'; - break; - case 'snt': - $h = 'snt_h'; - $a = 'snt_a'; - break; - case 'tsh': - $h = 'tsh_h'; - $a = 'tsh_a'; - break; - - default: - $h = 'gls_h'; - $a = 'gls_a'; - break; - } - - $starttimes = []; - $data_home = []; - $data_away = []; - foreach ($res as $event) { - $data_home[] = $event[$h]; - $data_away[] = $event[$a]; - $starttimes[] = $event['starttime']->format('d.m.Y'); - } - - return [ - 'datasets' => [ - [ - 'label' => $this->record->home->name, - 'data' => $data_home, - 'backgroundColor' => '#155dfc', - 'borderColor' => '#2b7fff', - ], - [ - 'label' => $this->record->away->name, - 'data' => $data_away, - 'backgroundColor' => '#00a63e', - 'borderColor' => '#00c950', - ], - ], - 'labels' => $starttimes, - 'scales' => $this->getOptions(), - ]; - } - - protected function getOptions(): array - { - return [ - 'scales' => [ - 'y' => [ - 'ticks' => [ - 'precision' => 0, // Forces integers - 'beginAtZero' => true, - ], - ], - ], - 'plugins' => [ - 'legend' => [ - 'display' => true, - 'position' => 'top', // Set position to 'top' - ], - ], - ]; - } - - // ], layout: FiltersLayout::AboveContent) - - protected function getType(): string - { - return 'line'; - } -} diff --git a/resources/views/components/statistic-event-chart.blade.php b/resources/views/components/statistic-event-chart.blade.php deleted file mode 100644 index 15f02094..00000000 --- a/resources/views/components/statistic-event-chart.blade.php +++ /dev/null @@ -1,26 +0,0 @@ -
- - -
{{ $record->country->name }} {{ $record->group->name }}
-
- @if ($record->home->betsapi_image_id) - - @endif -
{{ $record->home->name }}
-
vs
-
{{ $record->away->name }}
- @if ($record->away->betsapi_image_id) - - @endif -
-
-
- - -
-
- - @livewire(\App\Livewire\StatisticEventChart::class) -
diff --git a/resources/views/filament/tables/columns/statistic-event-column.blade.php b/resources/views/filament/tables/columns/statistic-event-column.blade.php deleted file mode 100644 index 79cb77fb..00000000 --- a/resources/views/filament/tables/columns/statistic-event-column.blade.php +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - @livewire('statistic-event-chart', ['record' => $record]) -