1 | <?php |
||
2 | |||
3 | namespace App; |
||
4 | |||
5 | class Championship extends \Xoco70\LaravelTournaments\Models\Championship |
||
6 | { |
||
7 | /** |
||
8 | * A championship belongs to a Category |
||
9 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
10 | */ |
||
11 | 8 | public function category() |
|
12 | { |
||
13 | 8 | return $this->belongsTo(\App\Category::class); |
|
14 | } |
||
15 | |||
16 | /** |
||
17 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
18 | */ |
||
19 | 3 | public function teams() |
|
20 | { |
||
21 | 3 | return $this->hasMany(\App\Team::class); |
|
22 | } |
||
23 | |||
24 | /** |
||
25 | * A championship belongs to a Tournament. |
||
26 | * |
||
27 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
28 | */ |
||
29 | 2 | public function tournament() |
|
30 | { |
||
31 | 2 | return $this->belongsTo(Tournament::class); |
|
32 | } |
||
33 | |||
34 | /** |
||
35 | * Generate Round Titles |
||
36 | * @param $numFighters |
||
37 | * @return array |
||
38 | */ |
||
39 | public function getRoundTitle($numFighters): array |
||
40 | { |
||
41 | $roundTitles = []; |
||
42 | if ($this->hasPreliminary()) { |
||
43 | $roundTitles[] = 'Preliminary'; |
||
44 | $this->noTeams = $numFighters / $this->getSettings()->preliminaryGroupSize; |
||
0 ignored issues
–
show
|
|||
45 | } else if ($this->isSingleEliminationType()) { |
||
46 | $this->noTeams = $numFighters; |
||
47 | } else if ($this->isPlayOffType()) { |
||
48 | $this->noTeams = $numFighters; |
||
49 | } |
||
50 | |||
51 | if ($this->noTeams == 2) { |
||
52 | $roundTitles[] = 'Final'; |
||
53 | } elseif ($this->noTeams <= 4) { |
||
54 | $roundTitles[] = 'Semi-Finals'; |
||
55 | $roundTitles[] = 'Final'; |
||
56 | } elseif ($this->noTeams <= 8) { |
||
57 | $roundTitles[] = 'Quarter-Finals'; |
||
58 | $roundTitles[] = 'Semi-Finals'; |
||
59 | $roundTitles[] = 'Final'; |
||
60 | } else { |
||
61 | $roundTitles[] = 'Quarter-Finals'; |
||
62 | $roundTitles[] = 'Semi-Finals'; |
||
63 | $roundTitles[] = 'Final'; |
||
64 | |||
65 | $noRounds = ceil(log($this->noTeams, 2)); |
||
66 | $noTeamsInFirstRound = pow(2, ceil(log($this->noTeams) / log(2))); |
||
67 | $tempRounds = array(); |
||
68 | |||
69 | //The minus 3 is to ignore the final, semi final and quarter final rounds |
||
70 | |||
71 | for ($i = 0; $i < $noRounds - 3; $i++) { |
||
72 | $tempRounds[] = 'Last ' . $noTeamsInFirstRound; |
||
73 | $noTeamsInFirstRound /= 2; |
||
74 | } |
||
75 | |||
76 | $roundTitles = array_merge($tempRounds, $roundTitles); |
||
77 | |||
78 | } |
||
79 | return $roundTitles; |
||
80 | } |
||
81 | } |
||
82 |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.