From fa9096c0ab521aae45cab6c48a54290d14a221b9 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 29 Nov 2023 11:03:15 +0100 Subject: event tables --- src/Controller/Village.php | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) (limited to 'src/Controller/Village.php') diff --git a/src/Controller/Village.php b/src/Controller/Village.php index 59e6d4b..16a8981 100644 --- a/src/Controller/Village.php +++ b/src/Controller/Village.php @@ -34,51 +34,46 @@ class Village $eventsBuilding = DB::query( << $village->id, 'type' => 'UpgradeBuilding'] + select * from events_upgrade_building as event + left join events on event.event_id = events.id + where events.village_id=:id + SQL, ['id' => $village->id] )->fetchAll(); foreach ($eventsBuilding as $row) { - $events[$row['type']][] = [ - 'event' => DB::convertToModel(UpgradeBuilding::class, $row), - 'data' => json_decode($row['payload']), - ]; + $events['UpgradeBuilding'][] = DB::convertToModel(UpgradeBuilding::class, $row); } $eventsUnits = DB::query( << 'TrainUnits', 'id' => $village->id] + select * from events_train_units as event + left join events on event.event_id = events.id + where village_id=:id + SQL, ['id' => $village->id] )->fetchAll(); foreach ($eventsUnits as $row) { - $events[$row['type']][] = [ - 'event' => DB::convertToModel(TrainUnits::class, $row), - 'data' => json_decode($row['payload'], true), - ]; + $events['TrainUnits'][] = DB::convertToModel(TrainUnits::class, $row); } $eventsUnitsSendOwn = DB::query( << 'SendUnits', 'id' => $village->id] + select * from events_send_units as event + left join events on event.event_id = events.id + where village_id=:id + SQL, ['id' => $village->id] )->fetchAll(); $eventsUnitsSendOther = DB::query( <<>'destination')::bigint=:id and (payload->>'cancel') is null - SQL, ['type' => 'SendUnits', 'id' => $village->id] + select * from events_send_units as event + left join events on event.event_id = events.id + where destination=:id and is_canceled=false + SQL, ['id' => $village->id] )->fetchAll(); foreach ([...$eventsUnitsSendOwn, ...$eventsUnitsSendOther] as $row) { - $events[$row['type']][] = [ - 'event' => DB::convertToModel(SendUnits::class, $row), - 'data' => json_decode($row['payload'], true), - ]; + $events['SendUnits'][] = DB::convertToModel(SendUnits::class, $row);; } $buildings = []; @@ -86,6 +81,7 @@ class Village $buildings[$building->type] = $building; } + return new Response(View::render('village.twig', [ 'village' => $village, 'events' => $events, -- cgit v1.2.3