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/Building.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/Controller/Building.php') diff --git a/src/Controller/Building.php b/src/Controller/Building.php index 6199286..876f474 100644 --- a/src/Controller/Building.php +++ b/src/Controller/Building.php @@ -2,7 +2,6 @@ namespace App\Controller; -use App\DB; use App\Model\Building as Model; use App\Model\Event; use App\Model\Event\UpgradeBuilding; @@ -28,18 +27,13 @@ class Building $village->updateResources(); // event - $event = new UpgradeBuilding(); - $event->type = 'UpgradeBuilding'; + $event = new Event(); $event->time = (new \DateTime())->add(\DateInterval::createFromDateString($building->getBuildTime() . ' seconds')); - $event->payload = json_encode([ - 'type' => $building->type, - 'village_id' => $building->villageId, - ]); - - DB::query( - 'insert into events (type, time, payload, village_id) VALUES (:type, :time, :payload, :id)', - ['type' => $event->type, 'time' => $event->time->format('c'), 'payload' => $event->payload, 'id' => $village->id] - ); + $event->villageId = $building->villageId; + $upgradeBuildingEvent = new UpgradeBuilding(); + $upgradeBuildingEvent->event = $event; + $upgradeBuildingEvent->type = $building->type; + $upgradeBuildingEvent->dbInsert(); return new RedirectResponse( Router::generate( -- cgit v1.2.3