| @@ 13-108 (lines=96) @@ | ||
| 10 | use Xoco70\LaravelTournaments\Models\FighterGroupCompetitor; |
|
| 11 | use Xoco70\LaravelTournaments\Models\FightersGroup; |
|
| 12 | ||
| 13 | class SingleEliminationCompetitorTreeGen extends SingleEliminationTreeGen |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * get Fighter by Id. |
|
| 17 | * |
|
| 18 | * @param $competitorId |
|
| 19 | * |
|
| 20 | * @return Competitor |
|
| 21 | */ |
|
| 22 | protected function getFighter($competitorId) |
|
| 23 | { |
|
| 24 | return Competitor::find($competitorId); |
|
| 25 | } |
|
| 26 | ||
| 27 | /** |
|
| 28 | * Fighter is the name for competitor or team, depending on the case. |
|
| 29 | * |
|
| 30 | * @return Collection |
|
| 31 | */ |
|
| 32 | protected function getFighters() |
|
| 33 | { |
|
| 34 | return $this->championship->competitors; |
|
| 35 | } |
|
| 36 | ||
| 37 | /** |
|
| 38 | * @param $group |
|
| 39 | * @param $fighters |
|
| 40 | */ |
|
| 41 | public function syncGroup(FightersGroup $group, $fighters) |
|
| 42 | { |
|
| 43 | return $group->syncCompetitors($fighters); |
|
| 44 | } |
|
| 45 | ||
| 46 | protected function createByeFighter() |
|
| 47 | { |
|
| 48 | return new Competitor(); |
|
| 49 | } |
|
| 50 | ||
| 51 | protected function addFighterToGroup(FightersGroup $group, $competitor) |
|
| 52 | { |
|
| 53 | $group->competitors()->attach($competitor->id); |
|
| 54 | } |
|
| 55 | ||
| 56 | /** |
|
| 57 | * Chunk Fighters into groups for fighting, and optionnaly shuffle. |
|
| 58 | * |
|
| 59 | * @param $fightersByEntity |
|
| 60 | * |
|
| 61 | * @return Collection|null |
|
| 62 | */ |
|
| 63 | protected function chunkAndShuffle(Collection $fightersByEntity) |
|
| 64 | { |
|
| 65 | if ($this->championship->hasPreliminary()) { |
|
| 66 | return (new PlayOffCompetitorTreeGen($this->championship, null))->chunkAndShuffle($fightersByEntity); |
|
| 67 | } |
|
| 68 | $fightersGroup = null; |
|
| 69 | ||
| 70 | $fightersGroup = $fightersByEntity->chunk(2); |
|
| 71 | if (!app()->runningUnitTests()) { |
|
| 72 | $fightersGroup = $fightersGroup->shuffle(); |
|
| 73 | } |
|
| 74 | ||
| 75 | return $fightersGroup; |
|
| 76 | } |
|
| 77 | ||
| 78 | /** |
|
| 79 | * @param FightersGroup $group |
|
| 80 | * @param Fight $fight |
|
| 81 | * @param $oldCompetitors |
|
| 82 | */ |
|
| 83 | protected function updateGroupFighters(FightersGroup $group, Fight $fight, $oldCompetitors) |
|
| 84 | { |
|
| 85 | ||
| 86 | for ($num = 0; $num <=1;$num++){ |
|
| 87 | $c1or2 = "c".($num+1); |
|
| 88 | $fgc = FighterGroupCompetitor::where('fighters_group_id', $group->id) |
|
| 89 | ->where('competitor_id', $oldCompetitors[$num]) |
|
| 90 | ->first(); |
|
| 91 | $fgc->competitor_id = $fight->$c1or2; |
|
| 92 | } |
|
| 93 | ||
| 94 | ||
| 95 | $fgc->save(); |
|
| 96 | ||
| 97 | // Get the round of this FGC |
|
| 98 | // $numRound = $fgc->group->round; |
|
| 99 | // $groupsIdInThisRound = $this->championship->groupsByRound($numRound)->pluck('id'); |
|
| 100 | // $count = FighterGroupCompetitor::whereIn('fighters_group_id', $groupsIdInThisRound) |
|
| 101 | // ->where('competitor_id', $fgc->competitor_id) |
|
| 102 | // ->count(); |
|
| 103 | // |
|
| 104 | // if ($count > 1) { |
|
| 105 | // throw new DuplicatedFighterException(trans('laravel-tournaments::core.duplicated_fighter_in_group')); |
|
| 106 | // } |
|
| 107 | } |
|
| 108 | } |
|
| 109 | ||
| @@ 11-105 (lines=95) @@ | ||
| 8 | use Xoco70\LaravelTournaments\Models\FightersGroup; |
|
| 9 | use Xoco70\LaravelTournaments\Models\Team; |
|
| 10 | ||
| 11 | class SingleEliminationTeamTreeGen extends SingleEliminationTreeGen |
|
| 12 | { |
|
| 13 | /** |
|
| 14 | * get Fighter by Id. |
|
| 15 | * |
|
| 16 | * @return Team |
|
| 17 | */ |
|
| 18 | protected function getFighter($teamId) |
|
| 19 | { |
|
| 20 | return Team::find($teamId); |
|
| 21 | } |
|
| 22 | ||
| 23 | /** |
|
| 24 | * Fighter is the name for competitor or team, depending on the case. |
|
| 25 | * |
|
| 26 | * @return Collection |
|
| 27 | */ |
|
| 28 | protected function getFighters() |
|
| 29 | { |
|
| 30 | return $this->championship->teams; |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * @param FightersGroup $group |
|
| 35 | * @param $fighters |
|
| 36 | * |
|
| 37 | * @return FightersGroup |
|
| 38 | */ |
|
| 39 | public function syncGroup(FightersGroup $group, $fighters) |
|
| 40 | { |
|
| 41 | // Add all competitors to Pivot Table |
|
| 42 | return $group->syncTeams($fighters); |
|
| 43 | } |
|
| 44 | ||
| 45 | protected function createByeFighter() |
|
| 46 | { |
|
| 47 | return new Team(); |
|
| 48 | } |
|
| 49 | ||
| 50 | protected function addFighterToGroup(FightersGroup $group, $team) |
|
| 51 | { |
|
| 52 | $group->teams()->attach($team->id); |
|
| 53 | } |
|
| 54 | /** |
|
| 55 | * Chunk Fighters into groups for fighting, and optionnaly shuffle. |
|
| 56 | * |
|
| 57 | * @param $fightersByEntity |
|
| 58 | * |
|
| 59 | * @return Collection|null |
|
| 60 | */ |
|
| 61 | protected function chunkAndShuffle(Collection $fightersByEntity) |
|
| 62 | { |
|
| 63 | if ($this->championship->hasPreliminary()) { |
|
| 64 | return (new PlayOffTeamTreeGen($this->championship, null))->chunkAndShuffle($fightersByEntity); |
|
| 65 | } |
|
| 66 | $fightersGroup = null; |
|
| 67 | ||
| 68 | $fightersGroup = $fightersByEntity->chunk(2); |
|
| 69 | if (!app()->runningUnitTests()) { |
|
| 70 | $fightersGroup = $fightersGroup->shuffle(); |
|
| 71 | } |
|
| 72 | ||
| 73 | return $fightersGroup; |
|
| 74 | } |
|
| 75 | ||
| 76 | ||
| 77 | /** |
|
| 78 | * @param FightersGroup $group |
|
| 79 | * @param Fight $fight |
|
| 80 | * @param $oldTeams |
|
| 81 | */ |
|
| 82 | protected function updateGroupFighters(FightersGroup $group, Fight $fight, $oldTeams) |
|
| 83 | { |
|
| 84 | ||
| 85 | for ($num = 0; $num <=1;$num++){ |
|
| 86 | $c1or2 = "c".($num+1); |
|
| 87 | $fgc = FighterGroupTeam::where('fighters_group_id', $group->id) |
|
| 88 | ->where('team_id', $oldTeams[$num]) |
|
| 89 | ->first(); |
|
| 90 | $fgc->team_id = $fight->$c1or2; |
|
| 91 | } |
|
| 92 | $fgc->save(); |
|
| 93 | ||
| 94 | // Get the round of this FGC |
|
| 95 | // $numRound = $fgc->group->round; |
|
| 96 | // $groupsIdInThisRound = $this->championship->groupsByRound($numRound)->pluck('id'); |
|
| 97 | // $count = FighterGroupCompetitor::whereIn('fighters_group_id', $groupsIdInThisRound) |
|
| 98 | // ->where('competitor_id', $fgc->competitor_id) |
|
| 99 | // ->count(); |
|
| 100 | // |
|
| 101 | // if ($count > 1) { |
|
| 102 | // throw new DuplicatedFighterException(trans('laravel-tournaments::core.duplicated_fighter_in_group')); |
|
| 103 | // } |
|
| 104 | } |
|
| 105 | } |
|
| 106 | ||