691 lines
37 KiB
PHP
691 lines
37 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Events\Tables;
|
|
|
|
use App\Filament\Resources\Events\Tables\Tools\CompareOptions;
|
|
use App\Filament\Resources\Events\Tables\Tools\LoadBettypeSettings;
|
|
use App\Filament\Resources\Events\Tables\Tools\LoadCompareDifferences;
|
|
use App\Filament\Resources\Events\Tables\Tools\LoadMultiline;
|
|
use App\Filament\Tables\Columns\ColumnOdds;
|
|
use App\Filament\Tables\Columns\ColumnStarttime;
|
|
use App\Filament\Tables\Columns\EventColumn;
|
|
use App\Filament\Tables\Columns\MatchIds;
|
|
use App\Filament\Tables\Columns\StatisticEventColumn;
|
|
use App\Filament\Tables\Columns\TooltipOdds;
|
|
use App\Models\ClientGroupList;
|
|
use App\Models\CompetitionGroup;
|
|
use App\Models\Country;
|
|
use App\Models\Event;
|
|
use App\Models\EventBookmaker;
|
|
use App\Models\EventUserNote;
|
|
use App\Models\EventUserStar;
|
|
use App\Models\Group;
|
|
use App\Models\OddsTable;
|
|
use CodeWithKyrian\FilamentDateRange\Forms\Components\DateRangePicker;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\ActionGroup;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Forms\Components\Hidden;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Schemas\Components\Utilities\Get;
|
|
use Filament\Support\Enums\VerticalAlignment;
|
|
use Filament\Support\Enums\Width;
|
|
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\Contracts\View\View;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class EventsTable
|
|
{
|
|
public static $user;
|
|
|
|
public static $bettype_settings;
|
|
|
|
public static $slots;
|
|
|
|
public static $bookmaker;
|
|
|
|
public static $filter;
|
|
|
|
public static function configure(Table $table): Table
|
|
{
|
|
LoadMultiline::load();
|
|
|
|
LoadBettypeSettings::load();
|
|
|
|
return $table
|
|
->striped()
|
|
->poll('10s')
|
|
->deferLoading()
|
|
->defaultPaginationPageOption(5)
|
|
->extremePaginationLinks()
|
|
->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')
|
|
->visible(fn () => auth()->user()->hasRole('super_admin')),
|
|
ColumnStarttime::make('start'),
|
|
TextColumn::make('country.name')
|
|
->label('League')
|
|
->wrap()
|
|
->hidden(fn () => auth()->user()->sport_id == 5)
|
|
->color('gray')
|
|
->icon(fn ($record) => $record->country?->icon)
|
|
->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')
|
|
->visible(fn () => in_array('odds_2ways', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->label('ML'),
|
|
|
|
TooltipOdds::make('mls1')->bettype('odds_2ways_s1')->label('')->visible(fn () => in_array('odds_2ways_s1', self::$bettype_settings)),
|
|
ColumnOdds::make('odds_2ways_s1')->bettype('odds_2ways_s1')
|
|
->visible(fn () => in_array('odds_2ways_s1', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->label('ML S1'),
|
|
|
|
TooltipOdds::make('1x2')->bettype('odds_3ways')->label('')->visible(fn () => in_array('odds_3ways', self::$bettype_settings)),
|
|
ColumnOdds::make('odds_3ways')
|
|
->bettype('odds_3ways')
|
|
->visible(fn () => in_array('odds_3ways', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->label('1X2'),
|
|
|
|
TooltipOdds::make('1x2ht')->bettype('odds_3ways_ht')->label('')->visible(fn () => in_array('odds_3ways_ht', self::$bettype_settings)),
|
|
ColumnOdds::make('odds_3ways_ht')->bettype('odds_3ways_ht')
|
|
->visible(fn () => in_array('odds_3ways_ht', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->label('1X2 HT'),
|
|
|
|
TooltipOdds::make('total')->bettype('odds_totals')->label('')->visible(fn () => in_array('odds_totals', self::$bettype_settings)),
|
|
ColumnOdds::make('odds_totals')->bettype('odds_totals')
|
|
->visible(fn () => in_array('odds_totals', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->label('Totals'),
|
|
|
|
TooltipOdds::make('total_ht')->bettype('odds_totals_ht')->label('')->visible(fn () => in_array('odds_totals_ht', self::$bettype_settings)),
|
|
ColumnOdds::make('odds_totals_ht')->bettype('odds_totals_ht')
|
|
->visible(fn () => in_array('odds_totals_ht', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->label('Totals HT'),
|
|
|
|
TooltipOdds::make('total_q1')->bettype('odds_totals_q1')->label('')->visible(fn () => in_array('odds_totals_q1', self::$bettype_settings)),
|
|
ColumnOdds::make('odds_totals_q1')->bettype('odds_totals_q1')
|
|
->visible(fn () => in_array('odds_totals_q1', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->alignCenter()
|
|
->label('Totals Q1'),
|
|
|
|
TooltipOdds::make('points')->bettype('odds_points')->label('')->visible(fn () => in_array('odds_points', self::$bettype_settings)),
|
|
ColumnOdds::make('odds_points')->bettype('odds_points')
|
|
->visible(fn () => in_array('odds_points', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->label('Points'),
|
|
|
|
TooltipOdds::make('points_ht')->bettype('odds_points_ht')->label('')->visible(fn () => in_array('odds_points_ht', self::$bettype_settings)),
|
|
ColumnOdds::make('odds_points_ht')->bettype('odds_points_ht')
|
|
->visible(fn () => in_array('odds_points_ht', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->label('Points HT'),
|
|
|
|
TooltipOdds::make('points_q1')->bettype('odds_points_q1')->label('')->visible(fn () => in_array('odds_points_q1', self::$bettype_settings)),
|
|
ColumnOdds::make('odds_points_q1')->bettype('odds_points_q1')
|
|
->visible(fn () => in_array('odds_points_q1', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->label('Points Q1'),
|
|
|
|
TooltipOdds::make('ggng')->bettype('odds_ggng')->label('')->visible(fn () => in_array('odds_ggng', self::$bettype_settings)),
|
|
ColumnOdds::make('odds_ggng')->bettype('odds_ggng')
|
|
->visible(fn () => \in_array('odds_ggng', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->label('Goal No Goal'),
|
|
|
|
TooltipOdds::make('dc')->bettype('odds_dc')->label('')->visible(fn () => in_array('odds_dc', self::$bettype_settings)),
|
|
ColumnOdds::make('odds_dc')->bettype('odds_dc')
|
|
->visible(fn () => \in_array('odds_dc', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->label('Double Chance'),
|
|
|
|
TooltipOdds::make('tq')->bettype('odds_tq')->label('')->visible(fn () => in_array('odds_tq', self::$bettype_settings)),
|
|
ColumnOdds::make('odds_tq')->bettype('odds_tq')
|
|
->visible(fn () => \in_array('odds_tq', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->label('To Qualify'),
|
|
|
|
TooltipOdds::make('dnb')->bettype('odds_dnb')->label('')->visible(fn () => in_array('odds_dnb', self::$bettype_settings)),
|
|
ColumnOdds::make('odds_dnb')->bettype('odds_dnb')
|
|
->visible(fn () => \in_array('odds_dnb', self::$bettype_settings))
|
|
->verticalAlignment(VerticalAlignment::Start)
|
|
->label('Draw No Bet'),
|
|
])
|
|
->searchable(['id', 'home.name', 'away.name', 'betsapi_id', 'betradar_id', 'bet365_id', 'bwin_id', 'event_bookmaker.event_id'])
|
|
->extremePaginationLinks()
|
|
->filters([
|
|
Filter::make('events')
|
|
->columns(7)->columnSpan(7)
|
|
->schema([
|
|
Hidden::make('filter_alarm_green'),
|
|
Hidden::make('filter_alarm_yellow'),
|
|
Hidden::make('filter_alarm_red'),
|
|
Hidden::make('filter_stars'),
|
|
Hidden::make('filter_notes'),
|
|
Hidden::make('filter_periode'),
|
|
Select::make(name: 'country_id')
|
|
->placeholder('Country')
|
|
->prefixIcon('phosphor-flag')
|
|
->hiddenLabel()
|
|
->label('')
|
|
->multiple()
|
|
->searchable()
|
|
->preload()
|
|
->options(function () {
|
|
$res = Event::where('has_markets', 1)
|
|
->where('sport_id', auth()->user()->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')
|
|
->placeholder('League')
|
|
->prefixIcon('phosphor-trophy')
|
|
->hiddenLabel()
|
|
->label('')
|
|
->multiple()
|
|
->searchable()
|
|
->options(function (Get $get) {
|
|
if ($get('country_id')) {
|
|
$res = Event::where('has_markets', 1)
|
|
->with('country')
|
|
->with('competition_group')
|
|
->where('sport_id', auth()->user()->sport_id)
|
|
->where('starttime', '>', Carbon::now())
|
|
->whereIn('country_id', $get('country_id'))
|
|
->groupBy('competition_group_id')->get();
|
|
} else {
|
|
$res = Event::where('has_markets', 1)
|
|
->with('country')
|
|
->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->country?->name.' '.$val->competition_group?->name;
|
|
}
|
|
asort($arr);
|
|
|
|
return $arr;
|
|
})
|
|
->live(),
|
|
Select::make('competition_group_id')
|
|
->visible(fn () => auth()->user()->sport_id == 5)
|
|
->placeholder('Tournament')
|
|
->prefixIcon('phosphor-trophy')
|
|
->columnSpan(2)
|
|
->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(),
|
|
Select::make('client_group_list_id')
|
|
->placeholder('Custom Groups')
|
|
->prefixIcon('phosphor-user-list')
|
|
->searchable()
|
|
->hiddenLabel()
|
|
->label('')
|
|
->preload()
|
|
->options(fn () => ClientGroupList::where('sport_id', auth()->user()->sport_id)
|
|
->where('client_id', auth()->user()->client_id)
|
|
->pluck('name', 'id'))
|
|
->live(),
|
|
|
|
DateRangePicker::make('starttime_period')
|
|
->columnSpan(2)
|
|
->displayFormat('d M Y')
|
|
->minDate(now())
|
|
->hiddenLabel()
|
|
->label('')
|
|
->live(),
|
|
|
|
TextInput::make('favorit_threshold')
|
|
->prefixIcon('phosphor-less-than')
|
|
->hintIconTooltip('Filter Favorit')
|
|
->suffix('Favorit')
|
|
->numeric()
|
|
->minValue(1.01)
|
|
->maxValue(3.00)
|
|
->step(0.01)
|
|
->hiddenLabel()
|
|
->live(),
|
|
|
|
Select::make('filter_compare_differences')
|
|
->placeholder('Compare')
|
|
->prefixIcon('phosphor-funnel')
|
|
->hiddenLabel()
|
|
->allowHtml()
|
|
->options(fn () => CompareOptions::load()),
|
|
])
|
|
->query(function (Builder $query, array $data): Builder {
|
|
return $query->when(
|
|
$data['country_id'],
|
|
function (Builder $query, $country_id) {
|
|
$query->whereIn('country_id', $country_id);
|
|
}
|
|
)->when(
|
|
$data['competition_group_id'],
|
|
fn (Builder $query, $competition_group_id) => $query->whereIn('competition_group_id', $competition_group_id)
|
|
|
|
)->when(
|
|
$data['client_group_list_id'],
|
|
function (Builder $query, $client_group_list_id) {
|
|
$client_group_list_ids = ClientGroupList::where('id', $client_group_list_id)->value('client_groups');
|
|
$query->whereIn('competition_group_id', $client_group_list_ids);
|
|
}
|
|
)->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);
|
|
}
|
|
}
|
|
)->when(
|
|
$data['filter_alarm_green'],
|
|
function (Builder $query, $filter_alarm_green) {
|
|
$res = OddsTable::where('name', $filter_alarm_green)->value('fieldnames');
|
|
$fieldnames = explode(',', $res);
|
|
|
|
return $query->whereHas('event_bookmaker', function ($query) use ($fieldnames) {
|
|
$query->where('bookmaker_id', auth()->user()->bookmaker_id)
|
|
->where(function ($query) use ($fieldnames) {
|
|
foreach ($fieldnames as $field) {
|
|
$query->orWhere($field, 1);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
)->when(
|
|
$data['filter_alarm_yellow'],
|
|
function (Builder $query, $filter_alarm_yellow) {
|
|
$res = OddsTable::where('name', $filter_alarm_yellow)->value('fieldnames');
|
|
$fieldnames = explode(',', $res);
|
|
|
|
return $query->whereHas('event_bookmaker', function ($query) use ($fieldnames) {
|
|
$query->where('bookmaker_id', auth()->user()->bookmaker_id)
|
|
->where(function ($query) use ($fieldnames) {
|
|
foreach ($fieldnames as $field) {
|
|
$query->orWhere($field, 2);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
)->when(
|
|
$data['filter_alarm_red'],
|
|
function (Builder $query, $filter_alarm_red) {
|
|
$res = OddsTable::where('name', $filter_alarm_red)->value('fieldnames');
|
|
$fieldnames = explode(',', $res);
|
|
|
|
return $query->whereHas('event_bookmaker', function ($query) use ($fieldnames) {
|
|
$query->where('bookmaker_id', auth()->user()->bookmaker_id)
|
|
->where(function ($query) use ($fieldnames) {
|
|
foreach ($fieldnames as $field) {
|
|
$query->orWhere($field, 3);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
)->when(
|
|
$data['filter_compare_differences'],
|
|
function (Builder $query, $filter_compare_differences) {
|
|
|
|
$opt = explode('-', $filter_compare_differences);
|
|
|
|
$compare_bookmaker_id = (int) $opt[2];
|
|
|
|
switch (auth()->user()->sport_id) {
|
|
case 1:
|
|
case 2:
|
|
$event_ids = LoadCompareDifferences::load($opt[0], $opt[1], 'odds_3ways', $compare_bookmaker_id);
|
|
break;
|
|
case 3:
|
|
$event_ids = LoadCompareDifferences::load($opt[0], $opt[1], 'odds_points', $compare_bookmaker_id);
|
|
break;
|
|
case 5:
|
|
$event_ids = LoadCompareDifferences::load($opt[0], $opt[1], 'odds_2ways', $compare_bookmaker_id);
|
|
break;
|
|
|
|
}
|
|
$query->whereIn('id', $event_ids);
|
|
}
|
|
|
|
)->when(
|
|
$data['filter_stars'],
|
|
function (Builder $query, $filter_stars) {
|
|
$query->whereHas('event_user_star');
|
|
}
|
|
)->when(in_array('odds_tq', self::$bettype_settings),
|
|
function (Builder $query, $filter_stars) {
|
|
$query->whereHas('odds_tq');
|
|
}
|
|
)->when(
|
|
$data['filter_notes'],
|
|
function (Builder $query, $filter_notes) {
|
|
$query->whereHas('event_user_note');
|
|
}
|
|
)->when(
|
|
$data['favorit_threshold'],
|
|
function (Builder $query, $favorit_threshold) {
|
|
|
|
switch (auth()->user()->sport_id) {
|
|
case 1:
|
|
return $query->whereHas('odds_3ways', function ($query) use ($favorit_threshold) {
|
|
$query->where('bookmaker_id', auth()->user()->bookmaker_id)->whereRaw('LEAST(h3w, d3w, a3w) BETWEEN ? AND ?', [1, $favorit_threshold]);
|
|
});
|
|
break;
|
|
case 2:
|
|
return $query->whereHas('odds_3ways', function ($query) use ($favorit_threshold) {
|
|
$query->where('bookmaker_id', auth()->user()->bookmaker_id)->whereRaw('LEAST(h3w, d3w, a3w) BETWEEN ? AND ?', [1, $favorit_threshold]);
|
|
});
|
|
break;
|
|
case 3:
|
|
return $query->whereHas('odds_points', function ($query) use ($favorit_threshold) {
|
|
$query->where('bookmaker_id', auth()->user()->bookmaker_id)->where('active_spread', 1)->whereRaw('LEAST(home, away) BETWEEN ? AND ?', [1, $favorit_threshold]);
|
|
});
|
|
break;
|
|
case 5:
|
|
return $query->whereHas('odds_2ways', function ($query) use ($favorit_threshold) {
|
|
$query->where('bookmaker_id', auth()->user()->bookmaker_id)->whereRaw('LEAST(h2w, a2w) BETWEEN ? AND ?', [1, $favorit_threshold]);
|
|
});
|
|
break;
|
|
|
|
}
|
|
}
|
|
);
|
|
})->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(implode(', ', $countries))->removeField('country_id')->color('info');
|
|
} else {
|
|
$indicators[] = Indicator::make($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(implode(', ', $group_ids))->removeField('group_id')->color('info');
|
|
} else {
|
|
$indicators[] = Indicator::make($group_ids[0])->removeField('group_id')->color('info');
|
|
}
|
|
}
|
|
|
|
if ($data['client_group_list_id'] ?? null) {
|
|
$client_group_list_name = ClientGroupList::where('id', $data['client_group_list_id'])->value('name');
|
|
$indicators[] = Indicator::make('Custom Group: '.$client_group_list_name)->removeField('client_group_list_id')->color('info');
|
|
}
|
|
|
|
if ($data['filter_stars'] ?? null) {
|
|
$indicators[] = Indicator::make('Favorits')->removeField('filter_stars')->color('info');
|
|
}
|
|
|
|
if (in_array('odds_tq', self::$bettype_settings)) {
|
|
$indicators[] = Indicator::make('To Qualify')->color('info')->removable(false);
|
|
}
|
|
|
|
if ($data['filter_notes'] ?? null) {
|
|
$indicators[] = Indicator::make('Notes')->removeField('filter_notes')->color('info');
|
|
}
|
|
|
|
if ($data['filter_alarm_green'] ?? null) {
|
|
$title = OddsTable::where('name', $data['filter_alarm_green'])->value('title');
|
|
$indicators[] = Indicator::make('Alarms: '.$title)->removeField('filter_alarm_green')->color('success');
|
|
}
|
|
|
|
if ($data['filter_alarm_yellow'] ?? null) {
|
|
$title = OddsTable::where('name', $data['filter_alarm_yellow'])->value('title');
|
|
$indicators[] = Indicator::make('Alarms: '.$title)->removeField('filter_alarm_yellow')->color('info');
|
|
}
|
|
|
|
if ($data['filter_alarm_red'] ?? null) {
|
|
$title = OddsTable::where('name', $data['filter_alarm_red'])->value('title');
|
|
$indicators[] = Indicator::make('Alarms: '.$title)->removeField('filter_alarm_red')->color('danger');
|
|
}
|
|
|
|
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');
|
|
}
|
|
}
|
|
|
|
if ($data['favorit_threshold'] ?? null) {
|
|
switch (auth()->user()->sport_id) {
|
|
case 1:
|
|
$indicators[] = Indicator::make('1X2 Fav <= '.$data['favorit_threshold'])->removeField('favorit_threshold')->color('warning');
|
|
break;
|
|
case 2:
|
|
$indicators[] = Indicator::make('1X2 Fav <= '.$data['favorit_threshold'])->removeField('favorit_threshold')->color('warning');
|
|
break;
|
|
case 3:
|
|
$indicators[] = Indicator::make('HC Fav <= '.$data['favorit_threshold'])->removeField('favorit_threshold')->color('warning');
|
|
break;
|
|
case 5:
|
|
$indicators[] = Indicator::make('ML Fav <= '.$data['favorit_threshold'])->removeField('favorit_threshold')->color('warning');
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
if ($data['filter_compare_differences'] ?? null) {
|
|
$opt = explode('-', $data['filter_compare_differences']);
|
|
$title = $opt[0];
|
|
switch ($opt[1]) {
|
|
case 'lte':
|
|
$title .= ' ≤ ';
|
|
break;
|
|
case 'gte':
|
|
$title .= ' ≥ ';
|
|
break;
|
|
case 'lt':
|
|
$title .= ' > ';
|
|
break;
|
|
}
|
|
$title .= $opt[3];
|
|
$indicators[] = Indicator::make($title)->removeField('filter_compare_differences')->color('warning');
|
|
}
|
|
|
|
return $indicators;
|
|
}),
|
|
], layout: FiltersLayout::AboveContent)
|
|
->deferFilters(false)
|
|
->hiddenFilterIndicators(false)
|
|
->persistFiltersInSession()
|
|
->emptyStateHeading('No events')
|
|
->emptyStateDescription('Modify the filter')
|
|
->recordUrl(null) // disable row click for page
|
|
->recordAction(null) // disable row click for modal
|
|
->recordActions([
|
|
// Action::make('event-statistic')
|
|
// ->iconButton()
|
|
// ->modalIcon('phosphor-chart-line')
|
|
// ->color('gray')
|
|
// ->modalHeading(fn ($record) => $record->country->name.' - '.$record->group->name)
|
|
// ->icon('phosphor-chart-line')
|
|
// ->modalContent(fn ($record): View => view(
|
|
// 'statistic-event-chart',
|
|
// ['record' => $record],
|
|
// )),
|
|
Action::make('star')
|
|
->iconButton()
|
|
->color(function ($record) {
|
|
if (isset($record->event_user_star->id)) {
|
|
return 'info';
|
|
} else {
|
|
return 'gray';
|
|
}
|
|
})
|
|
->icon(function ($record) {
|
|
if (isset($record->event_user_star->id)) {
|
|
return 'phosphor-star-fill';
|
|
} else {
|
|
return 'phosphor-star-duotone';
|
|
}
|
|
})
|
|
->tooltip('Add to favorits')
|
|
->action(function ($record) {
|
|
$res = EventUserStar::where('event_id', $record->id)
|
|
->where('user_id', auth()->user()->id)
|
|
->first();
|
|
if ($res) {
|
|
EventUserStar::find($res->id)->delete();
|
|
} else {
|
|
EventUserStar::insert(['event_id' => $record->id, 'user_id' => auth()->user()->id]);
|
|
}
|
|
}),
|
|
Action::make('event_note')
|
|
->modalIcon('phosphor-note-pencil-duotone')
|
|
->modalWidth(Width::Large)
|
|
->modalSubmitActionLabel('Save')
|
|
->extraModalFooterActions(fn (Action $action, $record) => $record->event_user_note->isEmpty() ? [] : [$action->makeModalSubmitAction('Delete', arguments: ['delete' => true])->color('danger')])
|
|
->fillForm(data: function ($record) {
|
|
foreach ($record->event_user_note as $value) {
|
|
if ($value->user_id == auth()->user()->id && $value->bookmaker_id == auth()->user()->bookmaker_id) {
|
|
return [
|
|
'event_user_note_id' => $value->id,
|
|
'message' => $value->message,
|
|
];
|
|
}
|
|
}
|
|
|
|
return ['event_user_note_id' => ''];
|
|
})
|
|
->schema([
|
|
Hidden::make('event_user_note_id'),
|
|
Textarea::make('message')
|
|
->rows(2)
|
|
->hiddenLabel(),
|
|
])
|
|
->icon('phosphor-note-pencil-duotone')
|
|
->iconButton()
|
|
->tooltip(fn ($record) => view('filament.resources.events.tooltip.event-user-note-tooltip', ['notes' => $record->event_user_note]))
|
|
->action(function ($record, array $data, $arguments = []) {
|
|
if ($arguments) {
|
|
EventUserNote::where('id', $data['event_user_note_id'])->delete();
|
|
} elseif ($data['event_user_note_id']) {
|
|
if (! $data['message']) {
|
|
EventUserNote::where('id', $data['event_user_note_id'])->delete();
|
|
} else {
|
|
EventUserNote::where('id', $data['event_user_note_id'])->update(['message' => $data['message']]);
|
|
}
|
|
} else {
|
|
EventUserNote::updateOrCreate([
|
|
'event_id' => $record->id,
|
|
'user_id' => auth()->user()->id,
|
|
'client_id' => auth()->user()->client_id,
|
|
'bookmaker_id' => auth()->user()->bookmaker_id,
|
|
], [
|
|
'message' => $data['message'],
|
|
]);
|
|
}
|
|
})
|
|
->color(fn ($record) => $record->event_user_note->isEmpty() ? 'gray' : 'info'),
|
|
ActionGroup::make([
|
|
DeleteAction::make()->visible(fn () => auth()->user()->hasRole('super_admin')),
|
|
Action::make('txodds_odds')
|
|
->label('TxOdds')
|
|
->disabled(fn () => ! auth()->user()->hasRole('super_admin'))
|
|
->icon('phosphor-arrow-square-out')
|
|
->url(fn ($record): string => route('txodds_odds', ['sportid' => $record->sport_id, 'txoddsid' => $record->id]))
|
|
->openUrlInNewTab(),
|
|
Action::make('swap_elements')
|
|
->icon('phosphor-swap')
|
|
->action(function ($record, $livewire) {
|
|
EventBookmaker::where('event_id', $record->id)->where('bookmaker_id', auth()->user()->bookmaker_id)->update(['is_swopped' => DB::raw('!is_swopped')]);
|
|
|
|
$livewire->dispatch('refreshBettypeMenu');
|
|
}),
|
|
|
|
])->iconButton()
|
|
->icon('phosphor-dots-three-vertical'),
|
|
]);
|
|
}
|
|
}
|