populateEvent(); DB::query( << $this->type, 'village_id' => $this->event->villageId] ); } /*public function populateEvent(): void { parent::populateEvent(); $event = DB::fetch(UpgradeBuilding::class, 'select * from events_upgrade_building where id=:id', ['id' => $this->id])[0]; $this->type = $event->type; $this->wood = $event->wood; $this->clay = $event->clay; $this->iron = $event->iron; }*/ public function create(): void { $this->populateEvent(); // remove resources $village = Village::get($this->event->villageId); $village->wood -= $this->wood; $village->clay -= $this->clay; $village->iron -= $this->iron; $village->updateResources(); // add to db $this->dbInsert(); } public function cancel(): void { $this->populateEvent(); // add resources $village = Village::get($this->event->villageId); $village->wood += $this->wood; $village->clay += $this->clay; $village->iron += $this->iron; $village->updateResources(); // remove from db $this->dbDelete(); } public function dbInsert(): void { DB::query( 'insert into events (time, village_id) VALUES (:time, :village_id)', ['time' => $this->event->time->format('c'), 'village_id' => $this->event->villageId] ); DB::query( 'insert into events_upgrade_building (event_id, type, wood, clay, iron) VALUES (:event_id, :type, :wood, :clay, :iron)', [ 'event_id' => DB::$connection->lastInsertId(), 'type' => $this->type, 'wood' => $this->wood, 'clay' => $this->clay, 'iron' => $this->iron, ] ); } public function dbDelete(): void { DB::query('delete from events where id=:id', ['id' => $this->eventId]); DB::query('delete from events_upgrade_building where id=:id', ['id' => $this->id]); } }