summaryrefslogtreecommitdiff
path: root/src/Controller/Village.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Controller/Village.php')
-rw-r--r--src/Controller/Village.php27
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]),
]));
}