summaryrefslogtreecommitdiff
path: root/src/http
diff options
context:
space:
mode:
Diffstat (limited to 'src/http')
-rw-r--r--src/http/Controller/Event.php52
1 files changed, 20 insertions, 32 deletions
diff --git a/src/http/Controller/Event.php b/src/http/Controller/Event.php
index 070d449..46e4c22 100644
--- a/src/http/Controller/Event.php
+++ b/src/http/Controller/Event.php
@@ -4,7 +4,10 @@ namespace App\http\Controller;
use App\DB;
use App\Model\Event as Model;
+use App\Model\Event\SendResources;
use App\Model\Event\SendUnits;
+use App\Model\Event\TrainUnits;
+use App\Model\Event\UpgradeBuilding;
use App\Model\Village;
use App\http\Router;
use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -31,44 +34,29 @@ class Event
$event = DB::fetch(Model::class, 'select * from events where id=:id', ['id' => $request->get('id')])[0] ?? null;
$village = Village::get($event->villageId);
+ /**@var UpgradeBuilding $upgradeBuildingEvent*/
+ $upgradeBuildingEvent = DB::fetch(UpgradeBuilding::class, 'select * from events_upgrade_building where event_id=:id', ['id' => $event->id])[0] ?? null;
+ /**@var TrainUnits $trainUnitsEvent*/
+ $trainUnitsEvent = DB::fetch(TrainUnits::class, 'select * from events_train_units where event_id=:id', ['id' => $event->id])[0] ?? null;
/**@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);
-
- $sendUnitsEvent->isCanceled = true;
- $sendUnitsEvent->home = $sendUnitsEvent->destination;
- $sendUnitsEvent->residence = $sendUnitsEvent->source;
+ /**@var SendUnits $sendUnitsEvent*/
+ $sendResourcesEvent = DB::fetch(SendResources::class, 'select * from events_send_resources where event_id=:id', ['id' => $event->id])[0] ?? null;
- DB::query(
- '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]
- );
- }
+ if (! empty($upgradeBuildingEvent)) {
+ $upgradeBuildingEvent->cancel();
+ }
- else if ($sendUnitsEvent->type === 'Recall') {
- $cancelTimeDiff = $event->createdAt->diff(new \DateTime());
- $cancelTime = (new \DateTime())->add($cancelTimeDiff);
+ else if (! empty($trainUnitsEvent)) {
+ $trainUnitsEvent->cancel();
+ }
- $sendUnitsEvent->isCanceled = true;
- $sendUnitsEvent->home = $sendUnitsEvent->destination;
- $sendUnitsEvent->residence = $sendUnitsEvent->source;
+ else if (! empty($sendUnitsEvent)) {
+ $sendUnitsEvent->cancel();
+ }
- DB::query(
- '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 (! empty($sendResourcesEvent)) {
+ $sendResourcesEvent->cancel();
}
else {