From 3afcaef927391db23fe23c6c8c26b8960e8dae32 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 29 Nov 2023 09:35:27 +0100 Subject: intermediate commit --- src/Controller/Village.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/Controller/Village.php') diff --git a/src/Controller/Village.php b/src/Controller/Village.php index dfca298..59e6d4b 100644 --- a/src/Controller/Village.php +++ b/src/Controller/Village.php @@ -34,9 +34,7 @@ class Village $eventsBuilding = DB::query( <<'id')::bigint + select * from events where events.village_id=:id and events.type=:type SQL, ['id' => $village->id, 'type' => 'UpgradeBuilding'] )->fetchAll(); @@ -44,9 +42,7 @@ class Village foreach ($eventsBuilding as $row) { $events[$row['type']][] = [ 'event' => DB::convertToModel(UpgradeBuilding::class, $row), - 'data' => [ - 'building' => $row['building'], - ], + 'data' => json_decode($row['payload']), ]; } @@ -64,23 +60,36 @@ class Village ]; } - $eventsUnitsSend = DB::query( + $eventsUnitsSendOwn = DB::query( <<>'destination')::bigint=:id) + where type=:type and village_id=:id SQL, ['type' => 'SendUnits', 'id' => $village->id] )->fetchAll(); - foreach ($eventsUnitsSend as $row) { + $eventsUnitsSendOther = DB::query( + <<>'destination')::bigint=:id and (payload->>'cancel') is null + SQL, ['type' => 'SendUnits', 'id' => $village->id] + )->fetchAll(); + + foreach ([...$eventsUnitsSendOwn, ...$eventsUnitsSendOther] as $row) { $events[$row['type']][] = [ 'event' => DB::convertToModel(SendUnits::class, $row), 'data' => json_decode($row['payload'], true), ]; } + $buildings = []; + foreach (Model::getBuildings($village->id, true) as $building) { + $buildings[$building->type] = $building; + } + return new Response(View::render('village.twig', [ 'village' => $village, 'events' => $events, + 'buildings' => $buildings, 'villages' => DB::fetch(Model::class, "select * from villages where id!=:id", ['id' => $village->id]), ])); } -- cgit v1.2.3