408 lines
22 KiB
PHP
408 lines
22 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Events\Tables;
|
|
|
|
use App\Filament\Resources\Events\Tables\Tools\LoadBettypeSettings;
|
|
use App\Filament\Resources\Events\Tables\Tools\LoadMultilineBookmaker;
|
|
use App\Filament\Tables\Columns\Column3way;
|
|
use App\Filament\Tables\Columns\Column3wayHt;
|
|
use App\Filament\Tables\Columns\ColumnDc;
|
|
use App\Filament\Tables\Columns\ColumnDnb;
|
|
use App\Filament\Tables\Columns\ColumnGgng;
|
|
use App\Filament\Tables\Columns\ColumnMl;
|
|
use App\Filament\Tables\Columns\ColumnMlS1;
|
|
use App\Filament\Tables\Columns\ColumnPoint;
|
|
use App\Filament\Tables\Columns\ColumnPointQ1;
|
|
use App\Filament\Tables\Columns\ColumnTotal;
|
|
use App\Filament\Tables\Columns\ColumnTotalHt;
|
|
use App\Filament\Tables\Columns\ColumnTotalQ1;
|
|
use App\Filament\Tables\Columns\ColumnTq;
|
|
use App\Filament\Tables\Columns\EventColumn;
|
|
use App\Filament\Tables\Columns\MatchIds;
|
|
use App\Filament\Tables\Columns\TooltipOdds;
|
|
use App\Models\CompetitionGroup;
|
|
use App\Models\Country;
|
|
use App\Models\Event;
|
|
use App\Models\EventUserStar;
|
|
use App\Models\Group;
|
|
use App\Models\Sport;
|
|
use App\Models\User;
|
|
use CodeWithKyrian\FilamentDateRange\Forms\Components\DateRangePicker;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\ActionGroup;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Schemas\Components\Utilities\Get;
|
|
use Filament\Support\Enums\FontWeight;
|
|
use Filament\Support\Enums\VerticalAlignment;
|
|
use Filament\Tables\Columns\IconColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Enums\FiltersLayout;
|
|
use Filament\Tables\Filters\Filter;
|
|
use Filament\Tables\Filters\Indicator;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class EventsTable
|
|
{
|
|
public static $user;
|
|
|
|
public static $bettype_settings;
|
|
|
|
public static $multiline_bookmaker;
|
|
|
|
public static function configure(Table $table): Table
|
|
{
|
|
self::$user = User::getUser();
|
|
|
|
self::$bettype_settings = LoadBettypeSettings::load();
|
|
|
|
self::$multiline_bookmaker = LoadMultilineBookmaker::load();
|
|
|
|
return $table
|
|
->poll('10s')
|
|
->striped()
|
|
->deferLoading()
|
|
->defaultPaginationPageOption(5)
|
|
->paginated([5, 10, 15])
|
|
->columns([
|
|
IconColumn::make('sport.icon')
|
|
->label('')
|
|
->icon(fn ($record) => $record->sport->icon)
|
|
->tooltip(fn ($record) => $record->id)
|
|
->visibleFrom('lg'),
|
|
|
|
MatchIds::make('ids')->grow(false)->visibleFrom('xl'),
|
|
|
|
TextColumn::make('starttime')
|
|
->label('Start')
|
|
->alignCenter()
|
|
->dateTime('H:i')
|
|
->weight(FontWeight::Bold)
|
|
->description(fn ($state): string => Carbon::createFromDate($state)->format('d. M')),
|
|
|
|
TextColumn::make('country.name')
|
|
->wrap()
|
|
->hidden(fn () => self::$user->sport_id == 5)
|
|
->color('gray')
|
|
->icon(fn ($record) => $record->country?->icon),
|
|
|
|
EventColumn::make('event'),
|
|
|
|
TooltipOdds::make('ml')->bettype('odds_2ways')->label('')->visible(fn () => in_array('odds_2ways', self::$bettype_settings)),
|
|
ColumnMl::make('odds_2ways')->bookmakers(self::$multiline_bookmaker['odds_2ways'] ?? [])
|
|
->visible(fn () => in_array('odds_2ways', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->alignCenter()
|
|
->label('ML'),
|
|
|
|
TooltipOdds::make('mls1')->bettype('odds_2ways_s1')->label('')->visible(fn () => in_array('odds_2ways_s1', self::$bettype_settings)),
|
|
ColumnMlS1::make('odds_2ways_s1')->bookmakers(self::$multiline_bookmaker['odds_2ways'] ?? [])
|
|
->visible(fn () => in_array('odds_2ways_s1', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->alignCenter()
|
|
->label('ML S1'),
|
|
|
|
TooltipOdds::make('1x2')->bettype('odds_3ways')->label('')->visible(fn () => in_array('odds_3ways', self::$bettype_settings)),
|
|
Column3way::make('odds_3ways')->bookmakers(self::$multiline_bookmaker['odds_3ways'] ?? [])
|
|
->visible(fn () => in_array('odds_3ways', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->alignCenter()
|
|
->label('1X2'),
|
|
|
|
TooltipOdds::make('total')->bettype('odds_totals')->label('')->visible(fn () => in_array('odds_totals', self::$bettype_settings)),
|
|
ColumnTotal::make('odds_totals')->bookmakers(self::$multiline_bookmaker['odds_totals'] ?? [])
|
|
->visible(fn () => in_array('odds_totals', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->alignCenter()
|
|
->label('Totals'),
|
|
|
|
TooltipOdds::make('1x2ht')->bettype('odds_3ways_ht')->label('')->visible(fn () => in_array('odds_3ways_ht', self::$bettype_settings)),
|
|
Column3wayHt::make('odds_3ways_ht')->bookmakers(self::$multiline_bookmaker['odds_3ways_ht'] ?? [])
|
|
->visible(fn () => in_array('odds_3ways_ht', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->alignCenter()
|
|
->label('1X2 HT'),
|
|
|
|
TooltipOdds::make('total_ht')->bettype('odds_totals_ht')->label('')->visible(fn () => in_array('odds_totals_ht', self::$bettype_settings)),
|
|
ColumnTotalHt::make('odds_totals_ht')->bookmakers(self::$multiline_bookmaker['odds_totals_ht'] ?? [])
|
|
->visible(fn () => in_array('odds_totals_ht', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->alignCenter()
|
|
->label('Totals HT'),
|
|
|
|
TooltipOdds::make('ggng')->bettype('odds_ggng')->label('')->visible(fn () => in_array('odds_ggng', self::$bettype_settings)),
|
|
ColumnGgng::make('odds_ggng')->bookmakers(self::$multiline_bookmaker['odds_ggng'] ?? [])
|
|
->visible(fn () => \in_array('odds_ggng', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->alignCenter()
|
|
->label('Goal No Goal'),
|
|
|
|
TooltipOdds::make('points')->bettype('odds_points')->label('')->visible(fn () => in_array('odds_points', self::$bettype_settings)),
|
|
ColumnPoint::make('odds_points')->bookmakers(self::$multiline_bookmaker['odds_points'] ?? [])
|
|
->visible(fn () => in_array('odds_points', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->alignCenter()
|
|
->label('Points'),
|
|
|
|
TooltipOdds::make('total_q1')->bettype('odds_totals_q1')->label('')->visible(fn () => in_array('odds_totals_q1', self::$bettype_settings)),
|
|
ColumnTotalQ1::make('odds_totals_q1')->bookmakers(self::$multiline_bookmaker['odds_totals_q1'] ?? [])
|
|
->visible(fn () => in_array('odds_totals_q1', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->alignCenter()
|
|
->label('Totals Q1'),
|
|
|
|
TooltipOdds::make('points_q1')->bettype('odds_points_q1')->label('')->visible(fn () => in_array('odds_points_q1', self::$bettype_settings)),
|
|
ColumnPointQ1::make('odds_points_q1')->bookmakers(self::$multiline_bookmaker['odds_points_q1'] ?? [])
|
|
->visible(fn () => in_array('odds_points_q1', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->alignCenter()
|
|
->label('Points Q1'),
|
|
|
|
TooltipOdds::make('dc')->bettype('odds_dc')->label('')->visible(fn () => in_array('odds_dc', self::$bettype_settings)),
|
|
ColumnDc::make('odds_dc')->bookmakers(self::$multiline_bookmaker['odds_dc'] ?? [])
|
|
->visible(fn () => \in_array('odds_dc', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->alignCenter()
|
|
->label('Double Chance'),
|
|
|
|
TooltipOdds::make('tq')->bettype('odds_tq')->label('')->visible(fn () => in_array('odds_tq', self::$bettype_settings)),
|
|
ColumnTq::make('odds_tq')->bookmakers(self::$multiline_bookmaker['odds_tq'] ?? [])
|
|
->visible(fn () => \in_array('odds_tq', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->alignCenter()
|
|
->label('To Qualify'),
|
|
|
|
TooltipOdds::make('dnb')->bettype('odds_dnb')->label('')->visible(fn () => in_array('odds_dnb', self::$bettype_settings)),
|
|
ColumnDnb::make('odds_dnb')->bookmakers(self::$multiline_bookmaker['odds_dnb'] ?? [])
|
|
->visible(fn () => \in_array('odds_dnb', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->alignCenter()
|
|
->label('Draw No Bet'),
|
|
|
|
])->searchable(['id', 'home.name', 'away.name', 'betsapi_id', 'betradar_id', 'bet365_id', 'bwin_id', 'magnig_id', 'magken_id', 'lognig_id', 'logcol_id'])
|
|
->defaultSort('starttime', 'ASC')
|
|
->extremePaginationLinks()
|
|
->filters([
|
|
Filter::make('events')
|
|
->columns(5)->columnSpan(5)
|
|
->schema([
|
|
Select::make(name: 'sport_id')
|
|
->options(fn () => Sport::getSportForClient())
|
|
->default(self::$user->sport_id)
|
|
->prefixIcon(self::$user->sport->icon)
|
|
->selectablePlaceholder(false)
|
|
->hiddenLabel()
|
|
->afterStateUpdated(function (callable $set, $state, $livewire) {
|
|
|
|
User::where('id', self::$user->id)->update(['sport_id' => (int) $state]);
|
|
|
|
$livewire->dispatch('refreshBettypeMenu');
|
|
|
|
$set('country_id', null);
|
|
$set('competition_group_id', null);
|
|
$set('group_id', null);
|
|
|
|
}),
|
|
Select::make(name: 'country_id')
|
|
->hidden(fn () => self::$user->sport_id == 5)
|
|
->placeholder('Country')
|
|
->hiddenLabel()
|
|
->label('')
|
|
->multiple()
|
|
->searchable()
|
|
->preload()
|
|
->options(function () {
|
|
$res = Event::where('sport_id', self::$user->sport_id)->where('starttime', '>', Carbon::now())->groupBy('country_id')->pluck('country_id')->toArray();
|
|
|
|
return Country::query()->whereIn('id', $res)->pluck('name', 'id');
|
|
})
|
|
->live()
|
|
->reactive()
|
|
->afterStateUpdated(function (callable $set) {
|
|
$set('competition_group_id', null);
|
|
}),
|
|
Select::make('competition_group_id')
|
|
->hidden(fn () => self::$user->sport_id == 5)
|
|
->placeholder('League')
|
|
->hiddenLabel()
|
|
->label('')
|
|
->multiple()
|
|
->searchable()
|
|
->options(function (Get $get) {
|
|
if ($get('country_id')) {
|
|
$res = Event::where('sport_id', self::$user->sport_id)->with('country')->with('competition_group')->where('country_id', $get('country_id'))->where('starttime', '>', Carbon::now())->groupBy('competition_group_id')->get();
|
|
} else {
|
|
$res = Event::where('sport_id', self::$user->sport_id)->with('country')->with('competition_group')->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('group_id')
|
|
->visible(fn () => self::$user->sport_id == 5)
|
|
->placeholder('Tournament')
|
|
->hiddenLabel()
|
|
->label('')
|
|
->multiple()
|
|
->searchable()
|
|
->options(function (Get $get) {
|
|
if ($get('country_id')) {
|
|
$res = Event::with('country')->where('sport_id', self::$user->sport_id)->with('group')->where('country_id', $get('country_id'))->where('starttime', '>', Carbon::now())->groupBy('group_id')->get();
|
|
} else {
|
|
$res = Event::with('country')->where('sport_id', self::$user->sport_id)->with('group')->where('starttime', '>', Carbon::now())->groupBy('group_id')->get();
|
|
}
|
|
$arr = [];
|
|
foreach ($res as $val) {
|
|
$arr[$val->group_id] = $val->country?->name.' '.$val->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'],
|
|
fn (Builder $query, $sport_id) => $query->where('sport_id', $sport_id)
|
|
)->when(
|
|
$data['country_id'],
|
|
fn (Builder $query, $country_id) => $query->where('country_id', $country_id)
|
|
)->when(
|
|
$data['group_id'],
|
|
fn (Builder $query, $group_id) => $query->whereIn('group_id', $group_id)
|
|
)->when(
|
|
$data['competition_group_id'],
|
|
fn (Builder $query, $competition_group_id) => $query->whereIn('competition_group_id', $competition_group_id)
|
|
)->when(
|
|
$data['starttime_period'],
|
|
function (Builder $query, $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
|
|
->whereDate('starttime', '>=', $from->format('Y-m-d 00:00:00'))
|
|
->whereDate('starttime', '<=', $end->format('Y-m-d 00:00:00'));
|
|
} elseif (isset($starttime_period['start'])) {
|
|
$from = Carbon::createFromDate($starttime_period['start']);
|
|
|
|
return $query
|
|
->whereDate('starttime', '>=', $from->format('Y-m-d 00:00:00'));
|
|
} elseif (isset($starttime_period['end'])) {
|
|
$end = Carbon::createFromDate($starttime_period['end']);
|
|
|
|
return $query
|
|
->whereDate('starttime', '<=', $end->format('Y-m-d 00:00:00'));
|
|
}
|
|
}
|
|
);
|
|
})->indicateUsing(function (array $data): array {
|
|
$indicators = [];
|
|
if ($data['country_id'] ?? null) {
|
|
$countries = Country::whereIn('id', $data['country_id'])->pluck('name')->toArray();
|
|
if (count($countries) > 1) {
|
|
$indicators[] = Indicator::make('Countries: '.implode(', ', $countries))->removeField('country_id')->color('info');
|
|
} else {
|
|
$indicators[] = Indicator::make('Country: '.$countries[0])->removeField('country_id')->color('info');
|
|
}
|
|
}
|
|
|
|
if ($data['group_id'] ?? null) {
|
|
$group_ids = Group::whereIn('id', $data['group_id'])->pluck('name')->toArray();
|
|
if (count($group_ids) > 1) {
|
|
$indicators[] = Indicator::make('Tournament: '.implode(', ', $group_ids))->removeField('group_id')->color('info');
|
|
} else {
|
|
$indicators[] = Indicator::make('Tournaments: '.$group_ids[0])->removeField('group_id')->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('Leagues: '.implode(', ', $competition_groups))->removeField('competition_group_id')->color('info');
|
|
} else {
|
|
$indicators[] = Indicator::make('League: '.$competition_groups[0])->removeField('competition_group_id')->color('info')->color('info');
|
|
}
|
|
}
|
|
|
|
if ($data['starttime_period'] ?? null) {
|
|
$span = $data['starttime_period'];
|
|
$text = '';
|
|
if ($span['start'] ?? null) {
|
|
$text .= 'From '.Carbon::parse($span['start'])->toFormattedDateString();
|
|
}
|
|
if ($span['end'] ?? null) {
|
|
$text .= ' To '.Carbon::parse($span['end'])->toFormattedDateString();
|
|
}
|
|
if ($text) {
|
|
$indicators[] = Indicator::make($text)->removeField('starttime_period.start')->color('info');
|
|
}
|
|
}
|
|
|
|
if ($data['stars_status'] ?? null) {
|
|
$indicators[] = Indicator::make('Favorits')->removeField('stars_status')->color('info');
|
|
}
|
|
|
|
return $indicators;
|
|
}),
|
|
], layout: FiltersLayout::AboveContent)
|
|
->deferFilters(false)
|
|
->persistFiltersInSession()
|
|
->recordActions([
|
|
Action::make('star')
|
|
->iconButton()
|
|
// ->color('gray')
|
|
->icon(function ($record) {
|
|
if (isset($record->event_user_star->id)) {
|
|
return 'phosphor-star-fill';
|
|
} else {
|
|
return 'phosphor-star';
|
|
}
|
|
})
|
|
->tooltip('Add to favorits')
|
|
->action(function ($record) {
|
|
$res = EventUserStar::where('event_id', $record->id)
|
|
->where('user_id', self::$user->id)
|
|
->first();
|
|
if ($res) {
|
|
EventUserStar::find($res->id)->delete();
|
|
} else {
|
|
EventUserStar::insert(['event_id' => $record->id, 'user_id' => self::$user->id]);
|
|
}
|
|
}),
|
|
ActionGroup::make([
|
|
// EditAction::make(),
|
|
DeleteAction::make()->visible(fn () => self::$user->hasRole('super_admin')),
|
|
Action::make('txodds_odds')
|
|
->label('TxOdds')
|
|
->disabled(fn () => ! self::$user->hasRole('super_admin'))
|
|
->icon('phosphor-arrow-square-out')
|
|
->url(fn ($record): string => route('txodds_odds', ['sportid' => $record->sport_id, 'txoddsid' => $record->id]))
|
|
->openUrlInNewTab(),
|
|
])->iconButton()
|
|
->icon('phosphor-dots-three-vertical'),
|
|
])->toolbarActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make()->visible(fn () => self::$user->hasRole('super_admin')),
|
|
]),
|
|
]);
|
|
}
|
|
}
|