X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FRound.php;h=18be60fe015d346a085a416e4990aee3458c7447;hb=f446d5bcf3b87bd9443a060e27e9c0601c96fbb9;hp=2232a0e2c95d675411de55c045e7f677217394d0;hpb=df75af8d30ceb44724280829b948dd01e86de07b;p=alttp.git diff --git a/app/Models/Round.php b/app/Models/Round.php index 2232a0e..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,6 +86,7 @@ class Round extends Model protected $casts = [ 'code' => 'array', 'locked' => 'boolean', + 'no_record' => 'boolean', ]; protected $fillable = [ @@ -73,4 +95,8 @@ class Round extends Model 'tournament_id', ]; + protected $with = [ + 'rolled_by_user', + ]; + }