1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Xoco70\KendoTournaments\Models; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
7
|
|
|
use Illuminate\Support\Collection; |
8
|
|
|
|
9
|
|
|
class Round extends Model |
10
|
|
|
{ |
11
|
|
|
protected $table = 'round'; |
12
|
|
|
public $timestamps = true; |
13
|
|
|
protected $guarded = ['id']; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Check if Request contains tournamentSlug / Should Move to TreeRequest When Built |
17
|
|
|
* @param $request |
18
|
|
|
* @return bool |
19
|
|
|
*/ |
20
|
|
|
public static function hasTournamentInRequest($request) |
21
|
|
|
{ |
22
|
|
|
return $request->tournament != null; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Check if Request contains championshipId / Should Move to TreeRequest When Built |
27
|
|
|
* @param $request |
28
|
|
|
* @return bool |
29
|
|
|
*/ |
30
|
|
|
public static function hasChampionshipInRequest($request) |
31
|
|
|
{ |
32
|
|
|
return $request->championshipId != null; // has return false, don't know why |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
38
|
|
|
*/ |
39
|
|
|
public function championship() |
40
|
|
|
{ |
41
|
|
|
return $this->belongsTo(Championship::class); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
46
|
|
|
*/ |
47
|
|
|
public function fights() |
48
|
|
|
{ |
49
|
|
|
return $this->hasMany(Fight::class, 'tree_id', 'id'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function teams() |
53
|
|
|
{ |
54
|
|
|
return $this->belongsToMany(Team::class, 'round_team'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function competitors() |
58
|
|
|
{ |
59
|
|
|
return $this->belongsToMany(Competitor::class, 'round_competitor'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param Collection $rounds |
65
|
|
|
* @param $settings |
66
|
|
|
* @param Championship $championship |
67
|
|
|
*/ |
68
|
|
|
public static function generateFights(Collection $rounds, $settings, Championship $championship = null) |
69
|
|
|
{ |
70
|
|
|
|
71
|
|
|
// Delete previous fight for this championship |
72
|
|
|
|
73
|
|
|
$arrRoundsId = $rounds->map(function ($value, $key) { |
|
|
|
|
74
|
|
|
return $value->id; |
75
|
|
|
})->toArray(); |
76
|
|
|
Fight::destroy($arrRoundsId); |
77
|
|
|
|
78
|
|
|
Fight::saveRoundRobinFights($championship, $rounds); |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
// if ($settings->hasPreliminary) { |
|
|
|
|
82
|
|
|
// if ($settings->preliminaryGroupSize == 3) { |
83
|
|
|
// for ($numRound = 1; $numRound <= $settings->preliminaryGroupSize; $numRound++) { |
84
|
|
|
// |
85
|
|
|
// } |
86
|
|
|
// } else { |
87
|
|
|
// Fight::saveRoundRobinFights($championship, $tree); |
88
|
|
|
// } |
89
|
|
|
// } elseif ($settings->treeType == config('kendo-tournaments.DIRECT_ELIMINATION')) { |
90
|
|
|
// Fight::saveFightRound($tree); // Always C1 x C2 |
91
|
|
|
// } elseif ($settings->treeType == config('kendo-tournaments.ROUND_ROBIN')) { |
92
|
|
|
// Fight::saveRoundRobinFights($championship, $tree); |
93
|
|
|
// |
94
|
|
|
// } |
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.