diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-11-29 11:03:15 +0100 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-11-29 11:03:15 +0100 |
commit | fa9096c0ab521aae45cab6c48a54290d14a221b9 (patch) | |
tree | 61466b792c2714848cfea00594456ac06c259c94 /src/Controller/Unit.php | |
parent | 3afcaef927391db23fe23c6c8c26b8960e8dae32 (diff) |
event tables
Diffstat (limited to 'src/Controller/Unit.php')
-rw-r--r-- | src/Controller/Unit.php | 87 |
1 files changed, 38 insertions, 49 deletions
diff --git a/src/Controller/Unit.php b/src/Controller/Unit.php index c57ff01..1774c17 100644 --- a/src/Controller/Unit.php +++ b/src/Controller/Unit.php @@ -3,6 +3,8 @@ namespace App\Controller; use App\DB; +use App\Model\Event\SendUnits; +use App\Model\Event\TrainUnits; use App\Model\Unit as Model; use App\Model\Event; use App\Model\Village; @@ -43,17 +45,13 @@ class Unit // event $event = new Event(); - $event->type = 'TrainUnits'; $event->time = (new \DateTime())->add(\DateInterval::createFromDateString($unit->getBuildTime($amount) . ' seconds')); - $event->payload = json_encode([ - 'type' => $request->get('type'), - 'amount' => $amount, - ]); - - 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 = $village->id; + $trainUnitsEvent = new TrainUnits(); + $trainUnitsEvent->event = $event; + $trainUnitsEvent->type = $request->get('type'); + $trainUnitsEvent->amount = $amount; + $trainUnitsEvent->dbInsert(); return new RedirectResponse( Router::generate( @@ -96,25 +94,22 @@ class Unit // event $event = new Event(); - $event->type = 'SendUnits'; $event->time = (new \DateTime())->add( \DateInterval::createFromDateString( Model::getTravelTime($unit, Village::getDistance($village->x, $village->y, $location->x, $location->y)) . ' seconds' ) ); - $event->payload = json_encode([ - 'type' => 'Recall', - 'unit' => $request->get('type'), - 'amount' => $amount, - 'source' => $location->id, - 'destination' => $village->id, - ]); - - 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 = $village->id; + $sendUnitsEvent = new SendUnits(); + $sendUnitsEvent->event = $event; + $sendUnitsEvent->type = 'Recall'; + $sendUnitsEvent->unit = $request->get('type'); + $sendUnitsEvent->amount = $amount; + $sendUnitsEvent->source = $location->id; + $sendUnitsEvent->destination = $village->id; + $sendUnitsEvent->dbInsert(); + return new RedirectResponse( Router::generate( @@ -157,25 +152,22 @@ class Unit // event $event = new Event(); - $event->type = 'SendUnits'; $event->time = (new \DateTime())->add( \DateInterval::createFromDateString( Model::getTravelTime($unit, Village::getDistance($village->x, $village->y, $location->x, $location->y)) . ' seconds' ) ); - $event->payload = json_encode([ - 'type' => 'SendBack', - 'unit' => $request->get('type'), - 'amount' => $amount, - 'source' => $village->id, - 'destination' => $location->id, - ]); - - 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 = $village->id; + $sendUnitsEvent = new SendUnits(); + $sendUnitsEvent->event = $event; + $sendUnitsEvent->type = 'SendBack'; + $sendUnitsEvent->unit = $request->get('type'); + $sendUnitsEvent->amount = $amount; + $sendUnitsEvent->source = $village->id; + $sendUnitsEvent->destination = $location->id; + $sendUnitsEvent->dbInsert(); + return new RedirectResponse( Router::generate( @@ -218,25 +210,22 @@ class Unit // event $event = new Event(); - $event->type = 'SendUnits'; $event->time = (new \DateTime())->add( \DateInterval::createFromDateString( Model::getTravelTime($unit, Village::getDistance($village->x, $village->y, $destination->x, $destination->y)) . ' seconds' ) ); - $event->payload = json_encode([ - 'type' => $request->get('type'), - 'unit' => $request->get('unit'), - 'amount' => $amount, - 'source' => $village->id, - 'destination' => $destination->id, - ]); - - 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 = $village->id; + $sendUnitsEvent = new SendUnits(); + $sendUnitsEvent->event = $event; + $sendUnitsEvent->type = $request->get('type'); + $sendUnitsEvent->unit = $request->get('unit'); + $sendUnitsEvent->amount = $amount; + $sendUnitsEvent->source = $village->id; + $sendUnitsEvent->destination = $destination->id; + $sendUnitsEvent->dbInsert(); + return new RedirectResponse( Router::generate( |