@@ -1,6 +1,5 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -use Illuminate\Database\QueryException; |
|
4 | 3 | use Illuminate\Database\Seeder; |
5 | 4 | use Xoco70\KendoTournaments\Models\Championship; |
6 | 5 | use Xoco70\KendoTournaments\Models\Venue; |
@@ -218,7 +218,7 @@ |
||
218 | 218 | |
219 | 219 | /** |
220 | 220 | * @param Collection $tree |
221 | - * @param $settings |
|
221 | + * @param ChampionshipSettings $settings |
|
222 | 222 | */ |
223 | 223 | public static function generateFights(Collection $tree, $settings, Championship $championship = null) |
224 | 224 | { |
@@ -5,7 +5,6 @@ |
||
5 | 5 | |
6 | 6 | use Illuminate\Database\Eloquent\Model; |
7 | 7 | use Illuminate\Support\Collection; |
8 | -use Illuminate\Support\Facades\Config; |
|
9 | 8 | use Xoco70\KendoTournaments\TreeGen\TreeGen; |
10 | 9 | |
11 | 10 | class Tree extends Model |
@@ -41,15 +41,15 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public static function getTournament($request) |
43 | 43 | { |
44 | - $tournament = Tournament::whereHas('championships', function ($query) use ($request) { |
|
44 | + $tournament = Tournament::whereHas('championships', function($query) use ($request) { |
|
45 | 45 | return $query->where('id', $request->championshipId); |
46 | 46 | }) |
47 | - ->with(['championships' => function ($query) use ($request) { |
|
47 | + ->with(['championships' => function($query) use ($request) { |
|
48 | 48 | $query->where('id', '=', $request->championshipId) |
49 | 49 | ->with([ |
50 | 50 | 'settings', |
51 | 51 | 'category', |
52 | - 'tree' => function ($query) { |
|
52 | + 'tree' => function($query) { |
|
53 | 53 | return $query->with('user1', 'user2', 'user3', 'user4', 'user5'); |
54 | 54 | }]); |
55 | 55 | }]) |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | |
226 | 226 | // Delete previous fight for this championship |
227 | 227 | |
228 | - $arrayTreeId = $tree->map(function ($value, $key) { |
|
228 | + $arrayTreeId = $tree->map(function($value, $key) { |
|
229 | 229 | return $value->id; |
230 | 230 | })->toArray(); |
231 | 231 | Fight::destroy($arrayTreeId); |
@@ -20,6 +20,9 @@ discard block |
||
20 | 20 | public $championship, $settings; |
21 | 21 | |
22 | 22 | |
23 | + /** |
|
24 | + * @param \Xoco70\KendoTournaments\Models\ChampionshipSettings $settings |
|
25 | + */ |
|
23 | 26 | public function __construct(Championship $championship, $groupBy, $settings) |
24 | 27 | { |
25 | 28 | $this->championship = $championship; |
@@ -257,7 +260,7 @@ discard block |
||
257 | 260 | |
258 | 261 | /** |
259 | 262 | * @param $userGroups |
260 | - * @param $max |
|
263 | + * @param integer $max |
|
261 | 264 | * @return Collection |
262 | 265 | */ |
263 | 266 | private function repart($userGroups, $max) |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | |
70 | 70 | } else if ($this->championship->isDirectEliminationType()) { |
71 | 71 | $roundRobinGroups = $users->chunk(2)->shuffle(); |
72 | - }else{ |
|
72 | + } else { |
|
73 | 73 | $roundRobinGroups = new Collection(); |
74 | 74 | |
75 | 75 | // Not so good, Round Robin has no trees |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | private function getTreeSize($userCount, $groupSize) |
224 | 224 | { |
225 | 225 | $square = collect([1, 2, 4, 8, 16, 32, 64]); |
226 | - $squareMultiplied = $square->map(function ($item, $key) use ($groupSize) { |
|
226 | + $squareMultiplied = $square->map(function($item, $key) use ($groupSize) { |
|
227 | 227 | return $item * $groupSize; |
228 | 228 | }); |
229 | 229 |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | |
70 | 70 | } else if ($this->championship->isDirectEliminationType()) { |
71 | 71 | $roundRobinGroups = $users->chunk(2)->shuffle(); |
72 | - }else{ |
|
72 | + } else{ |
|
73 | 73 | $roundRobinGroups = new Collection(); |
74 | 74 | |
75 | 75 | // Not so good, Round Robin has no trees |
@@ -106,11 +106,21 @@ discard block |
||
106 | 106 | $c4 = $robinGroup->get(3); |
107 | 107 | $c5 = $robinGroup->get(4); |
108 | 108 | |
109 | - if (isset($c1)) $pt->c1 = $c1->id; |
|
110 | - if (isset($c2)) $pt->c2 = $c2->id; |
|
111 | - if (isset($c3)) $pt->c3 = $c3->id; |
|
112 | - if (isset($c4)) $pt->c4 = $c4->id; |
|
113 | - if (isset($c5)) $pt->c5 = $c5->id; |
|
109 | + if (isset($c1)) { |
|
110 | + $pt->c1 = $c1->id; |
|
111 | + } |
|
112 | + if (isset($c2)) { |
|
113 | + $pt->c2 = $c2->id; |
|
114 | + } |
|
115 | + if (isset($c3)) { |
|
116 | + $pt->c3 = $c3->id; |
|
117 | + } |
|
118 | + if (isset($c4)) { |
|
119 | + $pt->c4 = $c4->id; |
|
120 | + } |
|
121 | + if (isset($c5)) { |
|
122 | + $pt->c5 = $c5->id; |
|
123 | + } |
|
114 | 124 | $pt->save(); |
115 | 125 | $trees->push($pt); |
116 | 126 | $order++; |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | -$directEliminationTree = $championship->tree->map(function ($item, $key) use ($championship) { |
|
3 | - if ($championship->category->isTeam()){ |
|
2 | +$directEliminationTree = $championship->tree->map(function($item, $key) use ($championship) { |
|
3 | + if ($championship->category->isTeam()) { |
|
4 | 4 | |
5 | 5 | $user1 = $item->team1 != null ? $item->team1->name : "Bye"; |
6 | 6 | $user2 = $item->team2 != null ? $item->team2->name : "Bye"; |
7 | - }else{ |
|
7 | + } else { |
|
8 | 8 | $user1 = $item->user1 != null ? $item->user1->name : "Bye"; |
9 | 9 | $user2 = $item->user2 != null ? $item->user2->name : "Bye"; |
10 | 10 | } |
@@ -4,7 +4,7 @@ |
||
4 | 4 | |
5 | 5 | $user1 = $item->team1 != null ? $item->team1->name : "Bye"; |
6 | 6 | $user2 = $item->team2 != null ? $item->team2->name : "Bye"; |
7 | - }else{ |
|
7 | + } else{ |
|
8 | 8 | $user1 = $item->user1 != null ? $item->user1->name : "Bye"; |
9 | 9 | $user2 = $item->user2 != null ? $item->user2->name : "Bye"; |
10 | 10 | } |
@@ -52,7 +52,7 @@ |
||
52 | 52 | // 'championships.users' |
53 | 53 | )->first(); |
54 | 54 | |
55 | - $championship = Championship::with('teams','users','category','settings')->find($championship->id); |
|
55 | + $championship = Championship::with('teams', 'users', 'category', 'settings')->find($championship->id); |
|
56 | 56 | |
57 | 57 | $settings = ChampionshipSettings::createOrUpdate($request, $championship); |
58 | 58 |
@@ -3,7 +3,6 @@ |
||
3 | 3 | namespace Xoco70\KendoTournaments; |
4 | 4 | |
5 | 5 | use App\Http\Controllers\Controller; |
6 | -use Illuminate\Auth\Access\AuthorizationException; |
|
7 | 6 | use Illuminate\Http\Request; |
8 | 7 | use Xoco70\KendoTournaments\Exceptions\TreeGenerationException; |
9 | 8 | use Xoco70\KendoTournaments\Models\Championship; |
@@ -22,11 +22,11 @@ |
||
22 | 22 | { |
23 | 23 | parent::boot(); |
24 | 24 | |
25 | - static::deleting(function ($championship) { |
|
25 | + static::deleting(function($championship) { |
|
26 | 26 | $championship->competitors()->delete(); |
27 | 27 | $championship->settings()->delete(); |
28 | 28 | }); |
29 | - static::restoring(function ($championship) { |
|
29 | + static::restoring(function($championship) { |
|
30 | 30 | $championship->competitors()->restore(); |
31 | 31 | $championship->settings()->restore(); |
32 | 32 |
@@ -33,7 +33,7 @@ |
||
33 | 33 | 'gradeMax', |
34 | 34 | ]; |
35 | 35 | |
36 | - public function getAliasString(){ |
|
36 | + public function getAliasString() { |
|
37 | 37 | return $this->alias; |
38 | 38 | } |
39 | 39 |
@@ -59,14 +59,14 @@ |
||
59 | 59 | protected static function boot() |
60 | 60 | { |
61 | 61 | parent::boot(); |
62 | - static::deleting(function ($tournament) { |
|
62 | + static::deleting(function($tournament) { |
|
63 | 63 | foreach ($tournament->championships as $ct) { |
64 | 64 | $ct->delete(); |
65 | 65 | } |
66 | 66 | $tournament->invites()->delete(); |
67 | 67 | |
68 | 68 | }); |
69 | - static::restoring(function ($tournament) { |
|
69 | + static::restoring(function($tournament) { |
|
70 | 70 | |
71 | 71 | foreach ($tournament->championships()->withTrashed()->get() as $ct) { |
72 | 72 | $ct->restore(); |
@@ -174,7 +174,7 @@ |
||
174 | 174 | $round = []; |
175 | 175 | $fighters = self::getActorsToFights($championship, $treeGroup); |
176 | 176 | |
177 | - $away = $fighters->splice(sizeof($fighters) / 2); // 2 |
|
177 | + $away = $fighters->splice(sizeof($fighters) / 2); // 2 |
|
178 | 178 | |
179 | 179 | $home = $fighters; // 1 |
180 | 180 |
@@ -43,17 +43,37 @@ |
||
43 | 43 | } else { |
44 | 44 | $fighters = new Collection; |
45 | 45 | if ($championship->category->isTeam) { |
46 | - if ($treeGroup->c1 != null) $fighters->push($treeGroup->team1); |
|
47 | - if ($treeGroup->c2 != null) $fighters->push($treeGroup->team2); |
|
48 | - if ($treeGroup->c3 != null) $fighters->push($treeGroup->team3); |
|
49 | - if ($treeGroup->c4 != null) $fighters->push($treeGroup->team4); |
|
50 | - if ($treeGroup->c5 != null) $fighters->push($treeGroup->team5); |
|
46 | + if ($treeGroup->c1 != null) { |
|
47 | + $fighters->push($treeGroup->team1); |
|
48 | + } |
|
49 | + if ($treeGroup->c2 != null) { |
|
50 | + $fighters->push($treeGroup->team2); |
|
51 | + } |
|
52 | + if ($treeGroup->c3 != null) { |
|
53 | + $fighters->push($treeGroup->team3); |
|
54 | + } |
|
55 | + if ($treeGroup->c4 != null) { |
|
56 | + $fighters->push($treeGroup->team4); |
|
57 | + } |
|
58 | + if ($treeGroup->c5 != null) { |
|
59 | + $fighters->push($treeGroup->team5); |
|
60 | + } |
|
51 | 61 | } else { |
52 | - if ($treeGroup->c1 != null) $fighters->push($treeGroup->user1); |
|
53 | - if ($treeGroup->c2 != null) $fighters->push($treeGroup->user2); |
|
54 | - if ($treeGroup->c3 != null) $fighters->push($treeGroup->user3); |
|
55 | - if ($treeGroup->c4 != null) $fighters->push($treeGroup->user4); |
|
56 | - if ($treeGroup->c5 != null) $fighters->push($treeGroup->user5); |
|
62 | + if ($treeGroup->c1 != null) { |
|
63 | + $fighters->push($treeGroup->user1); |
|
64 | + } |
|
65 | + if ($treeGroup->c2 != null) { |
|
66 | + $fighters->push($treeGroup->user2); |
|
67 | + } |
|
68 | + if ($treeGroup->c3 != null) { |
|
69 | + $fighters->push($treeGroup->user3); |
|
70 | + } |
|
71 | + if ($treeGroup->c4 != null) { |
|
72 | + $fighters->push($treeGroup->user4); |
|
73 | + } |
|
74 | + if ($treeGroup->c5 != null) { |
|
75 | + $fighters->push($treeGroup->user5); |
|
76 | + } |
|
57 | 77 | } |
58 | 78 | } |
59 | 79 | if ($championship->category->isTeam) { |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | |
107 | 107 | /** |
108 | 108 | * Save a Fight. |
109 | - * @param $tree |
|
109 | + * @param Collection $tree |
|
110 | 110 | * @param int $numRound |
111 | 111 | */ |
112 | 112 | public static function saveFightRound($tree, $numRound = 1) |
@@ -166,6 +166,9 @@ discard block |
||
166 | 166 | // } |
167 | 167 | // } |
168 | 168 | |
169 | + /** |
|
170 | + * @param Collection $tree |
|
171 | + */ |
|
169 | 172 | public static function saveRoundRobinFights(Championship $championship, $tree) |
170 | 173 | { |
171 | 174 |