]> git.localhorst.tv Git - alttp.git/blobdiff - app/Models/Result.php
server calculated scoring
[alttp.git] / app / Models / Result.php
index e5c9f7e77f8b756380275ebdf09854fe64df0555..cdb86c77798fb2bccb204c740ee0ced94473bf71 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace App\Models;
 
+use App\Events\ResultChanged;
 use Illuminate\Database\Eloquent\Factories\HasFactory;
 use Illuminate\Database\Eloquent\Model;
 
@@ -9,6 +10,26 @@ class Result extends Model
 {
        use HasFactory;
 
+
+       public function updateResult($time, $forfeit) {
+               $this->time = $time;
+               $this->forfeit = $forfeit;
+               $this->save();
+               if ($this->wasChanged()) {
+                       ResultChanged::dispatch($this);
+               }
+       }
+
+       public function updatePlacement($score, $placement) {
+               $this->score = $score;
+               $this->placement = $placement;
+               $this->save();
+               if ($this->wasChanged()) {
+                       ResultChanged::dispatch($this);
+               }
+       }
+
+
        public function round() {
                return $this->belongsTo(Round::class);
        }
@@ -17,7 +38,17 @@ class Result extends Model
                return $this->belongsTo(Participant::class);
        }
 
+       public function getHasFinishedAttribute() {
+               return $this->time > 0 || $this->forfeit;
+       }
+
+
+       protected $appends = [
+               'has_finished',
+       ];
+
        protected $fillable = [
+               'forfeit',
                'round_id',
                'time',
                'user_id',