timeframe to mapper for select queries
This commit is contained in:
1 parent
ac0ddfcdbd
commit
8a5446db7f
2 files changed
+111
-7
No files matched your search
@@ -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),
|
||||
|
||||
Reference in new issue
Block a user