From 8a5446db7feae292f42af89d8fd6b55b63c75a31 Mon Sep 17 00:00:00 2001 From: salam Date: Fri, 13 Feb 2026 14:33:52 +0100 Subject: [PATCH] timeframe to mapper for select queries --- app/Livewire/MapperLeft.php | 51 +++++++++++++++++++++++++-- app/Livewire/MapperRight.php | 67 +++++++++++++++++++++++++++++++++--- 2 files changed, 111 insertions(+), 7 deletions(-) diff --git a/app/Livewire/MapperLeft.php b/app/Livewire/MapperLeft.php index b1f226d4..cb117db9 100644 --- a/app/Livewire/MapperLeft.php +++ b/app/Livewire/MapperLeft.php @@ -103,8 +103,29 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable ->hiddenLabel() ->searchable() ->preload() - ->options(function () { - $res = Event::query()->where('sport_id', auth()->user()->sport_id)->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->groupBy('country_id')->pluck('country_id')->toArray(); + ->options(function (Get $get) { + $query = Event::query()->where('sport_id', auth()->user()->sport_id)->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->groupBy('country_id'); + + $timeframe = $get('starttime_period') ?? []; + + if ($timeframe['start'] || $timeframe['end']) { + if (isset($timeframe['start']) && isset($timeframe['end'])) { + $from = Carbon::createFromDate($timeframe['start']); + $end = Carbon::createFromDate($timeframe['end']); + + $query->whereDate('starttime', '>=', $from->format('Y-m-d 00:00:00'))->whereDate('starttime', '<=', $end->format('Y-m-d 00:00:00')); + } elseif (isset($timeframe['start'])) { + $from = Carbon::createFromDate($timeframe['start']); + + $query->whereDate('starttime', '>=', $from->format('Y-m-d 00:00:00')); + } elseif (isset($timeframe['end'])) { + $end = Carbon::createFromDate($timeframe['end']); + + $query->whereDate('starttime', '<=', $end->format('Y-m-d 00:00:00')); + } + } + + $res = $query->pluck('country_id')->toArray(); return Country::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id'); }) @@ -119,6 +140,7 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable ->searchable() ->options(function (Get $get) { $map = Country::all()->pluck('name', 'id')->toArray(); + $query = CompetitionGroup::where('sport_id', auth()->user()->sport_id) ->whereHas('event', function ($query) { $query->where('starttime', '>', now()) @@ -128,7 +150,30 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable if ($get('country_id') ?? null) { $res = $query->where('country_id', $get('country_id'))->get(); } else { - $res = $query->get(); + $timeframe = $get('starttime_period') ?? null; + + if ($timeframe['start'] || $timeframe['end']) { + $query = Event::query()->where('sport_id', auth()->user()->sport_id); + if (isset($timeframe['start']) && isset($timeframe['end'])) { + $from = Carbon::createFromDate($timeframe['start']); + $end = Carbon::createFromDate($timeframe['end']); + + $query->whereDate('starttime', '>=', $from->format('Y-m-d 00:00:00'))->whereDate('starttime', '<=', $end->format('Y-m-d 00:00:00')); + } elseif (isset($timeframe['start'])) { + $from = Carbon::createFromDate($timeframe['start']); + + $query->whereDate('starttime', '>=', $from->format('Y-m-d 00:00:00')); + } elseif (isset($timeframe['end'])) { + $end = Carbon::createFromDate($timeframe['end']); + + $query->whereDate('starttime', '<=', $end->format('Y-m-d 00:00:00')); + } + $countries = $query->pluck('country_id')->toArray(); + + $res = $query->groupBy('country_id')->whereIn('country_id', $countries)->get(); + } else { + $res = $query->get(); + } } $arr = []; foreach ($res as $value) { diff --git a/app/Livewire/MapperRight.php b/app/Livewire/MapperRight.php index f12eff43..0ffadc3c 100644 --- a/app/Livewire/MapperRight.php +++ b/app/Livewire/MapperRight.php @@ -101,7 +101,27 @@ class MapperRight extends Component implements HasActions, HasSchemas, HasTable ->preload() ->live() ->options(function (Get $get) { - return Mapper::query()->where('sport_id', auth()->user()->sport_id)->where('provider_id', auth()->user()->provider_id)->where('starttime', '>', Carbon::now())->groupBy('country_id')->orderBy('country')->pluck('country', 'country_id')->toArray(); + $query = Mapper::query()->where('sport_id', auth()->user()->sport_id)->where('provider_id', auth()->user()->provider_id)->where('starttime', '>', Carbon::now())->groupBy('country_id')->orderBy('country'); + + $timeframe = $get('starttime_period') ?? []; + if ($timeframe['start'] || $timeframe['end']) { + if (isset($timeframe['start']) && isset($timeframe['end'])) { + $from = Carbon::createFromDate($timeframe['start']); + $end = Carbon::createFromDate($timeframe['end']); + + $query->whereDate('starttime', '>=', $from->format('Y-m-d 00:00:00'))->whereDate('starttime', '<=', $end->format('Y-m-d 00:00:00')); + } elseif (isset($timeframe['start'])) { + $from = Carbon::createFromDate($timeframe['start']); + + $query->whereDate('starttime', '>=', $from->format('Y-m-d 00:00:00')); + } elseif (isset($timeframe['end'])) { + $end = Carbon::createFromDate($timeframe['end']); + + $query->whereDate('starttime', '<=', $end->format('Y-m-d 00:00:00')); + } + } + + return $query->pluck('country', 'country_id')->toArray(); }) ->afterStateUpdated(function (callable $set) { $set('group_id', null); @@ -117,6 +137,25 @@ class MapperRight extends Component implements HasActions, HasSchemas, HasTable ->live() ->options(function (Get $get) { $query = Mapper::query()->where('sport_id', auth()->user()->sport_id)->where('provider_id', auth()->user()->provider_id)->where('starttime', '>', Carbon::now())->groupBy('group_cc'); + + $timeframe = $get('starttime_period') ?? []; + + if ($timeframe['start'] || $timeframe['end']) { + if (isset($timeframe['start']) && isset($timeframe['end'])) { + $from = Carbon::createFromDate($timeframe['start']); + $end = Carbon::createFromDate($timeframe['end']); + + $query->whereDate('starttime', '>=', $from->format('Y-m-d 00:00:00'))->whereDate('starttime', '<=', $end->format('Y-m-d 00:00:00')); + } elseif (isset($timeframe['start'])) { + $from = Carbon::createFromDate($timeframe['start']); + + $query->whereDate('starttime', '>=', $from->format('Y-m-d 00:00:00')); + } elseif (isset($timeframe['end'])) { + $end = Carbon::createFromDate($timeframe['end']); + + $query->whereDate('starttime', '<=', $end->format('Y-m-d 00:00:00')); + } + } if ($get('country_id') ?? null) { $res = $query->where('country_id', $get('country_id'))->pluck('group_cc')->toArray(); } else { @@ -139,12 +178,32 @@ class MapperRight extends Component implements HasActions, HasSchemas, HasTable ->preload() ->options(function (Get $get) { if ($get('country_id')) { - return Mapper::query()->where('sport_id', auth()->user()->sport_id)->where('provider_id', auth()->user()->provider_id)->where('starttime', '>', Carbon::now())->where('country_id', $get('country_id'))->groupBy('group_id')->pluck('group', 'group_id')->toArray(); + $query = Mapper::query()->where('sport_id', auth()->user()->sport_id)->where('provider_id', auth()->user()->provider_id)->where('starttime', '>', Carbon::now())->where('country_id', $get('country_id'))->groupBy('group_id'); } elseif ($get('group_cc')) { - return Mapper::query()->where('sport_id', auth()->user()->sport_id)->where('provider_id', auth()->user()->provider_id)->where('starttime', '>', Carbon::now())->where('group_cc', $get('group_cc'))->groupBy('group_id')->pluck('group', 'group_id')->toArray(); + $query = Mapper::query()->where('sport_id', auth()->user()->sport_id)->where('provider_id', auth()->user()->provider_id)->where('starttime', '>', Carbon::now())->where('group_cc', $get('group_cc'))->groupBy('group_id'); } else { - return Mapper::query()->where('sport_id', auth()->user()->sport_id)->where('provider_id', auth()->user()->provider_id)->where('starttime', '>', Carbon::now())->groupBy('group_id')->pluck('group', 'group_id')->toArray(); + $query = Mapper::query()->where('sport_id', auth()->user()->sport_id)->where('provider_id', auth()->user()->provider_id)->where('starttime', '>', Carbon::now())->groupBy('group_id'); } + + $timeframe = $get('starttime_period') ?? []; + if ($timeframe['start'] || $timeframe['end']) { + if (isset($timeframe['start']) && isset($timeframe['end'])) { + $from = Carbon::createFromDate($timeframe['start']); + $end = Carbon::createFromDate($timeframe['end']); + + $query->whereDate('starttime', '>=', $from->format('Y-m-d 00:00:00'))->whereDate('starttime', '<=', $end->format('Y-m-d 00:00:00')); + } elseif (isset($timeframe['start'])) { + $from = Carbon::createFromDate($timeframe['start']); + + $query->whereDate('starttime', '>=', $from->format('Y-m-d 00:00:00')); + } elseif (isset($timeframe['end'])) { + $end = Carbon::createFromDate($timeframe['end']); + + $query->whereDate('starttime', '<=', $end->format('Y-m-d 00:00:00')); + } + } + + return $query->pluck('group', 'group_id')->toArray(); }) ->live(), ])->columnSpan(2),