X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=app%2FModels%2FRound.php;h=b6c9d023917f4076775dd3f5d8f55321bb57c745;hb=9160186db0ea1b0da0edfec49cb3d99ead213bc4;hp=2c1a43963897563cfe2686245418dc5f9c149e38;hpb=a4260a00251cef4ad806c9d5c44d4c444d6ab831;p=alttp.git diff --git a/app/Models/Round.php b/app/Models/Round.php index 2c1a439..b6c9d02 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); } @@ -69,9 +90,14 @@ class Round extends Model ]; protected $fillable = [ + 'game', 'number', 'no_record', 'tournament_id', ]; + protected $with = [ + 'rolled_by_user', + ]; + }