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.php44
1 files changed, 20 insertions, 24 deletions
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(
<<<SQL
- select * from events
- where events.village_id=:id and events.type=:type
- SQL, ['id' => $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(
<<<SQL
- select * from events
- where type=:type and village_id=:id
- SQL, ['type' => '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(
<<<SQL
- select * from events
- where type=:type and village_id=:id
- SQL, ['type' => '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(
<<<SQL
- select * from events
- where type=:type and (payload->>'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,