5 use Illuminate\Database\Eloquent\Factories\HasFactory;
6 use Illuminate\Database\Eloquent\Model;
8 class Round extends Model
13 public function updatePlacement() {
15 foreach ($this->tournament->participants as $p) {
19 $result = $p->findResult($this);
21 $result->updatePlacement(null, null);
26 usort($runners, Participant::compareResult($this));
27 $mapped = array_map(function ($p) {
28 return ['participant' => $p, 'result' => $p->findResult($this)];
30 $filtered = array_filter($mapped, function($r) {
31 return $r['result'] && ($r['result']->time || $r['result']->forfeit);
33 $reversed = array_reverse($filtered);
38 foreach ($reversed as $r) {
39 $betterThanLast = is_null($lastResult) || $r['result']->time < $lastResult;
40 if (!$r['result']->forfeit && $betterThanLast) {
42 $lastResult = $r['result']->time;
47 if (!$r['result']->forfeit) {
48 $r['result']->updatePlacement($running, count($filtered) - $running + 1);
50 $r['result']->updatePlacement(0, count($filtered));
56 public function results() {
57 return $this->hasMany(Result::class);
60 public function tournament() {
61 return $this->belongsTo(Tournament::class);
67 'locked' => 'boolean',
70 protected $fillable = [