diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-11-29 09:35:27 +0100 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-11-29 09:35:27 +0100 |
commit | 3afcaef927391db23fe23c6c8c26b8960e8dae32 (patch) | |
tree | 143b9f6df9e8c795c8c6ed901bffdc7119f40df1 /src/Model/Event/UpgradeBuilding.php | |
parent | c4ce3e884a6aa527bcc138771617215cf03265a4 (diff) |
intermediate commit
Diffstat (limited to 'src/Model/Event/UpgradeBuilding.php')
-rw-r--r-- | src/Model/Event/UpgradeBuilding.php | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/src/Model/Event/UpgradeBuilding.php b/src/Model/Event/UpgradeBuilding.php index c014cfe..f4f427d 100644 --- a/src/Model/Event/UpgradeBuilding.php +++ b/src/Model/Event/UpgradeBuilding.php @@ -5,23 +5,43 @@ namespace App\Model\Event; use App\DB; use App\Model\Event; -class UpgradeBuilding extends Event +class UpgradeBuilding extends BaseEvent { + public Event $event; + public string $type; + + public function __construct(Event $event, string $type) + { + $this->event = $event; + $this->type = $type; + } + /** * @return void */ public function __invoke(): void { - $payload = json_decode($this->payload, true); + DB::query( + <<<SQL + insert into village_buildings (level, type, village_id) + values (1, :type, :village_id) + on conflict (type, village_id) + do update set level = village_buildings.level+1 + SQL, + ['type' => $this->type, 'village_id' => $this->event->villageId] + ); + } + public function sqlInsert(): void + { DB::query( - 'update village_buildings set level=level+1 where id=:id', - ['id' => $payload['id']] + 'insert into events (time, village_id) values (:time, :village_id)', + ['time' => $this->event->time->format('c'), 'village_id' => $this->event->villageId] ); DB::query( - 'delete from events where id=:id', - ['id' => $this->id] + 'insert into events_upgrade_building (event_id, type) values (:event_id, :type)', + ['event_id' => DB::$connection->lastInsertId(), $this->type] ); } } |