timeframe to mapper for select queries

This commit is contained in:
salam committed 2026-02-13 14:33:52 +01:00
1 parent ac0ddfcdbd
commit 8a5446db7f
2 files changed
+111 -7

No files matched your search

+48 -3
View File
@@ -103,8 +103,29 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
->hiddenLabel() ->hiddenLabel()
->searchable() ->searchable()
->preload() ->preload()
->options(function () { ->options(function (Get $get) {
$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(); $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'); return Country::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id');
}) })
@@ -119,6 +140,7 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
->searchable() ->searchable()
->options(function (Get $get) { ->options(function (Get $get) {
$map = Country::all()->pluck('name', 'id')->toArray(); $map = Country::all()->pluck('name', 'id')->toArray();
$query = CompetitionGroup::where('sport_id', auth()->user()->sport_id) $query = CompetitionGroup::where('sport_id', auth()->user()->sport_id)
->whereHas('event', function ($query) { ->whereHas('event', function ($query) {
$query->where('starttime', '>', now()) $query->where('starttime', '>', now())
@@ -128,7 +150,30 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
if ($get('country_id') ?? null) { if ($get('country_id') ?? null) {
$res = $query->where('country_id', $get('country_id'))->get(); $res = $query->where('country_id', $get('country_id'))->get();
} else { } 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 = []; $arr = [];
foreach ($res as $value) { foreach ($res as $value) {
+63 -4
View File
@@ -101,7 +101,27 @@ class MapperRight extends Component implements HasActions, HasSchemas, HasTable
->preload() ->preload()
->live() ->live()
->options(function (Get $get) { ->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) { ->afterStateUpdated(function (callable $set) {
$set('group_id', null); $set('group_id', null);
@@ -117,6 +137,25 @@ class MapperRight extends Component implements HasActions, HasSchemas, HasTable
->live() ->live()
->options(function (Get $get) { ->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'); $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) { if ($get('country_id') ?? null) {
$res = $query->where('country_id', $get('country_id'))->pluck('group_cc')->toArray(); $res = $query->where('country_id', $get('country_id'))->pluck('group_cc')->toArray();
} else { } else {
@@ -139,12 +178,32 @@ class MapperRight extends Component implements HasActions, HasSchemas, HasTable
->preload() ->preload()
->options(function (Get $get) { ->options(function (Get $get) {
if ($get('country_id')) { 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')) { } 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 { } 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(), ->live(),
])->columnSpan(2), ])->columnSpan(2),