summaryrefslogtreecommitdiff
path: root/src/Controller/Event.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Controller/Event.php')
-rw-r--r--src/Controller/Event.php23
1 files changed, 13 insertions, 10 deletions
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]
);
}
}