5 use App\Events\ParticipantChanged;
6 use Illuminate\Database\Eloquent\Factories\HasFactory;
7 use Illuminate\Database\Eloquent\Model;
9 class Tournament extends Model
14 public function getRunners() {
16 foreach ($this->participants as $participant) {
17 if (in_array('runner', $participant->roles)) {
18 $runners[] = $participant;
24 public function hasScoreboard() {
25 return $this->type == 'signup-async';
28 public function updatePlacement() {
30 foreach ($this->participants as $p) {
35 $p->updatePlacement(null, null);
38 if (empty($runners)) {
41 foreach ($this->rounds as $round) {
42 foreach ($runners as $p) {
43 $result = $p->findResult($round);
45 $p->score += $result->score;
50 usort($runners, [Participant::class, 'compareScore']);
51 $reversed = array_reverse($runners);
52 $placement = count($runners);
54 $lastScore = $runners[0]->score;
55 foreach ($runners as $p) {
56 if ($p->score > $lastScore) {
57 $placement -= $skipped;
59 $lastScore = $p->score;
63 $p->updatePlacement($p->score, $placement);
68 public function applications() {
69 return $this->hasMany(Application::class);
72 public function participants() {
73 return $this->hasMany(Participant::class);
76 public function protocols() {
77 return $this->hasMany(Protocol::class)->orderBy('created_at', 'DESC');
80 public function rounds() {
81 return $this->hasMany(Round::class)->orderBy('number', 'DESC');
86 'accept_applications' => 'boolean',
87 'locked' => 'boolean',
88 'no_record' => 'boolean',
89 'show_numbers' => 'boolean',