summaryrefslogtreecommitdiff
path: root/src/Model/Event/TrainUnits.php
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-11-29 11:03:15 +0100
committerDaniel Weipert <code@drogueronin.de>2023-11-29 11:03:15 +0100
commitfa9096c0ab521aae45cab6c48a54290d14a221b9 (patch)
tree61466b792c2714848cfea00594456ac06c259c94 /src/Model/Event/TrainUnits.php
parent3afcaef927391db23fe23c6c8c26b8960e8dae32 (diff)
event tables
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]);
}
}