X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FResult.php;h=308b9e9fcfd2e8935b25a46df87a39e4d991f8b5;hb=6fe6cd1272c87bf7f89aa9ba59362e98c790c564;hp=e4954195bb3969ceb3be8510f2e085de276b9dcf;hpb=c59d0714d62f9028135cc9cff829d16b91e5fb4f;p=alttp.git diff --git a/app/Models/Result.php b/app/Models/Result.php index e495419..308b9e9 100644 --- a/app/Models/Result.php +++ b/app/Models/Result.php @@ -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); } @@ -18,14 +39,21 @@ class Result extends Model } public function getHasFinishedAttribute() { - return $this->time > 0; + return $this->time > 0 || $this->forfeit; } + + protected $casts = [ + 'forfeit' => 'boolean', + 'time' => 'double', + ]; + protected $appends = [ 'has_finished', ]; protected $fillable = [ + 'forfeit', 'round_id', 'time', 'user_id',