1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Xoco70\KendoTournaments; |
4
|
|
|
|
5
|
|
|
use Illuminate\Routing\Controller; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
use Illuminate\Support\Facades\DB; |
8
|
|
|
use Xoco70\KendoTournaments\Exceptions\TreeGenerationException; |
9
|
|
|
use Xoco70\KendoTournaments\Models\Championship; |
10
|
|
|
use Xoco70\KendoTournaments\Models\ChampionshipSettings; |
11
|
|
|
use Xoco70\KendoTournaments\Models\Round; |
12
|
|
|
use Xoco70\KendoTournaments\Models\Tournament; |
13
|
|
|
use Xoco70\KendoTournaments\TreeGen\TreeGen; |
14
|
|
|
|
15
|
|
|
class TreeController extends Controller |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Display a listing of trees. |
19
|
|
|
* |
20
|
|
|
* @param Request $request |
21
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
22
|
|
|
*/ |
23
|
|
|
public function index(Request $request) |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$tournament = Tournament::with( |
|
|
|
|
26
|
|
|
'competitors', |
27
|
|
|
'championshipSettings', |
28
|
|
|
'championships.settings', |
29
|
|
|
'championships.category')->first(); |
30
|
|
|
|
31
|
|
|
return view('kendo-tournaments::tree.index') |
|
|
|
|
32
|
|
|
->with('tournament', $tournament) |
33
|
|
|
->with('settings', $tournament->championships[0]->setting); |
34
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Build Tree |
39
|
|
|
* |
40
|
|
|
* @param Request $request |
41
|
|
|
* @param Championship $championship |
42
|
|
|
* @return \Illuminate\Http\Response|string |
43
|
|
|
*/ |
44
|
|
|
public function store(Request $request, Championship $championship) |
45
|
|
|
{ |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
DB::table('fight')->delete(); |
49
|
|
|
DB::table('round')->delete(); |
50
|
|
|
DB::table('round_competitor')->delete(); |
51
|
|
|
DB::table('round_team')->delete(); |
52
|
|
|
|
53
|
|
|
$tournament = Tournament::with( |
|
|
|
|
54
|
|
|
'competitors', |
55
|
|
|
'championshipSettings' |
56
|
|
|
)->first(); |
57
|
|
|
|
58
|
|
|
$championship = Championship::with('teams', 'users', 'category', 'settings')->find($championship->id); |
|
|
|
|
59
|
|
|
|
60
|
|
|
// $numFighters = $request->numFighters; |
|
|
|
|
61
|
|
|
|
62
|
|
|
// $users = factory(User::class, (int)$numFighters)->create(); |
|
|
|
|
63
|
|
|
// |
64
|
|
|
// foreach ($users as $user) { |
65
|
|
|
// factory(Competitor::class)->create([ |
66
|
|
|
// 'championship_id' => $championship->id, |
67
|
|
|
// 'user_id' => $user->id, |
68
|
|
|
// 'confirmed' => 1, |
69
|
|
|
// ]); |
70
|
|
|
// } |
71
|
|
|
|
72
|
|
|
$settings = ChampionshipSettings::createOrUpdate($request, $championship); |
73
|
|
|
|
74
|
|
|
//TODO Set groupBy argument to NULL for now |
75
|
|
|
$generation = new TreeGen($championship, null, $settings); |
76
|
|
|
try { |
77
|
|
|
|
78
|
|
|
$rounds = $generation->run(); |
79
|
|
|
Round::generateFights($rounds, $settings, $championship); |
80
|
|
|
|
81
|
|
|
} catch (TreeGenerationException $e) { |
82
|
|
|
return view('kendo-tournaments::tree.index') |
|
|
|
|
83
|
|
|
->with('tournament', $tournament) |
84
|
|
|
->with('error', "Error Generating Tree"); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return redirect()->back(); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.