summaryrefslogtreecommitdiff
path: root/src/Model/Event/TrainUnits.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Model/Event/TrainUnits.php')
-rw-r--r--src/Model/Event/TrainUnits.php27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/Model/Event/TrainUnits.php b/src/Model/Event/TrainUnits.php
index 0090d0f..5b4eef9 100644
--- a/src/Model/Event/TrainUnits.php
+++ b/src/Model/Event/TrainUnits.php
@@ -3,10 +3,12 @@
namespace App\Model\Event;
use App\DB;
-use App\Model\Event;
-class TrainUnits extends Event
+class TrainUnits extends BaseEvent
{
+ public int $amount;
+ public string $type;
+
/**
* @return void
*/
@@ -21,7 +23,26 @@ class TrainUnits extends Event
on conflict (type, home_village_id, residence_village_id)
do update set amount = village_units.amount+:amount
SQL,
- ['amount' => $payload['amount'], 'type' => $payload['type'], 'id' => $this->villageId]
+ ['amount' => $this->amount, 'type' => $this->type, 'id' => $this->event->villageId]
+ );
+ }
+
+ 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_train_units (event_id, amount, type) VALUES (:event_id, :amount, :type)',
+ ['event_id' => DB::$connection->lastInsertId(), 'amount' => $this->amount, 'type' => $this->type]
+ );
+ }
+
+ 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]);
}
}