| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 | use Xoco70\KendoTournaments\TreeGen\DirectEliminationTreeGen; | 
| 3 | 3 | |
| 4 | -$directEliminationTree = $championship->rounds->map(function ($item, $key) use ($championship) { | |
| 5 | -    if ($championship->category->isTeam()){ | |
| 4 | +$directEliminationTree = $championship->rounds->map(function($item, $key) use ($championship) { | |
| 5 | +    if ($championship->category->isTeam()) { | |
| 6 | 6 | |
| 7 | 7 | $fighter1 = $item->team1 != null ? $item->team1->name : "Bye"; | 
| 8 | 8 | $fighter2 = $item->team2 != null ? $item->team2->name : "Bye"; | 
| 9 | -    }else{ | |
| 9 | +    } else { | |
| 10 | 10 | $fighter1 = $item->competitors->get(0) != null ? $item->competitors->get(0)->user->name : "Bye"; | 
| 11 | 11 | $fighter2 = $item->competitors->get(1) != null ? $item->competitors->get(1)->user->name : "Bye"; | 
| 12 | 12 | } | 
| @@ -35,7 +35,7 @@ discard block | ||
| 35 | 35 | |
| 36 | 36 | //Make sure there's at least 2 teams | 
| 37 | 37 | |
| 38 | -            if(count($teams) == 1){ | |
| 38 | +            if (count($teams) == 1) { | |
| 39 | 39 | $teams[] = 'Team 2'; | 
| 40 | 40 | } | 
| 41 | 41 | |
| @@ -45,21 +45,21 @@ discard block | ||
| 45 | 45 | |
| 46 | 46 | |
| 47 | 47 | //Calculate the size of the first full round - for example if you have 5 teams, then the first full round will consist of 4 teams | 
| 48 | - $minimumFirstRoundSize = pow(2, ceil(log($this->noTeams)/log(2))); | |
| 48 | + $minimumFirstRoundSize = pow(2, ceil(log($this->noTeams) / log(2))); | |
| 49 | 49 | $this->noRounds = log($minimumFirstRoundSize, 2); | 
| 50 | 50 | $noByesToAdd = $minimumFirstRoundSize - $this->noTeams; | 
| 51 | 51 | |
| 52 | 52 | //Add the byes to the teams array | 
| 53 | -        for($i = 0; $i < $noByesToAdd; $i++){ | |
| 53 | +        for ($i = 0; $i < $noByesToAdd; $i++) { | |
| 54 | 54 | $teams[] = null; | 
| 55 | 55 | } | 
| 56 | 56 | |
| 57 | 57 | //Order the teams in a seeded order - this is required regardless of whether it is a seeded tournament or not, as it prevents BYEs playing eachother | 
| 58 | -        for($i = 0; $i < log($this->noTeams / 2, 2); $i++){ | |
| 58 | +        for ($i = 0; $i < log($this->noTeams / 2, 2); $i++) { | |
| 59 | 59 | |
| 60 | 60 | $out = array(); | 
| 61 | 61 | |
| 62 | -            foreach($teams as $player){ | |
| 62 | +            foreach ($teams as $player) { | |
| 63 | 63 | $splice = pow(2, $i); | 
| 64 | 64 | $out = array_merge($out, array_splice($teams, 0, $splice)); | 
| 65 | 65 | $out = array_merge($out, array_splice($teams, -$splice)); | 
| @@ -91,14 +91,14 @@ discard block | ||
| 91 | 91 | $matches = array_chunk($teams, 2); | 
| 92 | 92 | |
| 93 | 93 | //Only check for BYEs if there are more than 2 teams | 
| 94 | -        if($this->noTeams > 2){ | |
| 94 | +        if ($this->noTeams > 2) { | |
| 95 | 95 | |
| 96 | -            foreach($matches as $key => &$match){ | |
| 96 | +            foreach ($matches as $key => &$match) { | |
| 97 | 97 | |
| 98 | 98 | $matchNumber = $key + 1; | 
| 99 | 99 | |
| 100 | 100 | //If both teams are present, then that means they haven't had a BYE to the next round, so they must play in the first round | 
| 101 | -                if($match[0] && $match[1]){ | |
| 101 | +                if ($match[0] && $match[1]) { | |
| 102 | 102 | |
| 103 | 103 | //Add the match to the first round | 
| 104 | 104 | $this->brackets[$roundNumber][$matchNumber] = $match; | 
| @@ -106,7 +106,7 @@ discard block | ||
| 106 | 106 | //Set the match to null as the result of the above match hasn't yet been determined | 
| 107 | 107 | $match = null; | 
| 108 | 108 | |
| 109 | -                }else{ | |
| 109 | +                } else { | |
| 110 | 110 | |
| 111 | 111 | //If only the first or second player exists, then replace the multidimensional array with the existing player | 
| 112 | 112 | $match = $match[0] ? $match[0] : $match[1]; | 
| @@ -121,17 +121,17 @@ discard block | ||
| 121 | 121 | } | 
| 122 | 122 | |
| 123 | 123 | //If there's already a match in the match array, then that means the next round is round 2, so increase the round number | 
| 124 | - if(count($this->brackets)) $roundNumber++; | |
| 124 | + if (count($this->brackets)) $roundNumber++; | |
| 125 | 125 | |
| 126 | 126 | //Create the first full round of teams, some may be blank if waiting on the results of a previous round | 
| 127 | -        for($i = 0; $i < count($matches); $i++){ | |
| 128 | - $this->brackets[$roundNumber][$i+1] = $matches[$i]; | |
| 127 | +        for ($i = 0; $i < count($matches); $i++) { | |
| 128 | + $this->brackets[$roundNumber][$i + 1] = $matches[$i]; | |
| 129 | 129 | } | 
| 130 | 130 | |
| 131 | 131 | //Create the result of the empty rows for this tournament | 
| 132 | 132 | |
| 133 | -        for($roundNumber += 1; $roundNumber <= $this->noRounds; $roundNumber++){ | |
| 134 | -            for($matchNumber = 1; $matchNumber <= ($minimumFirstRoundSize/pow(2, $roundNumber)); $matchNumber++){ | |
| 133 | +        for ($roundNumber += 1; $roundNumber <= $this->noRounds; $roundNumber++) { | |
| 134 | +            for ($matchNumber = 1; $matchNumber <= ($minimumFirstRoundSize / pow(2, $roundNumber)); $matchNumber++) { | |
| 135 | 135 | $this->brackets[$roundNumber][$matchNumber] = array(null, null); | 
| 136 | 136 | } | 
| 137 | 137 | } | 
| @@ -148,9 +148,9 @@ discard block | ||
| 148 | 148 | $matchSpacingMultiplier = 0.5; | 
| 149 | 149 | $playerWrapperHeightMultiplier = 1; | 
| 150 | 150 | |
| 151 | -        foreach($this->brackets as $roundNumber => &$round){ | |
| 151 | +        foreach ($this->brackets as $roundNumber => &$round) { | |
| 152 | 152 | |
| 153 | -            foreach($round as $matchNumber => &$match){ | |
| 153 | +            foreach ($round as $matchNumber => &$match) { | |
| 154 | 154 | |
| 155 | 155 | //Give teams a nicer index | 
| 156 | 156 | |
| @@ -172,9 +172,9 @@ discard block | ||
| 172 | 172 | |
| 173 | 173 | //Adjust the positions depending on the match number | 
| 174 | 174 | |
| 175 | -                if(!($matchNumber % 2)){ | |
| 175 | +                if (!($matchNumber % 2)) { | |
| 176 | 176 | $match['hConnector2Top'] = $match['vConnectorTop'] -= ($match['vConnectorHeight'] - $this->borderWidth); | 
| 177 | -                }else{ | |
| 177 | +                } else { | |
| 178 | 178 | $match['hConnector2Top'] = $match['vConnectorTop'] + ($match['vConnectorHeight'] - $this->borderWidth); | 
| 179 | 179 | } | 
| 180 | 180 | |
| @@ -196,24 +196,24 @@ discard block | ||
| 196 | 196 | |
| 197 | 197 | echo '<div id="brackets-wrapper">'; | 
| 198 | 198 | |
| 199 | -        foreach($this->brackets as $roundNumber => $round) { | |
| 199 | +        foreach ($this->brackets as $roundNumber => $round) { | |
| 200 | 200 | |
| 201 | -            foreach($round as $matchNumber => $match) { | |
| 201 | +            foreach ($round as $matchNumber => $match) { | |
| 202 | 202 | |
| 203 | - echo '<div class="match-wrapper" style="top: '.$match['matchWrapperTop'].'px; left: '.$match['matchWrapperLeft'].'px; width: '.$this->matchWrapperWidth.'px;"> | |
| 203 | + echo '<div class="match-wrapper" style="top: ' . $match['matchWrapperTop'] . 'px; left: ' . $match['matchWrapperLeft'] . 'px; width: ' . $this->matchWrapperWidth . 'px;"> | |
| 204 | 204 | <input type="text" class="score">' | 
| 205 | - .$this->getPlayerList($match['playerA']). | |
| 205 | + .$this->getPlayerList($match['playerA']) . | |
| 206 | 206 | '<div class="match-divider"> | 
| 207 | 207 | </div> | 
| 208 | 208 | <input type="text" class="score">' | 
| 209 | - .$this->getPlayerList($match['playerB']). | |
| 209 | + .$this->getPlayerList($match['playerB']) . | |
| 210 | 210 | '</div>'; | 
| 211 | 211 | |
| 212 | 212 |                  if ($roundNumber != $this->noRounds) { | 
| 213 | 213 | |
| 214 | - echo '<div class="vertical-connector" style="top: '.$match['vConnectorTop'].'px; left: '.$match['vConnectorLeft'].'px; height: '.$match['vConnectorHeight'].'px;"></div> | |
| 215 | - <div class="horizontal-connector" style="top: '.$match['hConnectorTop'].'px; left: '.$match['hConnectorLeft'].'px;"></div> | |
| 216 | - <div class="horizontal-connector" style="top: '.$match['hConnector2Top'].'px; left: '.$match['hConnector2Left'].'px;"></div>'; | |
| 214 | + echo '<div class="vertical-connector" style="top: ' . $match['vConnectorTop'] . 'px; left: ' . $match['vConnectorLeft'] . 'px; height: ' . $match['vConnectorHeight'] . 'px;"></div> | |
| 215 | + <div class="horizontal-connector" style="top: '.$match['hConnectorTop'] . 'px; left: ' . $match['hConnectorLeft'] . 'px;"></div> | |
| 216 | + <div class="horizontal-connector" style="top: '.$match['hConnector2Top'] . 'px; left: ' . $match['hConnector2Left'] . 'px;"></div>'; | |
| 217 | 217 | |
| 218 | 218 | } | 
| 219 | 219 | |
| @@ -225,31 +225,31 @@ discard block | ||
| 225 | 225 | |
| 226 | 226 | } | 
| 227 | 227 | |
| 228 | -    private function printRoundTitles(){ | |
| 228 | +    private function printRoundTitles() { | |
| 229 | 229 | |
| 230 | -        if($this->noTeams == 2){ | |
| 230 | +        if ($this->noTeams == 2) { | |
| 231 | 231 | |
| 232 | 232 |              $roundTitles = array('Final'); | 
| 233 | 233 | |
| 234 | -        }elseif($this->noTeams <= 4){ | |
| 234 | +        }elseif ($this->noTeams <= 4) { | |
| 235 | 235 | |
| 236 | 236 |              $roundTitles = array('Semi-Finals', 'Final'); | 
| 237 | 237 | |
| 238 | -        }elseif($this->noTeams <= 8){ | |
| 238 | +        }elseif ($this->noTeams <= 8) { | |
| 239 | 239 | |
| 240 | 240 |              $roundTitles = array('Quarter-Finals', 'Semi-Finals', 'Final'); | 
| 241 | 241 | |
| 242 | -        }else{ | |
| 242 | +        } else { | |
| 243 | 243 | |
| 244 | 244 |              $roundTitles = array('Quarter-Finals', 'Semi-Finals', 'Final'); | 
| 245 | 245 | $noRounds = ceil(log($this->noTeams, 2)); | 
| 246 | - $noTeamsInFirstRound = pow(2, ceil(log($this->noTeams)/log(2))); | |
| 246 | + $noTeamsInFirstRound = pow(2, ceil(log($this->noTeams) / log(2))); | |
| 247 | 247 | $tempRounds = array(); | 
| 248 | 248 | |
| 249 | 249 | //The minus 3 is to ignore the final, semi final and quarter final rounds | 
| 250 | 250 | |
| 251 | -            for($i = 0; $i < $noRounds - 3; $i++){ | |
| 252 | - $tempRounds[] = 'Last '.$noTeamsInFirstRound; | |
| 251 | +            for ($i = 0; $i < $noRounds - 3; $i++) { | |
| 252 | + $tempRounds[] = 'Last ' . $noTeamsInFirstRound; | |
| 253 | 253 | $noTeamsInFirstRound /= 2; | 
| 254 | 254 | } | 
| 255 | 255 | |
| @@ -259,11 +259,11 @@ discard block | ||
| 259 | 259 | |
| 260 | 260 | echo '<div id="round-titles-wrapper">'; | 
| 261 | 261 | |
| 262 | -        foreach($roundTitles as $key => $roundTitle) { | |
| 262 | +        foreach ($roundTitles as $key => $roundTitle) { | |
| 263 | 263 | |
| 264 | 264 | $left = $key * ($this->matchWrapperWidth + $this->roundSpacing - 1); | 
| 265 | 265 | |
| 266 | - echo '<div class="round-title" style="left: '.$left.'px;">' . $roundTitle . '</div>'; | |
| 266 | + echo '<div class="round-title" style="left: ' . $left . 'px;">' . $roundTitle . '</div>'; | |
| 267 | 267 | |
| 268 | 268 | } | 
| 269 | 269 | |
| @@ -275,16 +275,16 @@ discard block | ||
| 275 | 275 |      { | 
| 276 | 276 | |
| 277 | 277 | $html = '<select> | 
| 278 | - <option'.($selected == '' ? ' selected' : '').'></option>'; | |
| 278 | + <option'.($selected == '' ? ' selected' : '') . '></option>'; | |
| 279 | 279 | |
| 280 | -        foreach(array_merge($this->brackets[1], $this->brackets[2]) as $bracket){ | |
| 280 | +        foreach (array_merge($this->brackets[1], $this->brackets[2]) as $bracket) { | |
| 281 | 281 | |
| 282 | -            if($bracket['playerA'] != ''){ | |
| 283 | - $html .= '<option'.($selected == $bracket['playerA'] ? ' selected' : '').'>'.$bracket['playerA'].'</option>'; | |
| 282 | +            if ($bracket['playerA'] != '') { | |
| 283 | + $html .= '<option' . ($selected == $bracket['playerA'] ? ' selected' : '') . '>' . $bracket['playerA'] . '</option>'; | |
| 284 | 284 | } | 
| 285 | 285 | |
| 286 | -            if($bracket['playerB'] != ''){ | |
| 287 | - $html .= '<option'.($selected == $bracket['playerB'] ? ' selected' : '').'>'.$bracket['playerB'].'</option>'; | |
| 286 | +            if ($bracket['playerB'] != '') { | |
| 287 | + $html .= '<option' . ($selected == $bracket['playerB'] ? ' selected' : '') . '>' . $bracket['playerB'] . '</option>'; | |
| 288 | 288 | } | 
| 289 | 289 | |
| 290 | 290 | } | 
| @@ -106,7 +106,7 @@ discard block | ||
| 106 | 106 | //Set the match to null as the result of the above match hasn't yet been determined | 
| 107 | 107 | $match = null; | 
| 108 | 108 | |
| 109 | -                }else{ | |
| 109 | +                } else{ | |
| 110 | 110 | |
| 111 | 111 | //If only the first or second player exists, then replace the multidimensional array with the existing player | 
| 112 | 112 | $match = $match[0] ? $match[0] : $match[1]; | 
| @@ -121,7 +121,9 @@ discard block | ||
| 121 | 121 | } | 
| 122 | 122 | |
| 123 | 123 | //If there's already a match in the match array, then that means the next round is round 2, so increase the round number | 
| 124 | - if(count($this->brackets)) $roundNumber++; | |
| 124 | +        if(count($this->brackets)) { | |
| 125 | + $roundNumber++; | |
| 126 | + } | |
| 125 | 127 | |
| 126 | 128 | //Create the first full round of teams, some may be blank if waiting on the results of a previous round | 
| 127 | 129 |          for($i = 0; $i < count($matches); $i++){ | 
| @@ -174,7 +176,7 @@ discard block | ||
| 174 | 176 | |
| 175 | 177 |                  if(!($matchNumber % 2)){ | 
| 176 | 178 | $match['hConnector2Top'] = $match['vConnectorTop'] -= ($match['vConnectorHeight'] - $this->borderWidth); | 
| 177 | -                }else{ | |
| 179 | +                } else{ | |
| 178 | 180 | $match['hConnector2Top'] = $match['vConnectorTop'] + ($match['vConnectorHeight'] - $this->borderWidth); | 
| 179 | 181 | } | 
| 180 | 182 | |
| @@ -231,15 +233,15 @@ discard block | ||
| 231 | 233 | |
| 232 | 234 |              $roundTitles = array('Final'); | 
| 233 | 235 | |
| 234 | -        }elseif($this->noTeams <= 4){ | |
| 236 | +        } elseif($this->noTeams <= 4){ | |
| 235 | 237 | |
| 236 | 238 |              $roundTitles = array('Semi-Finals', 'Final'); | 
| 237 | 239 | |
| 238 | -        }elseif($this->noTeams <= 8){ | |
| 240 | +        } elseif($this->noTeams <= 8){ | |
| 239 | 241 | |
| 240 | 242 |              $roundTitles = array('Quarter-Finals', 'Semi-Finals', 'Final'); | 
| 241 | 243 | |
| 242 | -        }else{ | |
| 244 | +        } else{ | |
| 243 | 245 | |
| 244 | 246 |              $roundTitles = array('Quarter-Finals', 'Semi-Finals', 'Final'); | 
| 245 | 247 | $noRounds = ceil(log($this->noTeams, 2)); |