X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FResult.php;h=cdb86c77798fb2bccb204c740ee0ced94473bf71;hb=d32516335ea2534e15256c948e9c38d3de40794b;hp=e693fc7de5d510783d7a0ea24ecfa4d326ce9bc9;hpb=55f2d7cd6c290a0d26db177d54d20c393f890bbb;p=alttp.git diff --git a/app/Models/Result.php b/app/Models/Result.php index e693fc7..cdb86c7 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); } @@ -17,4 +38,20 @@ 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', + ]; + }