|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Xoco70\KendoTournaments; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
6
|
|
|
use App\User; |
|
7
|
|
|
use Illuminate\Http\Request; |
|
8
|
|
|
use Illuminate\Support\Facades\DB; |
|
9
|
|
|
use Xoco70\KendoTournaments\Exceptions\TreeGenerationException; |
|
10
|
|
|
use Xoco70\KendoTournaments\Models\Championship; |
|
11
|
|
|
use Xoco70\KendoTournaments\Models\ChampionshipSettings; |
|
12
|
|
|
use Xoco70\KendoTournaments\Models\Competitor; |
|
13
|
|
|
use Xoco70\KendoTournaments\Models\Fight; |
|
14
|
|
|
use Xoco70\KendoTournaments\Models\Tournament; |
|
15
|
|
|
use Xoco70\KendoTournaments\Models\Round; |
|
16
|
|
|
use Xoco70\KendoTournaments\TreeGen\TreeGen; |
|
17
|
|
|
use Faker\Factory as Faker; |
|
18
|
|
|
|
|
19
|
|
|
class TreeController extends Controller |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Display a listing of trees. |
|
23
|
|
|
* |
|
24
|
|
|
* @param Request $request |
|
25
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|
26
|
|
|
*/ |
|
27
|
|
|
public function index(Request $request) |
|
28
|
|
|
{ |
|
29
|
|
|
$tournament = Tournament::with( |
|
|
|
|
|
|
30
|
|
|
'competitors', |
|
31
|
|
|
'championshipSettings', |
|
32
|
|
|
'championships.settings', |
|
33
|
|
|
'championships.category')->first(); |
|
34
|
|
|
|
|
35
|
|
|
return view('kendo-tournaments::tree.index') |
|
36
|
|
|
->with('tournament', $tournament); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Build Tree |
|
41
|
|
|
* |
|
42
|
|
|
* @param Request $request |
|
43
|
|
|
* @param Championship $championship |
|
44
|
|
|
* @return \Illuminate\Http\Response|string |
|
45
|
|
|
*/ |
|
46
|
|
|
public function store(Request $request, Championship $championship) |
|
47
|
|
|
{ |
|
48
|
|
|
// Store Championship Settings |
|
49
|
|
|
|
|
50
|
|
|
// DB::table('competitor')->delete(); |
|
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
$tournament = Tournament::with( |
|
|
|
|
|
|
53
|
|
|
'competitors', |
|
54
|
|
|
'championshipSettings' |
|
55
|
|
|
)->first(); |
|
56
|
|
|
|
|
57
|
|
|
$championship = Championship::with('teams', 'users', 'category', 'settings')->find($championship->id); |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
$numFighters = $request->numFighters; |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
// $users = factory(User::class, (int)$numFighters)->create(); |
|
|
|
|
|
|
62
|
|
|
// |
|
63
|
|
|
// foreach ($users as $user) { |
|
64
|
|
|
// factory(Competitor::class)->create([ |
|
65
|
|
|
// 'championship_id' => $championship->id, |
|
66
|
|
|
// 'user_id' => $user->id, |
|
67
|
|
|
// 'confirmed' => 1, |
|
68
|
|
|
// ]); |
|
69
|
|
|
// } |
|
70
|
|
|
|
|
71
|
|
|
$settings = ChampionshipSettings::createOrUpdate($request, $championship); |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
$generation = new TreeGen($championship, null, $settings); |
|
75
|
|
|
$generation->championship = $championship; |
|
76
|
|
|
try { |
|
77
|
|
|
|
|
78
|
|
|
$tree = $generation->run(); |
|
79
|
|
|
$championship->tree = $tree; |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
Round::generateFights($tree, $settings, $championship); |
|
83
|
|
|
|
|
84
|
|
|
} catch (TreeGenerationException $e) { |
|
85
|
|
|
return view('kendo-tournaments::tree.index') |
|
86
|
|
|
->with('tournament', $tournament) |
|
87
|
|
|
->with('error', "Error Generating Tree"); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return view('kendo-tournaments::tree.index') |
|
91
|
|
|
->with('tournament', $tournament) |
|
92
|
|
|
->with('message', "Tree Generated"); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: