diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-01-11 13:15:02 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-01-11 13:15:02 +0100 |
commit | 09caff2b2a06d1f8ac8203567035a21c612165f9 (patch) | |
tree | 999be04ff0a418a33e438be9befc8c9297e383f4 /src/gemini/Controller/Event.php | |
parent | 6301f63bd348109b8693a922f02e16d49205a8fd (diff) |
send resources
Diffstat (limited to 'src/gemini/Controller/Event.php')
-rw-r--r-- | src/gemini/Controller/Event.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/gemini/Controller/Event.php b/src/gemini/Controller/Event.php new file mode 100644 index 0000000..ab4463b --- /dev/null +++ b/src/gemini/Controller/Event.php @@ -0,0 +1,55 @@ +<?php + +namespace App\gemini\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 GeminiFoundation\Request; +use GeminiFoundation\Response; +use GeminiFoundation\Status; + +class Event +{ + // #[Route(path: '/event/{id}/cancel', methods: ['POST'])] + public function cancel(Request $request): Response + { + $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; + /**@var SendResources $sendResourcesEvent*/ + $sendResourcesEvent = DB::fetch(SendResources::class, 'select * from events_send_resources where event_id=:id', ['id' => $event->id])[0] ?? null; + + if (! empty($upgradeBuildingEvent)) { + $upgradeBuildingEvent->cancel(); + } + + else if (! empty($trainUnitsEvent)) { + $trainUnitsEvent->cancel(); + } + + else if (! empty($sendUnitsEvent)) { + $sendUnitsEvent->cancel(); + } + + else if (! empty($sendResourcesEvent)) { + $sendResourcesEvent->cancel(); + } + + + return new Response( + statusCode: Status::REDIRECT_TEMPORARY, + meta: "/village/{$village->x}/{$village->y}" + ); + } +} |