filters ok
This commit is contained in:
1 parent
8e9bb0eacb
commit
98d92b2ee3
16 files changed
+365
-189
No files matched your search
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Filament\Resources\Events\Tables;
|
||||
|
||||
use App\Filament\Resources\Events\Tables\Tools\CompareOptions;
|
||||
use App\Filament\Resources\Events\Tables\Tools\LoadBettype;
|
||||
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\EventColumn;
|
||||
@@ -15,8 +17,6 @@ use App\Models\EventBookmaker;
|
||||
use App\Models\EventUserStar;
|
||||
use App\Models\Group;
|
||||
use App\Models\OddsTable;
|
||||
use App\Models\Sport;
|
||||
use App\Models\User;
|
||||
use CodeWithKyrian\FilamentDateRange\Forms\Components\DateRangePicker;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
@@ -53,8 +53,6 @@ class EventsTable
|
||||
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
self::$user = User::getUser();
|
||||
|
||||
LoadMultiline::load();
|
||||
|
||||
LoadBettype::load();
|
||||
@@ -83,7 +81,7 @@ class EventsTable
|
||||
|
||||
TextColumn::make('country.name')
|
||||
->wrap()
|
||||
->hidden(fn () => self::$user->sport_id == 5)
|
||||
->hidden(fn () => auth()->user()->sport_id == 5)
|
||||
->color('gray')
|
||||
->icon(fn ($record) => $record->country?->icon),
|
||||
|
||||
@@ -178,34 +176,13 @@ class EventsTable
|
||||
->extremePaginationLinks()
|
||||
->filters([
|
||||
Filter::make('events')
|
||||
->columns(8)->columnSpan(8)
|
||||
->columns(6)->columnSpan(6)
|
||||
->schema([
|
||||
Hidden::make('filter_alarm_green'),
|
||||
Hidden::make('filter_alarm_yellow'),
|
||||
Hidden::make('filter_alarm_red'),
|
||||
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');
|
||||
$livewire->dispatch('reload_bookmaker_multiline');
|
||||
$livewire->dispatch('reload_alarm_bookmaker');
|
||||
$livewire->dispatch('refresh_comparing_bookmaker');
|
||||
$livewire->dispatch('refreshAlarmWidget');
|
||||
|
||||
$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)
|
||||
->hidden(fn () => auth()->user()->sport_id == 5)
|
||||
->placeholder('Country')
|
||||
->prefixIcon('phosphor-flag')
|
||||
->hiddenLabel()
|
||||
@@ -214,7 +191,7 @@ class EventsTable
|
||||
->searchable()
|
||||
->preload()
|
||||
->options(function () {
|
||||
$res = Event::where('sport_id', self::$user->sport_id)->where('starttime', '>', Carbon::now())->groupBy('country_id')->pluck('country_id')->toArray();
|
||||
$res = Event::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');
|
||||
})
|
||||
@@ -224,7 +201,7 @@ class EventsTable
|
||||
$set('competition_group_id', null);
|
||||
}),
|
||||
Select::make('competition_group_id')
|
||||
->hidden(fn () => self::$user->sport_id == 5)
|
||||
->hidden(fn () => auth()->user()->sport_id == 5)
|
||||
->placeholder('League')
|
||||
->prefixIcon('phosphor-trophy')
|
||||
->hiddenLabel()
|
||||
@@ -233,9 +210,9 @@ class EventsTable
|
||||
->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();
|
||||
$res = Event::where('sport_id', auth()->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();
|
||||
$res = Event::where('sport_id', auth()->user()->sport_id)->with('country')->with('competition_group')->where('starttime', '>', Carbon::now())->groupBy('competition_group_id')->get();
|
||||
}
|
||||
$arr = [];
|
||||
foreach ($res as $val) {
|
||||
@@ -247,7 +224,7 @@ class EventsTable
|
||||
})
|
||||
->live(),
|
||||
Select::make('group_id')
|
||||
->visible(fn () => self::$user->sport_id == 5)
|
||||
->visible(fn () => auth()->user()->sport_id == 5)
|
||||
->placeholder('Tournament')
|
||||
->prefixIcon('phosphor-trophy')
|
||||
->hiddenLabel()
|
||||
@@ -256,9 +233,9 @@ class EventsTable
|
||||
->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();
|
||||
$res = Event::with('country')->where('sport_id', auth()->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();
|
||||
$res = Event::with('country')->where('sport_id', auth()->user()->sport_id)->with('group')->where('starttime', '>', Carbon::now())->groupBy('group_id')->get();
|
||||
}
|
||||
$arr = [];
|
||||
foreach ($res as $val) {
|
||||
@@ -289,52 +266,15 @@ class EventsTable
|
||||
->hiddenLabel()
|
||||
->live(),
|
||||
|
||||
Select::make('special_filter_lteq')
|
||||
Select::make('filter_compare_differences')
|
||||
->placeholder('Compare')
|
||||
->prefixIcon('phosphor-funnel')
|
||||
->hiddenLabel()
|
||||
->allowHtml()
|
||||
->options([
|
||||
'Compare Favorits' => [
|
||||
'flte1' => 'Favorit ≤ Marathonbet',
|
||||
'flte2' => 'Favorit ≤ Bet365',
|
||||
'flte3' => 'Favorit ≤ 1Bet',
|
||||
'flte4' => 'Favorit ≤ Eurobet',
|
||||
'mlt1' => 'Favorit ≥ Marathonbet',
|
||||
'mlt2' => 'Favorit ≥ Bet365',
|
||||
'mlt3' => 'Favorit ≥ 1Bet',
|
||||
'mlt4' => 'Favorit ≥ Eurobet',
|
||||
],
|
||||
'Compare Margins' => [
|
||||
'mgt1' => 'Margin ≥ Marathonbet',
|
||||
'mgt2' => 'Margin ≥ Bet365',
|
||||
'mgt3' => 'Margin ≥ 1Bet',
|
||||
'mgt4' => 'Margin ≥ Eurobet',
|
||||
'mlt1' => 'Margin < Marathonbet',
|
||||
'mlt2' => 'Margin < Bet365',
|
||||
'mlt3' => 'Margin < 1Bet',
|
||||
'mlt4' => 'Margin < Eurobet',
|
||||
],
|
||||
'Compare X' => [
|
||||
'xlt1' => 'X < Marathonbet',
|
||||
'xlt2' => 'X < Bet365',
|
||||
'xlt3' => 'X < 1Bet',
|
||||
'xlt4' => 'X < Eurobet',
|
||||
],
|
||||
]),
|
||||
|
||||
Select::make('filter_missing')
|
||||
->placeholder('Missing')
|
||||
->prefixIcon('phosphor-cow')
|
||||
->hiddenLabel()
|
||||
->allowHtml()
|
||||
->options([1 => '1Bets']),
|
||||
->options(fn () => CompareOptions::load()),
|
||||
])
|
||||
->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(
|
||||
@@ -413,6 +353,29 @@ class EventsTable
|
||||
});
|
||||
});
|
||||
}
|
||||
)->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['favorit_threshold'],
|
||||
@@ -523,6 +486,24 @@ class EventsTable
|
||||
$indicators[] = Indicator::make('Favorits')->removeField('stars_status')->color('info');
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -551,20 +532,20 @@ class EventsTable
|
||||
->tooltip('Add to favorits')
|
||||
->action(function ($record) {
|
||||
$res = EventUserStar::where('event_id', $record->id)
|
||||
->where('user_id', self::$user->id)
|
||||
->where('user_id', auth()->user()->id)
|
||||
->first();
|
||||
if ($res) {
|
||||
EventUserStar::find($res->id)->delete();
|
||||
} else {
|
||||
EventUserStar::insert(['event_id' => $record->id, 'user_id' => self::$user->id]);
|
||||
EventUserStar::insert(['event_id' => $record->id, 'user_id' => auth()->user()->id]);
|
||||
}
|
||||
}),
|
||||
ActionGroup::make([
|
||||
// EditAction::make(),
|
||||
DeleteAction::make()->visible(fn () => self::$user->hasRole('super_admin')),
|
||||
DeleteAction::make()->visible(fn () => auth()->user()->hasRole('super_admin')),
|
||||
Action::make('txodds_odds')
|
||||
->label('TxOdds')
|
||||
->disabled(fn () => ! self::$user->hasRole('super_admin'))
|
||||
->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(),
|
||||
@@ -580,7 +561,7 @@ class EventsTable
|
||||
->icon('phosphor-dots-three-vertical'),
|
||||
])->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make()->visible(fn () => self::$user->hasRole('super_admin')),
|
||||
DeleteBulkAction::make()->visible(fn () => auth()->user()->hasRole('super_admin')),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user