Files
nuhodds_fi4/app/Actions/AlarmStatistic.php
T
2026-10-04 15:25:03 +02:00

48 lines
1.3 KiB
PHP

<?php
namespace App\Actions;
use App\Models\Event;
use App\Models\OddsTable;
use Carbon\Carbon;
class AlarmStatistic
{
public static function load()
{
$res = OddsTable::select('name', 'fieldnames')->get();
$fields = [];
foreach ($res as $value) {
$fields[$value->name] = explode(',', $value->fieldnames);
}
$events = Event::with('event_bookmaker')
->where('sport_id', auth()->user()->sport_id)
->where('starttime', '>=', Carbon::now())
->whereHas('event_bookmaker', function ($query) {
$query->where('bookmaker_id', auth()->user()->bookmaker_id);
})
->get();
$arr = [];
foreach ($events as $event) {
$row = $event->event_bookmaker;
// $row = get_object_vars($event->toArray());
foreach ($fields as $table => $names) {
foreach ($names as $name) {
$val = (int) $row[$name];
if ($val) {
if (isset($arr[$table][$val])) {
$arr[$table][$val]++;
} else {
$arr[$table][$val] = 1;
}
}
}
}
}
return $arr;
}
}