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/Event.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/Controller/Event.php') diff --git a/src/Controller/Event.php b/src/Controller/Event.php index a6538fe..78de9d5 100644 --- a/src/Controller/Event.php +++ b/src/Controller/Event.php @@ -4,6 +4,7 @@ namespace App\Controller; use App\DB; use App\Model\Event as Model; +use App\Model\Event\SendUnits; use App\Model\Village; use App\Router; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -31,22 +32,24 @@ class Event $village = Village::get($event->villageId); if ($event->type === 'SendUnits') { - $payload = json_decode($event->payload, true); + /**@var SendUnits $sendUnitsEvent*/ + $sendUnitsEvent = DB::fetch(SendUnits::class, 'select * from events_send_units where event_id=:id', ['id' => $event->id]); - if ($payload['type'] === 'SendBack') { + if ($sendUnitsEvent->type === 'SendBack') { $cancelTimeDiff = $event->createdAt->diff(new \DateTime()); $cancelTime = (new \DateTime())->add($cancelTimeDiff); - $cancelPayload = array_replace_recursive($payload, [ - 'cancel' => [ - 'home' => $payload['destination'], - 'residence' => $payload['source'], - ], - ]); + $sendUnitsEvent->isCanceled = true; + $sendUnitsEvent->home = $sendUnitsEvent->destination; + $sendUnitsEvent->residence = $sendUnitsEvent->source; DB::query( - 'update events set time=:time, payload=:payload where id=:id', - ['time' => $cancelTime->format('c'), 'payload' => json_encode($cancelPayload), 'id' => $request->get('id')] + 'update events set time=:time, where id=:id', + ['time' => $cancelTime->format('c'), 'id' => $request->get('id')] + ); + DB::query( + 'update events_send_units set is_canceled=:is_canceled, home=:home, residence=:residence where id=:id', + ['is_canceled' => $sendUnitsEvent->isCanceled, 'home' => $sendUnitsEvent->home, 'residence' => $sendUnitsEvent->residence, 'id' => $sendUnitsEvent->id] ); } } -- cgit v1.2.3