diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-12-02 14:14:34 +0100 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-12-02 14:14:34 +0100 |
commit | e5a243a52b910e35b10b26c06aa8978356b86769 (patch) | |
tree | 74ddb82add2f3ea200e9fd11cfedb6c0cace09be /src/Controller/Event.php | |
parent | fa9096c0ab521aae45cab6c48a54290d14a221b9 (diff) |
login and events
Diffstat (limited to 'src/Controller/Event.php')
-rw-r--r-- | src/Controller/Event.php | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/Controller/Event.php b/src/Controller/Event.php index 78de9d5..1fd304d 100644 --- a/src/Controller/Event.php +++ b/src/Controller/Event.php @@ -31,10 +31,9 @@ class Event $event = DB::fetch(Model::class, 'select * from events where id=:id', ['id' => $request->get('id')])[0] ?? null; $village = Village::get($event->villageId); - if ($event->type === 'SendUnits') { - /**@var SendUnits $sendUnitsEvent*/ - $sendUnitsEvent = DB::fetch(SendUnits::class, 'select * from events_send_units where event_id=:id', ['id' => $event->id]); - + /**@var SendUnits $sendUnitsEvent*/ + $sendUnitsEvent = DB::fetch(SendUnits::class, 'select * from events_send_units where event_id=:id', ['id' => $event->id])[0] ?? null; + if (! empty($sendUnitsEvent)) { if ($sendUnitsEvent->type === 'SendBack') { $cancelTimeDiff = $event->createdAt->diff(new \DateTime()); $cancelTime = (new \DateTime())->add($cancelTimeDiff); @@ -44,7 +43,25 @@ class Event $sendUnitsEvent->residence = $sendUnitsEvent->source; DB::query( - 'update events set time=:time, where id=: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] + ); + } + + else if ($sendUnitsEvent->type === 'Recall') { + $cancelTimeDiff = $event->createdAt->diff(new \DateTime()); + $cancelTime = (new \DateTime())->add($cancelTimeDiff); + + $sendUnitsEvent->isCanceled = true; + $sendUnitsEvent->home = $sendUnitsEvent->destination; + $sendUnitsEvent->residence = $sendUnitsEvent->source; + + DB::query( + 'update events set time=:time where id=:id', ['time' => $cancelTime->format('c'), 'id' => $request->get('id')] ); DB::query( |