isCanceled) { if ($this->type === 'SendBack' || $this->type === 'Recall') { $this->source = $this->home; $this->destination = $this->residence; $this->borrow(); } } else { if ($this->type === 'Recall' || $this->type === 'SendBack') { $this->return(); } else if ($this->type === 'Borrow') { $this->borrow(); } else if ($this->type === 'Gift') { $this->gift(); } } } private function return(): void { DB::query( << $this->amount, 'type' => $this->unit, 'id' => $this->destination] ); DB::query( 'delete from village_units where type=:type and home_village_id=:home and residence_village_id=:residence and is_traveling=true', ['type' => $this->unit, 'home' => $this->destination, 'residence' => $this->source] ); } private function borrow(): void { DB::query( << $this->amount, 'type' => $this->unit, 'home' => $this->source, 'residence' => $this->destination] ); DB::query( 'delete from village_units where type=:type and home_village_id=:home and residence_village_id=:residence and is_traveling=true', ['type' => $this->unit, 'home' => $this->source, 'residence' => $this->source] ); } private function gift(): void { DB::query( << $this->amount, 'type' => $this->unit, 'home' => $this->destination, 'residence' => $this->residence] ); DB::query( 'delete from village_units where type=:type and home_village_id=:home and residence_village_id=:residence and is_traveling=true', ['type' => $this->unit, 'home' => $this->source, 'residence' => $this->source] ); } 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( << DB::$connection->lastInsertId(), 'type' => $this->type, 'amount' => $this->amount, 'unit' => $this->unit, 'source' => $this->source, 'destination' => $this->destination, 'home' => $this->home, 'residence' => $this->residence, 'is_canceled' => $this->isCanceled ?: 0, // @see https://www.php.net/manual/de/pdostatement.execute.php#126013 ] ); } public function dbDelete(): void { DB::query('delete from events where id=:id', ['id' => $this->eventId]); DB::query('delete from events_send_units where id=:id', ['id' => $this->id]); } }