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
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user