X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FRound.php;h=18be60fe015d346a085a416e4990aee3458c7447;hb=6f22614d8c68c68c88b44804802cdffeb3c6a3c7;hp=3777df9e8e96040717fa8ce3e97e0d878188463c;hpb=d32516335ea2534e15256c948e9c38d3de40794b;p=alttp.git diff --git a/app/Models/Round.php b/app/Models/Round.php index 3777df9..18be60f 100644 --- a/app/Models/Round.php +++ b/app/Models/Round.php @@ -10,6 +10,16 @@ class Round extends Model use HasFactory; + public function isComplete() { + if (count($this->tournament->participants) == 0) return false; + if (count($this->results) == 0) return false; + foreach ($this->tournament->getRunners() as $participant) { + $result = $participant->findResult($this); + if (!$result || !$result->has_finished) return false; + } + return true; + } + public function updatePlacement() { $runners = []; foreach ($this->tournament->participants as $p) { @@ -53,10 +63,21 @@ class Round extends Model } + public function hideResults() { + foreach ($this->results as $result) { + $result->makeHidden(['forfeit', 'placement', 'score', 'time']); + } + } + + public function results() { return $this->hasMany(Result::class); } + public function rolled_by_user() { + return $this->belongsTo(User::class, 'rolled_by'); + } + public function tournament() { return $this->belongsTo(Tournament::class); } @@ -65,11 +86,17 @@ class Round extends Model protected $casts = [ 'code' => 'array', 'locked' => 'boolean', + 'no_record' => 'boolean', ]; protected $fillable = [ 'number', + 'no_record', 'tournament_id', ]; + protected $with = [ + 'rolled_by_user', + ]; + }