diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-11-29 09:35:27 +0100 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-11-29 09:35:27 +0100 |
commit | 3afcaef927391db23fe23c6c8c26b8960e8dae32 (patch) | |
tree | 143b9f6df9e8c795c8c6ed901bffdc7119f40df1 /src/Controller/Village.php | |
parent | c4ce3e884a6aa527bcc138771617215cf03265a4 (diff) |
intermediate commit
Diffstat (limited to 'src/Controller/Village.php')
-rw-r--r-- | src/Controller/Village.php | 27 |
1 files changed, 18 insertions, 9 deletions
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( <<<SQL - select events.*, village_buildings.type as building from events - join village_buildings - on village_buildings.id=(events.payload->'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( <<<SQL select * from events - where type=:type and (village_id=:id or (payload->>'destination')::bigint=:id) + where type=:type and village_id=:id SQL, ['type' => 'SendUnits', 'id' => $village->id] )->fetchAll(); - foreach ($eventsUnitsSend as $row) { + $eventsUnitsSendOther = DB::query( + <<<SQL + select * from events + where type=:type and (payload->>'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]), ])); } |