173 lines
6.2 KiB
PHP
173 lines
6.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Events;
|
|
|
|
use App\Filament\Resources\Events\Pages\ListEvents;
|
|
use App\Filament\Resources\Events\Schemas\EventForm;
|
|
use App\Filament\Resources\Events\Tables\EventsTable;
|
|
use App\Filament\Resources\Events\Tables\Tools\LoadClientStartimeDifference;
|
|
use App\Filament\Resources\Events\Tables\Tools\LoadPartnerDifferences;
|
|
use App\Models\Event;
|
|
use App\Models\EventBookmaker;
|
|
use Carbon\Carbon;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class EventResource extends Resource
|
|
{
|
|
protected static ?string $model = Event::class;
|
|
|
|
protected static string|\BackedEnum|null $navigationIcon = 'phosphor-monitor';
|
|
|
|
protected static ?string $navigationLabel = 'NUH Monitor';
|
|
|
|
protected static ?string $modelLabel = '';
|
|
|
|
protected static ?string $title = 'NUH Monitor';
|
|
|
|
protected static ?string $pluralModelLabel = '';
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return EventForm::configure($schema);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return EventsTable::configure($table);
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ListEvents::route('/'),
|
|
];
|
|
}
|
|
|
|
public static function getNavigationBadge(): ?string
|
|
{
|
|
return parent::getEloquentQuery()
|
|
->where('has_markets', 1)
|
|
->where('sport_id', auth()->user()->sport_id)
|
|
->where('starttime', '>=', Carbon::now())
|
|
->count();
|
|
}
|
|
|
|
public static function getEloquentQuery(): Builder
|
|
{
|
|
$query = parent::getEloquentQuery()
|
|
->with('competition_group')
|
|
->with('country')
|
|
->with('home')
|
|
->with('away')
|
|
->with('home_betsapi')
|
|
->with('away_betsapi')
|
|
->with('event_bookmaker')
|
|
->with('event_user_star')
|
|
->with('event_user_note')
|
|
->where('has_markets', 1)
|
|
->where('sport_id', auth()->user()->sport_id)
|
|
->orderBy('starttime', 'ASC');
|
|
|
|
$query->where('starttime', '>=', Carbon::now());
|
|
|
|
// if (config('env.app_env') == 'production') {
|
|
// $query->where('starttime', '>=', Carbon::now()->subHour());
|
|
// } else {
|
|
// $query->where('starttime', '>=', Carbon::now());
|
|
// }
|
|
|
|
if (auth()->user()->all_only_none > 0) {
|
|
switch (auth()->user()->all_only_none) {
|
|
case 1:
|
|
$query->whereHas('event_bookmaker');
|
|
break;
|
|
case 2:
|
|
$query->doesntHave('event_bookmaker');
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (auth()->user()->partner_compare) {
|
|
$event_ids = LoadPartnerDifferences::load();
|
|
$query->whereIn('id', $event_ids);
|
|
}
|
|
|
|
if (auth()->user()->starttime_differences) {
|
|
$event_ids = LoadClientStartimeDifference::load();
|
|
$query->whereIn('id', $event_ids);
|
|
}
|
|
|
|
if (auth()->user()->bookmaker_partner_differences == 1) {
|
|
// $a = EventBookmaker::where('bookmaker_id', auth()->user()->bookmaker_id)
|
|
// ->where('sport_id', auth()->user()->sport_id)
|
|
// ->pluck('event_id')->toArray();
|
|
// $b = EventBookmaker::where('bookmaker_id', auth()->user()->partner_bookmaker_id)
|
|
// ->where('sport_id', auth()->user()->sport_id)
|
|
// ->pluck('event_id')->toArray();
|
|
// $result = array_diff($a, $b);
|
|
// $query->whereIn('id', $result);
|
|
$e = DB::table('event_bookmakers')
|
|
->selectRaw('count(id) as c, event_id')
|
|
->whereIn('bookmaker_id', [auth()->user()->bookmaker_id, auth()->user()->partner_bookmaker_id])
|
|
->where('sport_id', auth()->user()->sport_id)
|
|
->where('starttime', '>', Carbon::now()->timezone('CET'))
|
|
->groupBy('event_id')
|
|
->havingRaw('c = 1')
|
|
->pluck('event_id')->toArray();
|
|
|
|
$query->whereIn('id', $e);
|
|
}
|
|
|
|
if (isset((EventsTable::$bettype_settings))) {
|
|
if (in_array('odds_2ways', EventsTable::$bettype_settings)) {
|
|
$query->with('odds_2ways.bookmaker');
|
|
}
|
|
if (in_array('odds_2ways_s1', EventsTable::$bettype_settings)) {
|
|
$query->with('odds_2ways_s1.bookmaker');
|
|
}
|
|
if (in_array('odds_3ways', EventsTable::$bettype_settings)) {
|
|
$query->with('odds_3ways.bookmaker');
|
|
}
|
|
if (in_array('odds_3ways_ht', EventsTable::$bettype_settings)) {
|
|
$query->with('odds_3ways_ht.bookmaker');
|
|
}
|
|
if (in_array('odds_dc', EventsTable::$bettype_settings)) {
|
|
$query->with('odds_dc.bookmaker');
|
|
}
|
|
if (in_array('odds_dnb', EventsTable::$bettype_settings)) {
|
|
$query->with('odds_dnb.bookmaker');
|
|
}
|
|
if (in_array('odds_ggng', EventsTable::$bettype_settings)) {
|
|
$query->with('odds_ggng.bookmaker');
|
|
}
|
|
if (in_array('odds_points', EventsTable::$bettype_settings)) {
|
|
$query->with('odds_points.bookmaker');
|
|
}
|
|
if (in_array('odds_points_ht', EventsTable::$bettype_settings)) {
|
|
$query->with('odds_points_ht.bookmaker');
|
|
}
|
|
if (in_array('odds_points_q1', EventsTable::$bettype_settings)) {
|
|
$query->with('odds_points_q1.bookmaker');
|
|
}
|
|
if (in_array('odds_totals', EventsTable::$bettype_settings)) {
|
|
$query->with('odds_totals.bookmaker');
|
|
}
|
|
if (in_array('odds_totals_ht', EventsTable::$bettype_settings)) {
|
|
$query->with('odds_totals_ht.bookmaker');
|
|
}
|
|
if (in_array('odds_totals_q1', EventsTable::$bettype_settings)) {
|
|
$query->with('odds_totals_q1.bookmaker');
|
|
}
|
|
if (in_array('odds_tq', EventsTable::$bettype_settings)) {
|
|
$query->with('odds_tq.bookmaker');
|
|
}
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
}
|