@@ -6,14 +6,14 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | class TeamMatchesController extends \BaseController { |
| 8 | 8 | |
| 9 | - public function __construct(MatchService $match, MatchRoundRepository $matchRoundRepo, TeamMatchesRepository $teamMatchesRepository) |
|
| 10 | - { |
|
| 11 | - $this->match = $match; |
|
| 12 | - $this->matchRoundRepo = $matchRoundRepo; |
|
| 13 | - $this->teamMatchesRepo = $teamMatchesRepository; |
|
| 14 | - } |
|
| 15 | - |
|
| 16 | - /** |
|
| 9 | + public function __construct(MatchService $match, MatchRoundRepository $matchRoundRepo, TeamMatchesRepository $teamMatchesRepository) |
|
| 10 | + { |
|
| 11 | + $this->match = $match; |
|
| 12 | + $this->matchRoundRepo = $matchRoundRepo; |
|
| 13 | + $this->teamMatchesRepo = $teamMatchesRepository; |
|
| 14 | + } |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | 17 | * Display a listing of the resource. |
| 18 | 18 | * |
| 19 | 19 | * @return Response |
@@ -54,263 +54,263 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public function show($id) |
| 56 | 56 | { |
| 57 | - $group = Input::get('group'); // Stay in controller |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - $groupPlayers = $this->matchRoundRepo->matchGroup($id, $group); |
|
| 61 | - |
|
| 62 | - // |
|
| 63 | - // Create Player data from MatchRound Repo |
|
| 64 | - // Takes group of players |
|
| 65 | - // |
|
| 66 | - // Creates data array for each player in the match |
|
| 67 | - // |
|
| 68 | - $matchUp = array(); |
|
| 69 | - foreach($groupPlayers as $key=>$groupPlayer){ |
|
| 70 | - $matchUp[$key]['player'] = $groupPlayer->pivot->player_id; |
|
| 71 | - $matchUp[$key]['matchHandicap'] = round($groupPlayer->pivot->handicap ,0); |
|
| 72 | - foreach ($groupPlayer->round as $round){ |
|
| 73 | - $matchUp[$key]['team'] = $round->team_id; |
|
| 74 | - $matchUp[$key]['course'] = $round->course_id; |
|
| 75 | - $matchUp[$key]['holescores'] = $round->holescores; |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // Change lowest handicap to ZERO and change others to reflect it |
|
| 80 | - // Create array of each players handicap |
|
| 81 | - foreach($matchUp as $key=>$match){ |
|
| 82 | - $matchHandicaps[] = $match['matchHandicap']; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - // Determine the lowest handicap in the group |
|
| 86 | - $lowestMatchHandicap = min($matchHandicaps); |
|
| 87 | - |
|
| 88 | - //handicapChange is the number of strokes to offset on the others handicap |
|
| 89 | - $handicapChange = $lowestMatchHandicap * -1; |
|
| 90 | - |
|
| 91 | - // Adjust all handicaps |
|
| 92 | - foreach($matchUp as $key=>$match){ |
|
| 93 | - $matchUp[$key]['matchHandicap'] = $match['matchHandicap'] + $handicapChange; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // Separate group into two teams |
|
| 97 | - |
|
| 98 | - foreach($matchUp as $key=>$item){ |
|
| 99 | - $teamIds[$key] = $item['team']; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - sort($teamIds); |
|
| 103 | - |
|
| 104 | - //$teamIds = array_slice($teamIds, 1, -1); |
|
| 105 | - $teamIds = array_unique($teamIds); |
|
| 106 | - $teamIds = array_values($teamIds); //reset array keys |
|
| 107 | - |
|
| 108 | - $team1Id = $teamIds[0]; |
|
| 109 | - $team2Id = $teamIds[1]; |
|
| 110 | - |
|
| 111 | - $team1 = array(); |
|
| 112 | - $team2 = array(); |
|
| 113 | - |
|
| 114 | - foreach($matchUp as $key=>$match){ |
|
| 115 | - if($match['team'] ==$team1Id ){ |
|
| 116 | - $team1[] = $matchUp[$key]; |
|
| 117 | - } else { |
|
| 118 | - $team2[] = $matchUp[$key]; |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - $team1Name = Team::select('name')->where('id', '=', $team1Id)->get()->toArray(); |
|
| 124 | - foreach($matchUp as $key=>$match){ |
|
| 125 | - if($match['team'] == $team1[0]['team']){ |
|
| 126 | - $team1[] = $match; |
|
| 127 | - unset($matchUp[$key]); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - $team2 = $matchUp; |
|
| 132 | - |
|
| 133 | - $team2Name = Team::select('name')->where('id', '=', $team2Id)->get()->toArray(); |
|
| 134 | - |
|
| 135 | - $holesData = Hole::select('handicap')->where('course_id', '=', $team1[0]['course'])->get(); |
|
| 136 | - |
|
| 137 | - $team1Scores = $this->getTeamNetScore($team1, $holesData); |
|
| 138 | - $team2Scores = $this->getTeamNetScore($team2, $holesData); |
|
| 139 | - |
|
| 140 | - $team1Points = $this->calculatePoints($team1Scores, $team2Scores); |
|
| 141 | - $team2Points = $this->calculatePoints($team2Scores, $team1Scores); |
|
| 142 | - |
|
| 143 | - // Bonus point logic |
|
| 144 | - // Occurs after 9th hole score is added to both teams |
|
| 145 | - |
|
| 146 | - $team1Bonus = null; |
|
| 147 | - $team2Bonus = null; |
|
| 148 | - |
|
| 149 | - if($team1Scores[8] != null && $team2Scores[8] != null){ |
|
| 150 | - if($team1Points > $team2Points){ |
|
| 151 | - $team1Points = $team1Points + 1; |
|
| 152 | - $team1Bonus = 1; |
|
| 153 | - } |
|
| 154 | - if($team2Points > $team1Points){ |
|
| 155 | - $team2Points = $team2Points + 1; |
|
| 156 | - $team2Bonus = 1; |
|
| 157 | - } |
|
| 158 | - if($team1Points == $team2Points){ |
|
| 159 | - $team1Points = $team1Points + .5; |
|
| 160 | - $team1Bonus = .5; |
|
| 161 | - $team2Points = $team2Points + .5; |
|
| 162 | - $team2Bonus = .5; |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - //Save Points in Teammatches |
|
| 167 | - Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team1Id)->update(array('pointsWon' => $team1Points)); |
|
| 168 | - Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team2Id)->update(array('pointsWon' => $team2Points)); |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - //Need to determine if same amount of scores are in both |
|
| 172 | - // If not then do not return |
|
| 173 | - |
|
| 174 | - foreach($team1Scores as $key=>$teamScore){ |
|
| 175 | - if($teamScore <= 0){ |
|
| 176 | - $team1Scores[$key] = ''; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - $team1Net = array_sum($team1Scores); |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - foreach($team2Scores as $key=>$teamScore){ |
|
| 183 | - if($teamScore <= 0){ |
|
| 184 | - $team2Scores[$key] = ''; |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - $team2Net = array_sum($team2Scores); |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - $team[0] = [ |
|
| 191 | - "team" => $team1Name[0]['name'], |
|
| 192 | - "hole1" => $team1Scores[0], |
|
| 193 | - "hole2" => $team1Scores[1], |
|
| 194 | - "hole3" => $team1Scores[2], |
|
| 195 | - "hole4" => $team1Scores[3], |
|
| 196 | - "hole5" => $team1Scores[4], |
|
| 197 | - "hole6" => $team1Scores[5], |
|
| 198 | - "hole7" => $team1Scores[6], |
|
| 199 | - "hole8" => $team1Scores[7], |
|
| 200 | - "hole9" => $team1Scores[8], |
|
| 201 | - "bonus" => $team1Bonus, |
|
| 202 | - "points" => $team1Points, |
|
| 203 | - "netscore" => $team1Net |
|
| 204 | - ]; |
|
| 205 | - |
|
| 206 | - $team[1] = [ |
|
| 207 | - "team" => $team2Name[0]['name'], |
|
| 208 | - "hole1" => $team2Scores[0], |
|
| 209 | - "hole2" => $team2Scores[1], |
|
| 210 | - "hole3" => $team2Scores[2], |
|
| 211 | - "hole4" => $team2Scores[3], |
|
| 212 | - "hole5" => $team2Scores[4], |
|
| 213 | - "hole6" => $team2Scores[5], |
|
| 214 | - "hole7" => $team2Scores[6], |
|
| 215 | - "hole8" => $team2Scores[7], |
|
| 216 | - "hole9" => $team2Scores[8], |
|
| 217 | - "bonus" => $team2Bonus, |
|
| 218 | - "points" => $team2Points, |
|
| 219 | - "netscore" => $team2Net, |
|
| 220 | - ]; |
|
| 221 | - |
|
| 222 | - $data['data'] = $team; |
|
| 223 | - return $data; |
|
| 57 | + $group = Input::get('group'); // Stay in controller |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + $groupPlayers = $this->matchRoundRepo->matchGroup($id, $group); |
|
| 61 | + |
|
| 62 | + // |
|
| 63 | + // Create Player data from MatchRound Repo |
|
| 64 | + // Takes group of players |
|
| 65 | + // |
|
| 66 | + // Creates data array for each player in the match |
|
| 67 | + // |
|
| 68 | + $matchUp = array(); |
|
| 69 | + foreach($groupPlayers as $key=>$groupPlayer){ |
|
| 70 | + $matchUp[$key]['player'] = $groupPlayer->pivot->player_id; |
|
| 71 | + $matchUp[$key]['matchHandicap'] = round($groupPlayer->pivot->handicap ,0); |
|
| 72 | + foreach ($groupPlayer->round as $round){ |
|
| 73 | + $matchUp[$key]['team'] = $round->team_id; |
|
| 74 | + $matchUp[$key]['course'] = $round->course_id; |
|
| 75 | + $matchUp[$key]['holescores'] = $round->holescores; |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // Change lowest handicap to ZERO and change others to reflect it |
|
| 80 | + // Create array of each players handicap |
|
| 81 | + foreach($matchUp as $key=>$match){ |
|
| 82 | + $matchHandicaps[] = $match['matchHandicap']; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + // Determine the lowest handicap in the group |
|
| 86 | + $lowestMatchHandicap = min($matchHandicaps); |
|
| 87 | + |
|
| 88 | + //handicapChange is the number of strokes to offset on the others handicap |
|
| 89 | + $handicapChange = $lowestMatchHandicap * -1; |
|
| 90 | + |
|
| 91 | + // Adjust all handicaps |
|
| 92 | + foreach($matchUp as $key=>$match){ |
|
| 93 | + $matchUp[$key]['matchHandicap'] = $match['matchHandicap'] + $handicapChange; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // Separate group into two teams |
|
| 97 | + |
|
| 98 | + foreach($matchUp as $key=>$item){ |
|
| 99 | + $teamIds[$key] = $item['team']; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + sort($teamIds); |
|
| 103 | + |
|
| 104 | + //$teamIds = array_slice($teamIds, 1, -1); |
|
| 105 | + $teamIds = array_unique($teamIds); |
|
| 106 | + $teamIds = array_values($teamIds); //reset array keys |
|
| 107 | + |
|
| 108 | + $team1Id = $teamIds[0]; |
|
| 109 | + $team2Id = $teamIds[1]; |
|
| 110 | + |
|
| 111 | + $team1 = array(); |
|
| 112 | + $team2 = array(); |
|
| 113 | + |
|
| 114 | + foreach($matchUp as $key=>$match){ |
|
| 115 | + if($match['team'] ==$team1Id ){ |
|
| 116 | + $team1[] = $matchUp[$key]; |
|
| 117 | + } else { |
|
| 118 | + $team2[] = $matchUp[$key]; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + $team1Name = Team::select('name')->where('id', '=', $team1Id)->get()->toArray(); |
|
| 124 | + foreach($matchUp as $key=>$match){ |
|
| 125 | + if($match['team'] == $team1[0]['team']){ |
|
| 126 | + $team1[] = $match; |
|
| 127 | + unset($matchUp[$key]); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + $team2 = $matchUp; |
|
| 132 | + |
|
| 133 | + $team2Name = Team::select('name')->where('id', '=', $team2Id)->get()->toArray(); |
|
| 134 | + |
|
| 135 | + $holesData = Hole::select('handicap')->where('course_id', '=', $team1[0]['course'])->get(); |
|
| 136 | + |
|
| 137 | + $team1Scores = $this->getTeamNetScore($team1, $holesData); |
|
| 138 | + $team2Scores = $this->getTeamNetScore($team2, $holesData); |
|
| 139 | + |
|
| 140 | + $team1Points = $this->calculatePoints($team1Scores, $team2Scores); |
|
| 141 | + $team2Points = $this->calculatePoints($team2Scores, $team1Scores); |
|
| 142 | + |
|
| 143 | + // Bonus point logic |
|
| 144 | + // Occurs after 9th hole score is added to both teams |
|
| 145 | + |
|
| 146 | + $team1Bonus = null; |
|
| 147 | + $team2Bonus = null; |
|
| 148 | + |
|
| 149 | + if($team1Scores[8] != null && $team2Scores[8] != null){ |
|
| 150 | + if($team1Points > $team2Points){ |
|
| 151 | + $team1Points = $team1Points + 1; |
|
| 152 | + $team1Bonus = 1; |
|
| 153 | + } |
|
| 154 | + if($team2Points > $team1Points){ |
|
| 155 | + $team2Points = $team2Points + 1; |
|
| 156 | + $team2Bonus = 1; |
|
| 157 | + } |
|
| 158 | + if($team1Points == $team2Points){ |
|
| 159 | + $team1Points = $team1Points + .5; |
|
| 160 | + $team1Bonus = .5; |
|
| 161 | + $team2Points = $team2Points + .5; |
|
| 162 | + $team2Bonus = .5; |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + //Save Points in Teammatches |
|
| 167 | + Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team1Id)->update(array('pointsWon' => $team1Points)); |
|
| 168 | + Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team2Id)->update(array('pointsWon' => $team2Points)); |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + //Need to determine if same amount of scores are in both |
|
| 172 | + // If not then do not return |
|
| 173 | + |
|
| 174 | + foreach($team1Scores as $key=>$teamScore){ |
|
| 175 | + if($teamScore <= 0){ |
|
| 176 | + $team1Scores[$key] = ''; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + $team1Net = array_sum($team1Scores); |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + foreach($team2Scores as $key=>$teamScore){ |
|
| 183 | + if($teamScore <= 0){ |
|
| 184 | + $team2Scores[$key] = ''; |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + $team2Net = array_sum($team2Scores); |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + $team[0] = [ |
|
| 191 | + "team" => $team1Name[0]['name'], |
|
| 192 | + "hole1" => $team1Scores[0], |
|
| 193 | + "hole2" => $team1Scores[1], |
|
| 194 | + "hole3" => $team1Scores[2], |
|
| 195 | + "hole4" => $team1Scores[3], |
|
| 196 | + "hole5" => $team1Scores[4], |
|
| 197 | + "hole6" => $team1Scores[5], |
|
| 198 | + "hole7" => $team1Scores[6], |
|
| 199 | + "hole8" => $team1Scores[7], |
|
| 200 | + "hole9" => $team1Scores[8], |
|
| 201 | + "bonus" => $team1Bonus, |
|
| 202 | + "points" => $team1Points, |
|
| 203 | + "netscore" => $team1Net |
|
| 204 | + ]; |
|
| 205 | + |
|
| 206 | + $team[1] = [ |
|
| 207 | + "team" => $team2Name[0]['name'], |
|
| 208 | + "hole1" => $team2Scores[0], |
|
| 209 | + "hole2" => $team2Scores[1], |
|
| 210 | + "hole3" => $team2Scores[2], |
|
| 211 | + "hole4" => $team2Scores[3], |
|
| 212 | + "hole5" => $team2Scores[4], |
|
| 213 | + "hole6" => $team2Scores[5], |
|
| 214 | + "hole7" => $team2Scores[6], |
|
| 215 | + "hole8" => $team2Scores[7], |
|
| 216 | + "hole9" => $team2Scores[8], |
|
| 217 | + "bonus" => $team2Bonus, |
|
| 218 | + "points" => $team2Points, |
|
| 219 | + "netscore" => $team2Net, |
|
| 220 | + ]; |
|
| 221 | + |
|
| 222 | + $data['data'] = $team; |
|
| 223 | + return $data; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + private function getTeamNetScore($team, $holesData) |
|
| 227 | + { |
|
| 228 | + foreach($team as $key=>$item){ |
|
| 229 | + // Create holes array for NET |
|
| 230 | + $holes = array(); |
|
| 231 | + $i = 1; |
|
| 232 | + foreach($holesData as $key=>$holeData){ |
|
| 233 | + $holes[$i] = $holeData->handicap; |
|
| 234 | + $i++; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + // Create stroke array - how many to take away from score |
|
| 238 | + $strokeArray = [ |
|
| 239 | + 1 => 0, |
|
| 240 | + 2 => 0, |
|
| 241 | + 3 => 0, |
|
| 242 | + 4 => 0, |
|
| 243 | + 5 => 0, |
|
| 244 | + 6 => 0, |
|
| 245 | + 7 => 0, |
|
| 246 | + 8 => 0, |
|
| 247 | + 9 => 0 |
|
| 248 | + ]; |
|
| 249 | + //Create array of strokes |
|
| 250 | + for($counter = $item['matchHandicap']; $counter > 0; $counter--){ |
|
| 251 | + if($counter > 9){ |
|
| 252 | + $newCounter = $counter - 9; |
|
| 253 | + while($newCounter > 0) { |
|
| 254 | + $strokeArray[$newCounter] = $strokeArray[$newCounter] + 1; |
|
| 255 | + $counter--; |
|
| 256 | + $newCounter--; |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + $strokeArray[$counter] = $strokeArray[$counter] + 1; |
|
| 260 | + } |
|
| 261 | + // Plus handicaps don't hit previous loop so need its own |
|
| 262 | + //Plus handicap logic |
|
| 263 | + |
|
| 264 | + foreach($strokeArray as $strokeKey=>$stroke){ |
|
| 265 | + $holeKey = array_search($strokeKey,$holes); |
|
| 266 | + $holes[$holeKey] = $stroke; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + ///now have array of strokes to subtract |
|
| 270 | + //get array of holescores |
|
| 271 | + |
|
| 272 | + $holeScores = $item['holescores']; |
|
| 273 | + foreach($holeScores as $key=>$holeScore){ |
|
| 274 | + //check if new score is less PlayerScores |
|
| 275 | + if(isset($teamScores[$key])){ // 2nd time in for hole |
|
| 276 | + |
|
| 277 | + //set temp handi score |
|
| 278 | + $tempScore = $holeScore['score'] - $holes[$key+1]; |
|
| 279 | + if($teamScores[$key] >= $tempScore){ |
|
| 280 | + $teamScores[$key] = $holeScore['score'] - $holes[$key+1]; |
|
| 281 | + } |
|
| 282 | + } else{ // first time in for hole |
|
| 283 | + if($holeScore['score'] != null){ |
|
| 284 | + $teamScores[$key] = $holeScore['score'] - $holes[$key+1]; |
|
| 285 | + } else{ |
|
| 286 | + $teamScores[$key] = null; |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + } |
|
| 292 | + return $teamScores; |
|
| 224 | 293 | } |
| 225 | 294 | |
| 226 | - private function getTeamNetScore($team, $holesData) |
|
| 227 | - { |
|
| 228 | - foreach($team as $key=>$item){ |
|
| 229 | - // Create holes array for NET |
|
| 230 | - $holes = array(); |
|
| 231 | - $i = 1; |
|
| 232 | - foreach($holesData as $key=>$holeData){ |
|
| 233 | - $holes[$i] = $holeData->handicap; |
|
| 234 | - $i++; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - // Create stroke array - how many to take away from score |
|
| 238 | - $strokeArray = [ |
|
| 239 | - 1 => 0, |
|
| 240 | - 2 => 0, |
|
| 241 | - 3 => 0, |
|
| 242 | - 4 => 0, |
|
| 243 | - 5 => 0, |
|
| 244 | - 6 => 0, |
|
| 245 | - 7 => 0, |
|
| 246 | - 8 => 0, |
|
| 247 | - 9 => 0 |
|
| 248 | - ]; |
|
| 249 | - //Create array of strokes |
|
| 250 | - for($counter = $item['matchHandicap']; $counter > 0; $counter--){ |
|
| 251 | - if($counter > 9){ |
|
| 252 | - $newCounter = $counter - 9; |
|
| 253 | - while($newCounter > 0) { |
|
| 254 | - $strokeArray[$newCounter] = $strokeArray[$newCounter] + 1; |
|
| 255 | - $counter--; |
|
| 256 | - $newCounter--; |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - $strokeArray[$counter] = $strokeArray[$counter] + 1; |
|
| 260 | - } |
|
| 261 | - // Plus handicaps don't hit previous loop so need its own |
|
| 262 | - //Plus handicap logic |
|
| 263 | - |
|
| 264 | - foreach($strokeArray as $strokeKey=>$stroke){ |
|
| 265 | - $holeKey = array_search($strokeKey,$holes); |
|
| 266 | - $holes[$holeKey] = $stroke; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - ///now have array of strokes to subtract |
|
| 270 | - //get array of holescores |
|
| 271 | - |
|
| 272 | - $holeScores = $item['holescores']; |
|
| 273 | - foreach($holeScores as $key=>$holeScore){ |
|
| 274 | - //check if new score is less PlayerScores |
|
| 275 | - if(isset($teamScores[$key])){ // 2nd time in for hole |
|
| 276 | - |
|
| 277 | - //set temp handi score |
|
| 278 | - $tempScore = $holeScore['score'] - $holes[$key+1]; |
|
| 279 | - if($teamScores[$key] >= $tempScore){ |
|
| 280 | - $teamScores[$key] = $holeScore['score'] - $holes[$key+1]; |
|
| 281 | - } |
|
| 282 | - } else{ // first time in for hole |
|
| 283 | - if($holeScore['score'] != null){ |
|
| 284 | - $teamScores[$key] = $holeScore['score'] - $holes[$key+1]; |
|
| 285 | - } else{ |
|
| 286 | - $teamScores[$key] = null; |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - } |
|
| 292 | - return $teamScores; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - private function calculatePoints($team, $opponent) |
|
| 296 | - { |
|
| 297 | - $points = 0; |
|
| 298 | - $teamTotalPoints = 0; |
|
| 299 | - $opponentTotalPoints = 0; |
|
| 300 | - foreach ($team as $key=>$score){ |
|
| 301 | - if($score != null){ |
|
| 302 | - if($score < $opponent[$key]){ |
|
| 303 | - $points++; |
|
| 304 | - } |
|
| 305 | - if($score == $opponent[$key]){ |
|
| 306 | - $points = $points + .5; |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - return $points; |
|
| 313 | - } |
|
| 295 | + private function calculatePoints($team, $opponent) |
|
| 296 | + { |
|
| 297 | + $points = 0; |
|
| 298 | + $teamTotalPoints = 0; |
|
| 299 | + $opponentTotalPoints = 0; |
|
| 300 | + foreach ($team as $key=>$score){ |
|
| 301 | + if($score != null){ |
|
| 302 | + if($score < $opponent[$key]){ |
|
| 303 | + $points++; |
|
| 304 | + } |
|
| 305 | + if($score == $opponent[$key]){ |
|
| 306 | + $points = $points + .5; |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + return $points; |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | 315 | /** |
| 316 | 316 | * Show the form for editing the specified resource. |
@@ -348,22 +348,22 @@ discard block |
||
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | public function getPointsByYear($year) |
| 351 | - { |
|
| 352 | - $teamMatches = Teammatch::select('team_id','pointsWon')->whereYear('created_at', '=', $year)->with('team')->get(); |
|
| 353 | - foreach($teamMatches as $key=>$teamMatch){ |
|
| 354 | - $pointsData[$key]['name'] = $teamMatch['team']['name']; |
|
| 355 | - $pointsData[$key]['points'] = Teammatch::select('team_id','pointsWon') |
|
| 356 | - ->where('team_id', '=', $teamMatch->team_id) |
|
| 357 | - ->whereYear('created_at', '=', $year) |
|
| 358 | - ->with('team') |
|
| 359 | - ->sum('pointsWon'); |
|
| 360 | - |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - $pointsData = array_map("unserialize", array_unique(array_map("serialize", $pointsData))); |
|
| 364 | - $data['data'] = $pointsData; |
|
| 365 | - return $data; |
|
| 366 | - } |
|
| 351 | + { |
|
| 352 | + $teamMatches = Teammatch::select('team_id','pointsWon')->whereYear('created_at', '=', $year)->with('team')->get(); |
|
| 353 | + foreach($teamMatches as $key=>$teamMatch){ |
|
| 354 | + $pointsData[$key]['name'] = $teamMatch['team']['name']; |
|
| 355 | + $pointsData[$key]['points'] = Teammatch::select('team_id','pointsWon') |
|
| 356 | + ->where('team_id', '=', $teamMatch->team_id) |
|
| 357 | + ->whereYear('created_at', '=', $year) |
|
| 358 | + ->with('team') |
|
| 359 | + ->sum('pointsWon'); |
|
| 360 | + |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + $pointsData = array_map("unserialize", array_unique(array_map("serialize", $pointsData))); |
|
| 364 | + $data['data'] = $pointsData; |
|
| 365 | + return $data; |
|
| 366 | + } |
|
| 367 | 367 | |
| 368 | 368 | |
| 369 | 369 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public function show($id) |
| 56 | 56 | { |
| 57 | - $group = Input::get('group'); // Stay in controller |
|
| 57 | + $group = Input::get('group'); // Stay in controller |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | 60 | $groupPlayers = $this->matchRoundRepo->matchGroup($id, $group); |
@@ -66,10 +66,10 @@ discard block |
||
| 66 | 66 | // Creates data array for each player in the match |
| 67 | 67 | // |
| 68 | 68 | $matchUp = array(); |
| 69 | - foreach($groupPlayers as $key=>$groupPlayer){ |
|
| 69 | + foreach ($groupPlayers as $key=>$groupPlayer) { |
|
| 70 | 70 | $matchUp[$key]['player'] = $groupPlayer->pivot->player_id; |
| 71 | - $matchUp[$key]['matchHandicap'] = round($groupPlayer->pivot->handicap ,0); |
|
| 72 | - foreach ($groupPlayer->round as $round){ |
|
| 71 | + $matchUp[$key]['matchHandicap'] = round($groupPlayer->pivot->handicap, 0); |
|
| 72 | + foreach ($groupPlayer->round as $round) { |
|
| 73 | 73 | $matchUp[$key]['team'] = $round->team_id; |
| 74 | 74 | $matchUp[$key]['course'] = $round->course_id; |
| 75 | 75 | $matchUp[$key]['holescores'] = $round->holescores; |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | // Change lowest handicap to ZERO and change others to reflect it |
| 80 | 80 | // Create array of each players handicap |
| 81 | - foreach($matchUp as $key=>$match){ |
|
| 81 | + foreach ($matchUp as $key=>$match) { |
|
| 82 | 82 | $matchHandicaps[] = $match['matchHandicap']; |
| 83 | 83 | } |
| 84 | 84 | |
@@ -89,13 +89,13 @@ discard block |
||
| 89 | 89 | $handicapChange = $lowestMatchHandicap * -1; |
| 90 | 90 | |
| 91 | 91 | // Adjust all handicaps |
| 92 | - foreach($matchUp as $key=>$match){ |
|
| 92 | + foreach ($matchUp as $key=>$match) { |
|
| 93 | 93 | $matchUp[$key]['matchHandicap'] = $match['matchHandicap'] + $handicapChange; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | // Separate group into two teams |
| 97 | 97 | |
| 98 | - foreach($matchUp as $key=>$item){ |
|
| 98 | + foreach ($matchUp as $key=>$item) { |
|
| 99 | 99 | $teamIds[$key] = $item['team']; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -111,8 +111,8 @@ discard block |
||
| 111 | 111 | $team1 = array(); |
| 112 | 112 | $team2 = array(); |
| 113 | 113 | |
| 114 | - foreach($matchUp as $key=>$match){ |
|
| 115 | - if($match['team'] ==$team1Id ){ |
|
| 114 | + foreach ($matchUp as $key=>$match) { |
|
| 115 | + if ($match['team'] == $team1Id) { |
|
| 116 | 116 | $team1[] = $matchUp[$key]; |
| 117 | 117 | } else { |
| 118 | 118 | $team2[] = $matchUp[$key]; |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | |
| 123 | 123 | $team1Name = Team::select('name')->where('id', '=', $team1Id)->get()->toArray(); |
| 124 | - foreach($matchUp as $key=>$match){ |
|
| 125 | - if($match['team'] == $team1[0]['team']){ |
|
| 124 | + foreach ($matchUp as $key=>$match) { |
|
| 125 | + if ($match['team'] == $team1[0]['team']) { |
|
| 126 | 126 | $team1[] = $match; |
| 127 | 127 | unset($matchUp[$key]); |
| 128 | 128 | } |
@@ -146,16 +146,16 @@ discard block |
||
| 146 | 146 | $team1Bonus = null; |
| 147 | 147 | $team2Bonus = null; |
| 148 | 148 | |
| 149 | - if($team1Scores[8] != null && $team2Scores[8] != null){ |
|
| 150 | - if($team1Points > $team2Points){ |
|
| 149 | + if ($team1Scores[8] != null && $team2Scores[8] != null) { |
|
| 150 | + if ($team1Points > $team2Points) { |
|
| 151 | 151 | $team1Points = $team1Points + 1; |
| 152 | 152 | $team1Bonus = 1; |
| 153 | 153 | } |
| 154 | - if($team2Points > $team1Points){ |
|
| 154 | + if ($team2Points > $team1Points) { |
|
| 155 | 155 | $team2Points = $team2Points + 1; |
| 156 | 156 | $team2Bonus = 1; |
| 157 | 157 | } |
| 158 | - if($team1Points == $team2Points){ |
|
| 158 | + if ($team1Points == $team2Points) { |
|
| 159 | 159 | $team1Points = $team1Points + .5; |
| 160 | 160 | $team1Bonus = .5; |
| 161 | 161 | $team2Points = $team2Points + .5; |
@@ -171,16 +171,16 @@ discard block |
||
| 171 | 171 | //Need to determine if same amount of scores are in both |
| 172 | 172 | // If not then do not return |
| 173 | 173 | |
| 174 | - foreach($team1Scores as $key=>$teamScore){ |
|
| 175 | - if($teamScore <= 0){ |
|
| 174 | + foreach ($team1Scores as $key=>$teamScore) { |
|
| 175 | + if ($teamScore <= 0) { |
|
| 176 | 176 | $team1Scores[$key] = ''; |
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | $team1Net = array_sum($team1Scores); |
| 180 | 180 | |
| 181 | 181 | |
| 182 | - foreach($team2Scores as $key=>$teamScore){ |
|
| 183 | - if($teamScore <= 0){ |
|
| 182 | + foreach ($team2Scores as $key=>$teamScore) { |
|
| 183 | + if ($teamScore <= 0) { |
|
| 184 | 184 | $team2Scores[$key] = ''; |
| 185 | 185 | } |
| 186 | 186 | } |
@@ -225,11 +225,11 @@ discard block |
||
| 225 | 225 | |
| 226 | 226 | private function getTeamNetScore($team, $holesData) |
| 227 | 227 | { |
| 228 | - foreach($team as $key=>$item){ |
|
| 228 | + foreach ($team as $key=>$item) { |
|
| 229 | 229 | // Create holes array for NET |
| 230 | 230 | $holes = array(); |
| 231 | 231 | $i = 1; |
| 232 | - foreach($holesData as $key=>$holeData){ |
|
| 232 | + foreach ($holesData as $key=>$holeData) { |
|
| 233 | 233 | $holes[$i] = $holeData->handicap; |
| 234 | 234 | $i++; |
| 235 | 235 | } |
@@ -247,10 +247,10 @@ discard block |
||
| 247 | 247 | 9 => 0 |
| 248 | 248 | ]; |
| 249 | 249 | //Create array of strokes |
| 250 | - for($counter = $item['matchHandicap']; $counter > 0; $counter--){ |
|
| 251 | - if($counter > 9){ |
|
| 250 | + for ($counter = $item['matchHandicap']; $counter > 0; $counter--) { |
|
| 251 | + if ($counter > 9) { |
|
| 252 | 252 | $newCounter = $counter - 9; |
| 253 | - while($newCounter > 0) { |
|
| 253 | + while ($newCounter > 0) { |
|
| 254 | 254 | $strokeArray[$newCounter] = $strokeArray[$newCounter] + 1; |
| 255 | 255 | $counter--; |
| 256 | 256 | $newCounter--; |
@@ -261,8 +261,8 @@ discard block |
||
| 261 | 261 | // Plus handicaps don't hit previous loop so need its own |
| 262 | 262 | //Plus handicap logic |
| 263 | 263 | |
| 264 | - foreach($strokeArray as $strokeKey=>$stroke){ |
|
| 265 | - $holeKey = array_search($strokeKey,$holes); |
|
| 264 | + foreach ($strokeArray as $strokeKey=>$stroke) { |
|
| 265 | + $holeKey = array_search($strokeKey, $holes); |
|
| 266 | 266 | $holes[$holeKey] = $stroke; |
| 267 | 267 | } |
| 268 | 268 | |
@@ -270,19 +270,19 @@ discard block |
||
| 270 | 270 | //get array of holescores |
| 271 | 271 | |
| 272 | 272 | $holeScores = $item['holescores']; |
| 273 | - foreach($holeScores as $key=>$holeScore){ |
|
| 273 | + foreach ($holeScores as $key=>$holeScore) { |
|
| 274 | 274 | //check if new score is less PlayerScores |
| 275 | - if(isset($teamScores[$key])){ // 2nd time in for hole |
|
| 275 | + if (isset($teamScores[$key])) { // 2nd time in for hole |
|
| 276 | 276 | |
| 277 | 277 | //set temp handi score |
| 278 | - $tempScore = $holeScore['score'] - $holes[$key+1]; |
|
| 279 | - if($teamScores[$key] >= $tempScore){ |
|
| 280 | - $teamScores[$key] = $holeScore['score'] - $holes[$key+1]; |
|
| 278 | + $tempScore = $holeScore['score'] - $holes[$key + 1]; |
|
| 279 | + if ($teamScores[$key] >= $tempScore) { |
|
| 280 | + $teamScores[$key] = $holeScore['score'] - $holes[$key + 1]; |
|
| 281 | 281 | } |
| 282 | - } else{ // first time in for hole |
|
| 283 | - if($holeScore['score'] != null){ |
|
| 284 | - $teamScores[$key] = $holeScore['score'] - $holes[$key+1]; |
|
| 285 | - } else{ |
|
| 282 | + } else { // first time in for hole |
|
| 283 | + if ($holeScore['score'] != null) { |
|
| 284 | + $teamScores[$key] = $holeScore['score'] - $holes[$key + 1]; |
|
| 285 | + } else { |
|
| 286 | 286 | $teamScores[$key] = null; |
| 287 | 287 | } |
| 288 | 288 | } |
@@ -297,12 +297,12 @@ discard block |
||
| 297 | 297 | $points = 0; |
| 298 | 298 | $teamTotalPoints = 0; |
| 299 | 299 | $opponentTotalPoints = 0; |
| 300 | - foreach ($team as $key=>$score){ |
|
| 301 | - if($score != null){ |
|
| 302 | - if($score < $opponent[$key]){ |
|
| 300 | + foreach ($team as $key=>$score) { |
|
| 301 | + if ($score != null) { |
|
| 302 | + if ($score < $opponent[$key]) { |
|
| 303 | 303 | $points++; |
| 304 | 304 | } |
| 305 | - if($score == $opponent[$key]){ |
|
| 305 | + if ($score == $opponent[$key]) { |
|
| 306 | 306 | $points = $points + .5; |
| 307 | 307 | } |
| 308 | 308 | } |
@@ -349,10 +349,10 @@ discard block |
||
| 349 | 349 | |
| 350 | 350 | public function getPointsByYear($year) |
| 351 | 351 | { |
| 352 | - $teamMatches = Teammatch::select('team_id','pointsWon')->whereYear('created_at', '=', $year)->with('team')->get(); |
|
| 353 | - foreach($teamMatches as $key=>$teamMatch){ |
|
| 352 | + $teamMatches = Teammatch::select('team_id', 'pointsWon')->whereYear('created_at', '=', $year)->with('team')->get(); |
|
| 353 | + foreach ($teamMatches as $key=>$teamMatch) { |
|
| 354 | 354 | $pointsData[$key]['name'] = $teamMatch['team']['name']; |
| 355 | - $pointsData[$key]['points'] = Teammatch::select('team_id','pointsWon') |
|
| 355 | + $pointsData[$key]['points'] = Teammatch::select('team_id', 'pointsWon') |
|
| 356 | 356 | ->where('team_id', '=', $teamMatch->team_id) |
| 357 | 357 | ->whereYear('created_at', '=', $year) |
| 358 | 358 | ->with('team') |
@@ -66,10 +66,10 @@ discard block |
||
| 66 | 66 | // Creates data array for each player in the match |
| 67 | 67 | // |
| 68 | 68 | $matchUp = array(); |
| 69 | - foreach($groupPlayers as $key=>$groupPlayer){ |
|
| 69 | + foreach($groupPlayers as $key=>$groupPlayer) { |
|
| 70 | 70 | $matchUp[$key]['player'] = $groupPlayer->pivot->player_id; |
| 71 | 71 | $matchUp[$key]['matchHandicap'] = round($groupPlayer->pivot->handicap ,0); |
| 72 | - foreach ($groupPlayer->round as $round){ |
|
| 72 | + foreach ($groupPlayer->round as $round) { |
|
| 73 | 73 | $matchUp[$key]['team'] = $round->team_id; |
| 74 | 74 | $matchUp[$key]['course'] = $round->course_id; |
| 75 | 75 | $matchUp[$key]['holescores'] = $round->holescores; |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | // Change lowest handicap to ZERO and change others to reflect it |
| 80 | 80 | // Create array of each players handicap |
| 81 | - foreach($matchUp as $key=>$match){ |
|
| 81 | + foreach($matchUp as $key=>$match) { |
|
| 82 | 82 | $matchHandicaps[] = $match['matchHandicap']; |
| 83 | 83 | } |
| 84 | 84 | |
@@ -89,13 +89,13 @@ discard block |
||
| 89 | 89 | $handicapChange = $lowestMatchHandicap * -1; |
| 90 | 90 | |
| 91 | 91 | // Adjust all handicaps |
| 92 | - foreach($matchUp as $key=>$match){ |
|
| 92 | + foreach($matchUp as $key=>$match) { |
|
| 93 | 93 | $matchUp[$key]['matchHandicap'] = $match['matchHandicap'] + $handicapChange; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | // Separate group into two teams |
| 97 | 97 | |
| 98 | - foreach($matchUp as $key=>$item){ |
|
| 98 | + foreach($matchUp as $key=>$item) { |
|
| 99 | 99 | $teamIds[$key] = $item['team']; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -111,8 +111,8 @@ discard block |
||
| 111 | 111 | $team1 = array(); |
| 112 | 112 | $team2 = array(); |
| 113 | 113 | |
| 114 | - foreach($matchUp as $key=>$match){ |
|
| 115 | - if($match['team'] ==$team1Id ){ |
|
| 114 | + foreach($matchUp as $key=>$match) { |
|
| 115 | + if($match['team'] ==$team1Id ) { |
|
| 116 | 116 | $team1[] = $matchUp[$key]; |
| 117 | 117 | } else { |
| 118 | 118 | $team2[] = $matchUp[$key]; |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | |
| 123 | 123 | $team1Name = Team::select('name')->where('id', '=', $team1Id)->get()->toArray(); |
| 124 | - foreach($matchUp as $key=>$match){ |
|
| 125 | - if($match['team'] == $team1[0]['team']){ |
|
| 124 | + foreach($matchUp as $key=>$match) { |
|
| 125 | + if($match['team'] == $team1[0]['team']) { |
|
| 126 | 126 | $team1[] = $match; |
| 127 | 127 | unset($matchUp[$key]); |
| 128 | 128 | } |
@@ -146,16 +146,16 @@ discard block |
||
| 146 | 146 | $team1Bonus = null; |
| 147 | 147 | $team2Bonus = null; |
| 148 | 148 | |
| 149 | - if($team1Scores[8] != null && $team2Scores[8] != null){ |
|
| 150 | - if($team1Points > $team2Points){ |
|
| 149 | + if($team1Scores[8] != null && $team2Scores[8] != null) { |
|
| 150 | + if($team1Points > $team2Points) { |
|
| 151 | 151 | $team1Points = $team1Points + 1; |
| 152 | 152 | $team1Bonus = 1; |
| 153 | 153 | } |
| 154 | - if($team2Points > $team1Points){ |
|
| 154 | + if($team2Points > $team1Points) { |
|
| 155 | 155 | $team2Points = $team2Points + 1; |
| 156 | 156 | $team2Bonus = 1; |
| 157 | 157 | } |
| 158 | - if($team1Points == $team2Points){ |
|
| 158 | + if($team1Points == $team2Points) { |
|
| 159 | 159 | $team1Points = $team1Points + .5; |
| 160 | 160 | $team1Bonus = .5; |
| 161 | 161 | $team2Points = $team2Points + .5; |
@@ -171,16 +171,16 @@ discard block |
||
| 171 | 171 | //Need to determine if same amount of scores are in both |
| 172 | 172 | // If not then do not return |
| 173 | 173 | |
| 174 | - foreach($team1Scores as $key=>$teamScore){ |
|
| 175 | - if($teamScore <= 0){ |
|
| 174 | + foreach($team1Scores as $key=>$teamScore) { |
|
| 175 | + if($teamScore <= 0) { |
|
| 176 | 176 | $team1Scores[$key] = ''; |
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | $team1Net = array_sum($team1Scores); |
| 180 | 180 | |
| 181 | 181 | |
| 182 | - foreach($team2Scores as $key=>$teamScore){ |
|
| 183 | - if($teamScore <= 0){ |
|
| 182 | + foreach($team2Scores as $key=>$teamScore) { |
|
| 183 | + if($teamScore <= 0) { |
|
| 184 | 184 | $team2Scores[$key] = ''; |
| 185 | 185 | } |
| 186 | 186 | } |
@@ -225,11 +225,11 @@ discard block |
||
| 225 | 225 | |
| 226 | 226 | private function getTeamNetScore($team, $holesData) |
| 227 | 227 | { |
| 228 | - foreach($team as $key=>$item){ |
|
| 228 | + foreach($team as $key=>$item) { |
|
| 229 | 229 | // Create holes array for NET |
| 230 | 230 | $holes = array(); |
| 231 | 231 | $i = 1; |
| 232 | - foreach($holesData as $key=>$holeData){ |
|
| 232 | + foreach($holesData as $key=>$holeData) { |
|
| 233 | 233 | $holes[$i] = $holeData->handicap; |
| 234 | 234 | $i++; |
| 235 | 235 | } |
@@ -247,8 +247,8 @@ discard block |
||
| 247 | 247 | 9 => 0 |
| 248 | 248 | ]; |
| 249 | 249 | //Create array of strokes |
| 250 | - for($counter = $item['matchHandicap']; $counter > 0; $counter--){ |
|
| 251 | - if($counter > 9){ |
|
| 250 | + for($counter = $item['matchHandicap']; $counter > 0; $counter--) { |
|
| 251 | + if($counter > 9) { |
|
| 252 | 252 | $newCounter = $counter - 9; |
| 253 | 253 | while($newCounter > 0) { |
| 254 | 254 | $strokeArray[$newCounter] = $strokeArray[$newCounter] + 1; |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | // Plus handicaps don't hit previous loop so need its own |
| 262 | 262 | //Plus handicap logic |
| 263 | 263 | |
| 264 | - foreach($strokeArray as $strokeKey=>$stroke){ |
|
| 264 | + foreach($strokeArray as $strokeKey=>$stroke) { |
|
| 265 | 265 | $holeKey = array_search($strokeKey,$holes); |
| 266 | 266 | $holes[$holeKey] = $stroke; |
| 267 | 267 | } |
@@ -270,19 +270,21 @@ discard block |
||
| 270 | 270 | //get array of holescores |
| 271 | 271 | |
| 272 | 272 | $holeScores = $item['holescores']; |
| 273 | - foreach($holeScores as $key=>$holeScore){ |
|
| 273 | + foreach($holeScores as $key=>$holeScore) { |
|
| 274 | 274 | //check if new score is less PlayerScores |
| 275 | - if(isset($teamScores[$key])){ // 2nd time in for hole |
|
| 275 | + if(isset($teamScores[$key])) { |
|
| 276 | +// 2nd time in for hole |
|
| 276 | 277 | |
| 277 | 278 | //set temp handi score |
| 278 | 279 | $tempScore = $holeScore['score'] - $holes[$key+1]; |
| 279 | - if($teamScores[$key] >= $tempScore){ |
|
| 280 | + if($teamScores[$key] >= $tempScore) { |
|
| 280 | 281 | $teamScores[$key] = $holeScore['score'] - $holes[$key+1]; |
| 281 | 282 | } |
| 282 | - } else{ // first time in for hole |
|
| 283 | - if($holeScore['score'] != null){ |
|
| 283 | + } else { |
|
| 284 | +// first time in for hole |
|
| 285 | + if($holeScore['score'] != null) { |
|
| 284 | 286 | $teamScores[$key] = $holeScore['score'] - $holes[$key+1]; |
| 285 | - } else{ |
|
| 287 | + } else { |
|
| 286 | 288 | $teamScores[$key] = null; |
| 287 | 289 | } |
| 288 | 290 | } |
@@ -297,12 +299,12 @@ discard block |
||
| 297 | 299 | $points = 0; |
| 298 | 300 | $teamTotalPoints = 0; |
| 299 | 301 | $opponentTotalPoints = 0; |
| 300 | - foreach ($team as $key=>$score){ |
|
| 301 | - if($score != null){ |
|
| 302 | - if($score < $opponent[$key]){ |
|
| 302 | + foreach ($team as $key=>$score) { |
|
| 303 | + if($score != null) { |
|
| 304 | + if($score < $opponent[$key]) { |
|
| 303 | 305 | $points++; |
| 304 | 306 | } |
| 305 | - if($score == $opponent[$key]){ |
|
| 307 | + if($score == $opponent[$key]) { |
|
| 306 | 308 | $points = $points + .5; |
| 307 | 309 | } |
| 308 | 310 | } |
@@ -348,9 +350,9 @@ discard block |
||
| 348 | 350 | } |
| 349 | 351 | |
| 350 | 352 | public function getPointsByYear($year) |
| 351 | - { |
|
| 353 | + { |
|
| 352 | 354 | $teamMatches = Teammatch::select('team_id','pointsWon')->whereYear('created_at', '=', $year)->with('team')->get(); |
| 353 | - foreach($teamMatches as $key=>$teamMatch){ |
|
| 355 | + foreach($teamMatches as $key=>$teamMatch) { |
|
| 354 | 356 | $pointsData[$key]['name'] = $teamMatch['team']['name']; |
| 355 | 357 | $pointsData[$key]['points'] = Teammatch::select('team_id','pointsWon') |
| 356 | 358 | ->where('team_id', '=', $teamMatch->team_id) |
@@ -19,367 +19,367 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class MatchService |
| 21 | 21 | { |
| 22 | - // Containing our matchRepository to make all our database calls to |
|
| 23 | - protected $matchRepo; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Loads our $matchRepo |
|
| 27 | - * |
|
| 28 | - * @param MatchRepository $matchRepo |
|
| 29 | - * @return MatchService |
|
| 30 | - */ |
|
| 31 | - public function __construct(MatchRoundRepository $matchRoundRepo, |
|
| 32 | - MatchRepository $matchRepo, |
|
| 33 | - PrizeMoney $prizeMoney, |
|
| 34 | - Player $player, |
|
| 35 | - Match $match, |
|
| 36 | - CtpRepository $ctp, |
|
| 37 | - Teammatch $teammatch, |
|
| 38 | - Dispatcher $events) |
|
| 39 | - { |
|
| 40 | - $this->matchRoundRepo = $matchRoundRepo; |
|
| 41 | - $this->matchRepo = $matchRepo; |
|
| 42 | - $this->prizeMoney = $prizeMoney; |
|
| 43 | - $this->player = $player; |
|
| 44 | - $this->match = $match; |
|
| 45 | - $this->ctp = $ctp; |
|
| 46 | - $this->teammatch = $teammatch; |
|
| 47 | - $this->events = $events; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Method to create match from input Match data |
|
| 52 | - * |
|
| 53 | - * @param mixed $matchdata |
|
| 54 | - * @return |
|
| 55 | - */ |
|
| 56 | - public function create($matchdata) |
|
| 57 | - { |
|
| 58 | - $this->prizeMoney->setPurse($matchdata['purse']); |
|
| 59 | - |
|
| 60 | - $matchdata['purse'] = number_format($matchdata['purse'], 2); |
|
| 61 | - $matchdata['grossmoney'] = $this->prizeMoney->getlowScore(); |
|
| 62 | - $matchdata['netmoney'] = $this->prizeMoney->getlowScore(); |
|
| 63 | - |
|
| 64 | - //How many A and B players |
|
| 65 | - $totalPlayers = 0; |
|
| 66 | - |
|
| 67 | - $aPlayerCount = 0; |
|
| 22 | + // Containing our matchRepository to make all our database calls to |
|
| 23 | + protected $matchRepo; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Loads our $matchRepo |
|
| 27 | + * |
|
| 28 | + * @param MatchRepository $matchRepo |
|
| 29 | + * @return MatchService |
|
| 30 | + */ |
|
| 31 | + public function __construct(MatchRoundRepository $matchRoundRepo, |
|
| 32 | + MatchRepository $matchRepo, |
|
| 33 | + PrizeMoney $prizeMoney, |
|
| 34 | + Player $player, |
|
| 35 | + Match $match, |
|
| 36 | + CtpRepository $ctp, |
|
| 37 | + Teammatch $teammatch, |
|
| 38 | + Dispatcher $events) |
|
| 39 | + { |
|
| 40 | + $this->matchRoundRepo = $matchRoundRepo; |
|
| 41 | + $this->matchRepo = $matchRepo; |
|
| 42 | + $this->prizeMoney = $prizeMoney; |
|
| 43 | + $this->player = $player; |
|
| 44 | + $this->match = $match; |
|
| 45 | + $this->ctp = $ctp; |
|
| 46 | + $this->teammatch = $teammatch; |
|
| 47 | + $this->events = $events; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Method to create match from input Match data |
|
| 52 | + * |
|
| 53 | + * @param mixed $matchdata |
|
| 54 | + * @return |
|
| 55 | + */ |
|
| 56 | + public function create($matchdata) |
|
| 57 | + { |
|
| 58 | + $this->prizeMoney->setPurse($matchdata['purse']); |
|
| 59 | + |
|
| 60 | + $matchdata['purse'] = number_format($matchdata['purse'], 2); |
|
| 61 | + $matchdata['grossmoney'] = $this->prizeMoney->getlowScore(); |
|
| 62 | + $matchdata['netmoney'] = $this->prizeMoney->getlowScore(); |
|
| 63 | + |
|
| 64 | + //How many A and B players |
|
| 65 | + $totalPlayers = 0; |
|
| 66 | + |
|
| 67 | + $aPlayerCount = 0; |
|
| 68 | 68 | |
| 69 | - $bPlayerCount = 0; |
|
| 70 | - foreach($matchdata['player'] as $player){ |
|
| 71 | - if ($player['level_id'] == '1'){ |
|
| 72 | - $aPlayerCount++; |
|
| 73 | - } |
|
| 74 | - else { |
|
| 75 | - $bPlayerCount++; |
|
| 76 | - } |
|
| 77 | - $totalPlayers++; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - //Calculate Skins money based on how many players in each group |
|
| 81 | - |
|
| 82 | - $matchdata['skinsamoney'] = $this->prizeMoney->skinsGroupPot($matchdata['purse'], $totalPlayers, $aPlayerCount); |
|
| 83 | - $matchdata['skinsbmoney'] = $this->prizeMoney->skinsGroupPot($matchdata['purse'], $totalPlayers, $bPlayerCount); |
|
| 84 | - //check for carry over money and if there is add it to skins money |
|
| 85 | - $carryOver = new CarryOver; |
|
| 86 | - $carryOverMoney = $carryOver->calculate(); |
|
| 87 | - $matchdata['skinsamoney'] += $carryOverMoney[1]; |
|
| 88 | - $matchdata['skinsbmoney'] += $carryOverMoney[2]; |
|
| 89 | - |
|
| 90 | - //append current handicap and set winnings to 0 for each player |
|
| 91 | - foreach ($matchdata['player'] as $key=>$player) { |
|
| 92 | - //get each player's current handicap |
|
| 93 | - $currentPlayer = $this->player->find($player['player_id']); |
|
| 94 | - $matchdata['player'][$key]['handicap'] = $currentPlayer->handicap; |
|
| 95 | - $matchdata['player'][$key]['winnings'] = 0; |
|
| 96 | - }// End foreach |
|
| 97 | - |
|
| 98 | - $matchid = $this->matchRepo->create($matchdata); |
|
| 99 | - $matchdata['match_id'] = $matchid; |
|
| 100 | - $this->events->fire('match.create', array($matchdata)); // MatchHandler and teamMatchHandler are listening... |
|
| 101 | - |
|
| 102 | - // Run for team Matches |
|
| 103 | - if($matchdata['matchType'] === 'team' || $matchdata['matchType'] === 'both'){ |
|
| 104 | - |
|
| 105 | - foreach ($matchdata['teamMatchUp1'] as $teamKey => $team){ |
|
| 106 | - $matchUp1[] = $this->search($matchdata['player'], 'team', $team); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - //Save matchUp 1 |
|
| 110 | - $match1['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 111 | - $match1['team_id'] = $matchUp1[0][0]['team']; |
|
| 112 | - $match1['player1'] = $matchUp1[0][0]['player_id']; |
|
| 113 | - if(isset($matchUp1[0][1]['player_id'])){ |
|
| 114 | - $match1['player2'] = $matchUp1[0][1]['player_id']; |
|
| 115 | - } |
|
| 116 | - $match1['opponent'] = $matchUp1[1][0]['team']; |
|
| 117 | - $this->teammatch->create($match1); //save to match table |
|
| 118 | - |
|
| 119 | - $match1['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 120 | - $match1['team_id'] = $matchUp1[1][0]['team']; |
|
| 121 | - $match1['player1'] = $matchUp1[1][0]['player_id']; |
|
| 122 | - if(isset($matchUp1[1][1]['player_id'])){ |
|
| 123 | - $match1['player2'] = $matchUp1[1][1]['player_id']; |
|
| 124 | - } |
|
| 125 | - $match1['opponent'] = $matchUp1[0][0]['team']; |
|
| 126 | - $this->teammatch->create($match1); //save to match table |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - foreach ($matchdata['teamMatchUp2'] as $teamKey => $team){ |
|
| 130 | - $matchUp2[] = $this->search($matchdata['player'], 'team', $team); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - //Save matchUp 2 |
|
| 134 | - $match2['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 135 | - $match2['team_id'] = $matchUp2[0][0]['team']; |
|
| 136 | - $match2['player1'] = $matchUp2[0][0]['player_id']; |
|
| 137 | - if(isset($matchUp2[0][1]['player_id'])){ |
|
| 138 | - $match2['player2'] = $matchUp2[0][1]['player_id']; |
|
| 139 | - } |
|
| 140 | - $match2['opponent'] = $matchUp2[1][0]['team']; |
|
| 141 | - $this->teammatch->create($match2); //save to match table |
|
| 142 | - |
|
| 143 | - $match2['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 144 | - $match2['team_id'] = $matchUp2[1][0]['team']; |
|
| 145 | - $match2['player1'] = $matchUp2[1][0]['player_id']; |
|
| 146 | - if(isset($matchUp2[1][1]['player_id'])){ |
|
| 147 | - $match2['player2'] = $matchUp2[1][1]['player_id']; |
|
| 148 | - } |
|
| 149 | - $match2['opponent'] = $matchUp2[0][0]['team']; |
|
| 150 | - $this->teammatch->create($match2); //save to match table |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - foreach ($matchdata['teamMatchUp3'] as $teamKey => $team){ |
|
| 154 | - $matchUp3[] = $this->search($matchdata['player'], 'team', $team); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - //Save matchUp 3 |
|
| 158 | - $match3['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 159 | - $match3['team_id'] = $matchUp3[0][0]['team']; |
|
| 160 | - $match3['player1'] = $matchUp3[0][0]['player_id']; |
|
| 161 | - if(isset($matchUp3[0][1]['player_id'])){ |
|
| 162 | - $match3['player2'] = $matchUp3[0][1]['player_id']; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - $match3['opponent'] = $matchUp3[1][0]['team']; |
|
| 166 | - $this->teammatch->create($match3); //save to match table |
|
| 167 | - |
|
| 168 | - $match3['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 169 | - $match3['team_id'] = $matchUp3[1][0]['team']; |
|
| 170 | - $match3['player1'] = $matchUp3[1][0]['player_id']; |
|
| 171 | - if(isset($matchUp3[1][1]['player_id'])){ |
|
| 172 | - $match3['player2'] = $matchUp3[1][1]['player_id']; |
|
| 173 | - } |
|
| 174 | - $match3['opponent'] = $matchUp3[0][0]['team']; |
|
| 175 | - $this->teammatch->create($match3); //save to match table |
|
| 176 | - |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - public function finalize($matchdata) |
|
| 181 | - { |
|
| 182 | - // post CTP1 and CTP2 |
|
| 183 | - $ctp1 = array( |
|
| 184 | - 'match_id' => $matchdata['match'], |
|
| 185 | - 'player_id' => $matchdata['ctp1'], |
|
| 186 | - 'hole_id' => $matchdata['ctp1hole'], |
|
| 187 | - 'money' => $this->prizeMoney->getCtp() |
|
| 188 | - ); |
|
| 189 | - $this->ctp->create($ctp1); |
|
| 190 | - $ctp2 = array( |
|
| 191 | - 'match_id' => $matchdata['match'], |
|
| 192 | - 'player_id' => $matchdata['ctp2'], |
|
| 193 | - 'hole_id' => $matchdata['ctp2hole'], |
|
| 194 | - 'money' => $this->prizeMoney->getCtp() |
|
| 195 | - ); |
|
| 196 | - $this->ctp->create($ctp2); |
|
| 197 | - |
|
| 198 | - //calculate Gross winner and post to grossWinnersTable |
|
| 199 | - |
|
| 200 | - $matchRound = $this->matchRoundRepo->getByMatch($matchdata['match']); |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - $lowGross = array(); |
|
| 204 | - foreach ($matchRound as $key => $match){ |
|
| 205 | - $lowGross[$match['player']->id] = $match['score']; |
|
| 206 | - } |
|
| 207 | - $arrayLowGross = array_keys($lowGross, min($lowGross)); |
|
| 208 | - foreach($arrayLowGross as $key => $lowgrossPlayer) { |
|
| 209 | - $grossWinner = new Grosswinner; |
|
| 210 | - $grossWinner->player_id = $lowgrossPlayer; |
|
| 211 | - $grossWinner->match_id = $matchdata['match']; |
|
| 212 | - $grossWinner->score = $lowGross[$lowgrossPlayer]; |
|
| 213 | - $grossWinner->money = $this->prizeMoney->getlowScore() / count($arrayLowGross); |
|
| 214 | - $grossWinner->save(); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - //Calculate NET winner |
|
| 218 | - $lowNet = array(); |
|
| 219 | - $scores =array(); |
|
| 220 | - foreach ($matchRound as $key => $match){ |
|
| 221 | - $netScore = ($match['score'] - round($match['player']->handicap,0)); //calculate net score |
|
| 222 | - $lowNet[$match['player']->id] = $netScore; |
|
| 223 | - } |
|
| 224 | - $arrayLowNet = array_keys($lowNet, min($lowNet)); |
|
| 225 | - |
|
| 226 | - foreach($arrayLowNet as $key => $lownetPlayer) { |
|
| 227 | - $netWinner = new Netwinner; |
|
| 228 | - $netWinner->player_id = $lownetPlayer; |
|
| 229 | - $netWinner->match_id = $matchdata['match']; |
|
| 230 | - $netWinner->score = $lowNet[$lownetPlayer]; |
|
| 231 | - $netWinner->money = $this->prizeMoney->getlowScore() / count($arrayLowNet); |
|
| 232 | - $netWinner->save(); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - //Calculate Skins |
|
| 236 | - |
|
| 237 | - //determine A and B players |
|
| 238 | - //using pivot table match_player |
|
| 239 | - $match = $this->match->find($matchdata['match']); |
|
| 240 | - $aPlayers = array(); |
|
| 241 | - $bPlayers = array(); |
|
| 242 | - foreach($match->players as $player) |
|
| 243 | - { |
|
| 244 | - if($player->pivot->level_id == 1){ |
|
| 245 | - $aPlayers[] = $player->pivot->player_id; |
|
| 246 | - |
|
| 247 | - } |
|
| 248 | - if($player->pivot->level_id == 2){ |
|
| 249 | - $bPlayers[] = $player->pivot->player_id; |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - //Create Skins arrays |
|
| 254 | - //player_id, 'holescores' |
|
| 255 | - foreach($matchRound as $key => $round) { |
|
| 256 | - if (in_array($round->player_id,$aPlayers)){ |
|
| 257 | - $aPlayersSkins[$key]['player_id'] = $round->player_id; |
|
| 258 | - $aPlayersSkins[$key]['holescores'] = $round->holescores; |
|
| 259 | - } |
|
| 260 | - if (in_array($round->player_id,$bPlayers)){ |
|
| 261 | - $bPlayersSkins[$key]['player_id'] = $round->player_id; |
|
| 262 | - $bPlayersSkins[$key]['holescores'] = $round->holescores; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - //Run A Skins analysis |
|
| 267 | - $scores = array(); |
|
| 268 | - foreach($aPlayersSkins as $key => $playerSkin){ |
|
| 269 | - foreach($playerSkin['holescores'] as $hole => $holescore){ |
|
| 270 | - $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score']; |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - foreach($scores as $hole_id => $hole) { |
|
| 275 | - $minScore = min($hole); |
|
| 276 | - $winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score |
|
| 277 | - } |
|
| 278 | - $aSkinsWon = 0; |
|
| 279 | - foreach($winners as $key => $winner) { |
|
| 280 | - if(count($winner) === 1) { |
|
| 281 | - //post to DB |
|
| 282 | - $skinWinner = new Skin; |
|
| 283 | - $skinWinner->player_id = $winner[0]; |
|
| 284 | - $skinWinner->level_id = 1; |
|
| 285 | - $skinWinner->match_id = intval($matchdata['match']); |
|
| 286 | - $skinWinner->hole_id = $key; |
|
| 287 | - $skinWinner->save(); |
|
| 288 | - $aSkinsWon++; |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - //Run B Skins analysis |
|
| 293 | - $scores = array(); |
|
| 294 | - foreach($bPlayersSkins as $key => $playerSkin){ |
|
| 295 | - foreach($playerSkin['holescores'] as $hole => $holescore){ |
|
| 296 | - $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score']; |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - foreach($scores as $hole_id => $hole) { |
|
| 301 | - $minScore = min($hole); |
|
| 302 | - $winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score |
|
| 303 | - } |
|
| 304 | - $bSkinsWon = 0; |
|
| 305 | - foreach($winners as $key => $winner) { |
|
| 306 | - if(count($winner) === 1) { |
|
| 307 | - //post to DB |
|
| 308 | - $skinWinner = new Skin; |
|
| 309 | - $skinWinner->player_id = $winner[0]; |
|
| 310 | - $skinWinner->level_id = 2; |
|
| 311 | - $skinWinner->match_id = intval($matchdata['match']); |
|
| 312 | - $skinWinner->hole_id = $key; |
|
| 313 | - $skinWinner->save(); |
|
| 314 | - $bSkinsWon++; |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - $match = Match::find($matchdata['match']); |
|
| 319 | - |
|
| 320 | - //Need to add Carry over money if there no skins are won |
|
| 321 | - //check for carry over money |
|
| 322 | - $skinsamoney = $match->skinsamoney; // + carryover A money if any |
|
| 323 | - $skinsbmoney = $match->skinsbmoney; // + carryover B money if any |
|
| 324 | - |
|
| 325 | - if($aSkinsWon > 0) { |
|
| 326 | - $moneyperskinA = $skinsamoney / $aSkinsWon; |
|
| 327 | - |
|
| 328 | - $aSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 1)->get(); |
|
| 329 | - foreach ($aSkins as $askin){ |
|
| 330 | - $askin->money = $moneyperskinA; |
|
| 331 | - $askin->save(); |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - if($bSkinsWon > 0) { |
|
| 336 | - $moneyperskinB = $skinsbmoney / $bSkinsWon; |
|
| 337 | - |
|
| 338 | - $bSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 2)->get(); |
|
| 339 | - foreach ($bSkins as $bskin){ |
|
| 340 | - $bskin->money = $moneyperskinB; |
|
| 341 | - $bskin->save(); |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - //foreach player in pivot table create player and run handicap analysis |
|
| 345 | - foreach($match->players as $matchplayer) |
|
| 346 | - { |
|
| 347 | - $player = Player::find($matchplayer->pivot->player_id); |
|
| 348 | - $handicap = new Handicap($player); |
|
| 349 | - $player->handicap = $handicap->calculate(); |
|
| 350 | - $player->save(); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - //Fire event to calculate money won and add to pivot table match_player |
|
| 354 | - $this->events->fire('match.finalize', $match); |
|
| 355 | - |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * Method to get match from input Match data |
|
| 360 | - * |
|
| 361 | - * @param mixed $matchdata |
|
| 362 | - * @return JSON object |
|
| 363 | - */ |
|
| 364 | - public function get($matchid) |
|
| 365 | - { |
|
| 366 | - $matchdata = $this->matchRepo->get($matchid); |
|
| 367 | - return $matchdata; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - private function search($array, $key, $value) |
|
| 373 | - { |
|
| 374 | - $results = array(); |
|
| 375 | - if (is_array($array)) { |
|
| 376 | - if (isset($array[$key]) && $array[$key] == $value) { |
|
| 377 | - $results[] = $array; |
|
| 378 | - } |
|
| 379 | - foreach ($array as $subarray) { |
|
| 380 | - $results = array_merge($results, $this->search($subarray, $key, $value)); |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - return $results; |
|
| 384 | - } |
|
| 69 | + $bPlayerCount = 0; |
|
| 70 | + foreach($matchdata['player'] as $player){ |
|
| 71 | + if ($player['level_id'] == '1'){ |
|
| 72 | + $aPlayerCount++; |
|
| 73 | + } |
|
| 74 | + else { |
|
| 75 | + $bPlayerCount++; |
|
| 76 | + } |
|
| 77 | + $totalPlayers++; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + //Calculate Skins money based on how many players in each group |
|
| 81 | + |
|
| 82 | + $matchdata['skinsamoney'] = $this->prizeMoney->skinsGroupPot($matchdata['purse'], $totalPlayers, $aPlayerCount); |
|
| 83 | + $matchdata['skinsbmoney'] = $this->prizeMoney->skinsGroupPot($matchdata['purse'], $totalPlayers, $bPlayerCount); |
|
| 84 | + //check for carry over money and if there is add it to skins money |
|
| 85 | + $carryOver = new CarryOver; |
|
| 86 | + $carryOverMoney = $carryOver->calculate(); |
|
| 87 | + $matchdata['skinsamoney'] += $carryOverMoney[1]; |
|
| 88 | + $matchdata['skinsbmoney'] += $carryOverMoney[2]; |
|
| 89 | + |
|
| 90 | + //append current handicap and set winnings to 0 for each player |
|
| 91 | + foreach ($matchdata['player'] as $key=>$player) { |
|
| 92 | + //get each player's current handicap |
|
| 93 | + $currentPlayer = $this->player->find($player['player_id']); |
|
| 94 | + $matchdata['player'][$key]['handicap'] = $currentPlayer->handicap; |
|
| 95 | + $matchdata['player'][$key]['winnings'] = 0; |
|
| 96 | + }// End foreach |
|
| 97 | + |
|
| 98 | + $matchid = $this->matchRepo->create($matchdata); |
|
| 99 | + $matchdata['match_id'] = $matchid; |
|
| 100 | + $this->events->fire('match.create', array($matchdata)); // MatchHandler and teamMatchHandler are listening... |
|
| 101 | + |
|
| 102 | + // Run for team Matches |
|
| 103 | + if($matchdata['matchType'] === 'team' || $matchdata['matchType'] === 'both'){ |
|
| 104 | + |
|
| 105 | + foreach ($matchdata['teamMatchUp1'] as $teamKey => $team){ |
|
| 106 | + $matchUp1[] = $this->search($matchdata['player'], 'team', $team); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + //Save matchUp 1 |
|
| 110 | + $match1['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 111 | + $match1['team_id'] = $matchUp1[0][0]['team']; |
|
| 112 | + $match1['player1'] = $matchUp1[0][0]['player_id']; |
|
| 113 | + if(isset($matchUp1[0][1]['player_id'])){ |
|
| 114 | + $match1['player2'] = $matchUp1[0][1]['player_id']; |
|
| 115 | + } |
|
| 116 | + $match1['opponent'] = $matchUp1[1][0]['team']; |
|
| 117 | + $this->teammatch->create($match1); //save to match table |
|
| 118 | + |
|
| 119 | + $match1['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 120 | + $match1['team_id'] = $matchUp1[1][0]['team']; |
|
| 121 | + $match1['player1'] = $matchUp1[1][0]['player_id']; |
|
| 122 | + if(isset($matchUp1[1][1]['player_id'])){ |
|
| 123 | + $match1['player2'] = $matchUp1[1][1]['player_id']; |
|
| 124 | + } |
|
| 125 | + $match1['opponent'] = $matchUp1[0][0]['team']; |
|
| 126 | + $this->teammatch->create($match1); //save to match table |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + foreach ($matchdata['teamMatchUp2'] as $teamKey => $team){ |
|
| 130 | + $matchUp2[] = $this->search($matchdata['player'], 'team', $team); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + //Save matchUp 2 |
|
| 134 | + $match2['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 135 | + $match2['team_id'] = $matchUp2[0][0]['team']; |
|
| 136 | + $match2['player1'] = $matchUp2[0][0]['player_id']; |
|
| 137 | + if(isset($matchUp2[0][1]['player_id'])){ |
|
| 138 | + $match2['player2'] = $matchUp2[0][1]['player_id']; |
|
| 139 | + } |
|
| 140 | + $match2['opponent'] = $matchUp2[1][0]['team']; |
|
| 141 | + $this->teammatch->create($match2); //save to match table |
|
| 142 | + |
|
| 143 | + $match2['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 144 | + $match2['team_id'] = $matchUp2[1][0]['team']; |
|
| 145 | + $match2['player1'] = $matchUp2[1][0]['player_id']; |
|
| 146 | + if(isset($matchUp2[1][1]['player_id'])){ |
|
| 147 | + $match2['player2'] = $matchUp2[1][1]['player_id']; |
|
| 148 | + } |
|
| 149 | + $match2['opponent'] = $matchUp2[0][0]['team']; |
|
| 150 | + $this->teammatch->create($match2); //save to match table |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + foreach ($matchdata['teamMatchUp3'] as $teamKey => $team){ |
|
| 154 | + $matchUp3[] = $this->search($matchdata['player'], 'team', $team); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + //Save matchUp 3 |
|
| 158 | + $match3['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 159 | + $match3['team_id'] = $matchUp3[0][0]['team']; |
|
| 160 | + $match3['player1'] = $matchUp3[0][0]['player_id']; |
|
| 161 | + if(isset($matchUp3[0][1]['player_id'])){ |
|
| 162 | + $match3['player2'] = $matchUp3[0][1]['player_id']; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + $match3['opponent'] = $matchUp3[1][0]['team']; |
|
| 166 | + $this->teammatch->create($match3); //save to match table |
|
| 167 | + |
|
| 168 | + $match3['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 169 | + $match3['team_id'] = $matchUp3[1][0]['team']; |
|
| 170 | + $match3['player1'] = $matchUp3[1][0]['player_id']; |
|
| 171 | + if(isset($matchUp3[1][1]['player_id'])){ |
|
| 172 | + $match3['player2'] = $matchUp3[1][1]['player_id']; |
|
| 173 | + } |
|
| 174 | + $match3['opponent'] = $matchUp3[0][0]['team']; |
|
| 175 | + $this->teammatch->create($match3); //save to match table |
|
| 176 | + |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + public function finalize($matchdata) |
|
| 181 | + { |
|
| 182 | + // post CTP1 and CTP2 |
|
| 183 | + $ctp1 = array( |
|
| 184 | + 'match_id' => $matchdata['match'], |
|
| 185 | + 'player_id' => $matchdata['ctp1'], |
|
| 186 | + 'hole_id' => $matchdata['ctp1hole'], |
|
| 187 | + 'money' => $this->prizeMoney->getCtp() |
|
| 188 | + ); |
|
| 189 | + $this->ctp->create($ctp1); |
|
| 190 | + $ctp2 = array( |
|
| 191 | + 'match_id' => $matchdata['match'], |
|
| 192 | + 'player_id' => $matchdata['ctp2'], |
|
| 193 | + 'hole_id' => $matchdata['ctp2hole'], |
|
| 194 | + 'money' => $this->prizeMoney->getCtp() |
|
| 195 | + ); |
|
| 196 | + $this->ctp->create($ctp2); |
|
| 197 | + |
|
| 198 | + //calculate Gross winner and post to grossWinnersTable |
|
| 199 | + |
|
| 200 | + $matchRound = $this->matchRoundRepo->getByMatch($matchdata['match']); |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + $lowGross = array(); |
|
| 204 | + foreach ($matchRound as $key => $match){ |
|
| 205 | + $lowGross[$match['player']->id] = $match['score']; |
|
| 206 | + } |
|
| 207 | + $arrayLowGross = array_keys($lowGross, min($lowGross)); |
|
| 208 | + foreach($arrayLowGross as $key => $lowgrossPlayer) { |
|
| 209 | + $grossWinner = new Grosswinner; |
|
| 210 | + $grossWinner->player_id = $lowgrossPlayer; |
|
| 211 | + $grossWinner->match_id = $matchdata['match']; |
|
| 212 | + $grossWinner->score = $lowGross[$lowgrossPlayer]; |
|
| 213 | + $grossWinner->money = $this->prizeMoney->getlowScore() / count($arrayLowGross); |
|
| 214 | + $grossWinner->save(); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + //Calculate NET winner |
|
| 218 | + $lowNet = array(); |
|
| 219 | + $scores =array(); |
|
| 220 | + foreach ($matchRound as $key => $match){ |
|
| 221 | + $netScore = ($match['score'] - round($match['player']->handicap,0)); //calculate net score |
|
| 222 | + $lowNet[$match['player']->id] = $netScore; |
|
| 223 | + } |
|
| 224 | + $arrayLowNet = array_keys($lowNet, min($lowNet)); |
|
| 225 | + |
|
| 226 | + foreach($arrayLowNet as $key => $lownetPlayer) { |
|
| 227 | + $netWinner = new Netwinner; |
|
| 228 | + $netWinner->player_id = $lownetPlayer; |
|
| 229 | + $netWinner->match_id = $matchdata['match']; |
|
| 230 | + $netWinner->score = $lowNet[$lownetPlayer]; |
|
| 231 | + $netWinner->money = $this->prizeMoney->getlowScore() / count($arrayLowNet); |
|
| 232 | + $netWinner->save(); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + //Calculate Skins |
|
| 236 | + |
|
| 237 | + //determine A and B players |
|
| 238 | + //using pivot table match_player |
|
| 239 | + $match = $this->match->find($matchdata['match']); |
|
| 240 | + $aPlayers = array(); |
|
| 241 | + $bPlayers = array(); |
|
| 242 | + foreach($match->players as $player) |
|
| 243 | + { |
|
| 244 | + if($player->pivot->level_id == 1){ |
|
| 245 | + $aPlayers[] = $player->pivot->player_id; |
|
| 246 | + |
|
| 247 | + } |
|
| 248 | + if($player->pivot->level_id == 2){ |
|
| 249 | + $bPlayers[] = $player->pivot->player_id; |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + //Create Skins arrays |
|
| 254 | + //player_id, 'holescores' |
|
| 255 | + foreach($matchRound as $key => $round) { |
|
| 256 | + if (in_array($round->player_id,$aPlayers)){ |
|
| 257 | + $aPlayersSkins[$key]['player_id'] = $round->player_id; |
|
| 258 | + $aPlayersSkins[$key]['holescores'] = $round->holescores; |
|
| 259 | + } |
|
| 260 | + if (in_array($round->player_id,$bPlayers)){ |
|
| 261 | + $bPlayersSkins[$key]['player_id'] = $round->player_id; |
|
| 262 | + $bPlayersSkins[$key]['holescores'] = $round->holescores; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + //Run A Skins analysis |
|
| 267 | + $scores = array(); |
|
| 268 | + foreach($aPlayersSkins as $key => $playerSkin){ |
|
| 269 | + foreach($playerSkin['holescores'] as $hole => $holescore){ |
|
| 270 | + $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score']; |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + foreach($scores as $hole_id => $hole) { |
|
| 275 | + $minScore = min($hole); |
|
| 276 | + $winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score |
|
| 277 | + } |
|
| 278 | + $aSkinsWon = 0; |
|
| 279 | + foreach($winners as $key => $winner) { |
|
| 280 | + if(count($winner) === 1) { |
|
| 281 | + //post to DB |
|
| 282 | + $skinWinner = new Skin; |
|
| 283 | + $skinWinner->player_id = $winner[0]; |
|
| 284 | + $skinWinner->level_id = 1; |
|
| 285 | + $skinWinner->match_id = intval($matchdata['match']); |
|
| 286 | + $skinWinner->hole_id = $key; |
|
| 287 | + $skinWinner->save(); |
|
| 288 | + $aSkinsWon++; |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + //Run B Skins analysis |
|
| 293 | + $scores = array(); |
|
| 294 | + foreach($bPlayersSkins as $key => $playerSkin){ |
|
| 295 | + foreach($playerSkin['holescores'] as $hole => $holescore){ |
|
| 296 | + $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score']; |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + foreach($scores as $hole_id => $hole) { |
|
| 301 | + $minScore = min($hole); |
|
| 302 | + $winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score |
|
| 303 | + } |
|
| 304 | + $bSkinsWon = 0; |
|
| 305 | + foreach($winners as $key => $winner) { |
|
| 306 | + if(count($winner) === 1) { |
|
| 307 | + //post to DB |
|
| 308 | + $skinWinner = new Skin; |
|
| 309 | + $skinWinner->player_id = $winner[0]; |
|
| 310 | + $skinWinner->level_id = 2; |
|
| 311 | + $skinWinner->match_id = intval($matchdata['match']); |
|
| 312 | + $skinWinner->hole_id = $key; |
|
| 313 | + $skinWinner->save(); |
|
| 314 | + $bSkinsWon++; |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + $match = Match::find($matchdata['match']); |
|
| 319 | + |
|
| 320 | + //Need to add Carry over money if there no skins are won |
|
| 321 | + //check for carry over money |
|
| 322 | + $skinsamoney = $match->skinsamoney; // + carryover A money if any |
|
| 323 | + $skinsbmoney = $match->skinsbmoney; // + carryover B money if any |
|
| 324 | + |
|
| 325 | + if($aSkinsWon > 0) { |
|
| 326 | + $moneyperskinA = $skinsamoney / $aSkinsWon; |
|
| 327 | + |
|
| 328 | + $aSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 1)->get(); |
|
| 329 | + foreach ($aSkins as $askin){ |
|
| 330 | + $askin->money = $moneyperskinA; |
|
| 331 | + $askin->save(); |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + if($bSkinsWon > 0) { |
|
| 336 | + $moneyperskinB = $skinsbmoney / $bSkinsWon; |
|
| 337 | + |
|
| 338 | + $bSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 2)->get(); |
|
| 339 | + foreach ($bSkins as $bskin){ |
|
| 340 | + $bskin->money = $moneyperskinB; |
|
| 341 | + $bskin->save(); |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + //foreach player in pivot table create player and run handicap analysis |
|
| 345 | + foreach($match->players as $matchplayer) |
|
| 346 | + { |
|
| 347 | + $player = Player::find($matchplayer->pivot->player_id); |
|
| 348 | + $handicap = new Handicap($player); |
|
| 349 | + $player->handicap = $handicap->calculate(); |
|
| 350 | + $player->save(); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + //Fire event to calculate money won and add to pivot table match_player |
|
| 354 | + $this->events->fire('match.finalize', $match); |
|
| 355 | + |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * Method to get match from input Match data |
|
| 360 | + * |
|
| 361 | + * @param mixed $matchdata |
|
| 362 | + * @return JSON object |
|
| 363 | + */ |
|
| 364 | + public function get($matchid) |
|
| 365 | + { |
|
| 366 | + $matchdata = $this->matchRepo->get($matchid); |
|
| 367 | + return $matchdata; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + private function search($array, $key, $value) |
|
| 373 | + { |
|
| 374 | + $results = array(); |
|
| 375 | + if (is_array($array)) { |
|
| 376 | + if (isset($array[$key]) && $array[$key] == $value) { |
|
| 377 | + $results[] = $array; |
|
| 378 | + } |
|
| 379 | + foreach ($array as $subarray) { |
|
| 380 | + $results = array_merge($results, $this->search($subarray, $key, $value)); |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + return $results; |
|
| 384 | + } |
|
| 385 | 385 | } |
@@ -67,8 +67,8 @@ discard block |
||
| 67 | 67 | $aPlayerCount = 0; |
| 68 | 68 | |
| 69 | 69 | $bPlayerCount = 0; |
| 70 | - foreach($matchdata['player'] as $player){ |
|
| 71 | - if ($player['level_id'] == '1'){ |
|
| 70 | + foreach ($matchdata['player'] as $player) { |
|
| 71 | + if ($player['level_id'] == '1') { |
|
| 72 | 72 | $aPlayerCount++; |
| 73 | 73 | } |
| 74 | 74 | else { |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | //check for carry over money and if there is add it to skins money |
| 85 | 85 | $carryOver = new CarryOver; |
| 86 | 86 | $carryOverMoney = $carryOver->calculate(); |
| 87 | - $matchdata['skinsamoney'] += $carryOverMoney[1]; |
|
| 88 | - $matchdata['skinsbmoney'] += $carryOverMoney[2]; |
|
| 87 | + $matchdata['skinsamoney'] += $carryOverMoney[1]; |
|
| 88 | + $matchdata['skinsbmoney'] += $carryOverMoney[2]; |
|
| 89 | 89 | |
| 90 | 90 | //append current handicap and set winnings to 0 for each player |
| 91 | 91 | foreach ($matchdata['player'] as $key=>$player) { |
@@ -97,78 +97,78 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | $matchid = $this->matchRepo->create($matchdata); |
| 99 | 99 | $matchdata['match_id'] = $matchid; |
| 100 | - $this->events->fire('match.create', array($matchdata)); // MatchHandler and teamMatchHandler are listening... |
|
| 100 | + $this->events->fire('match.create', array($matchdata)); // MatchHandler and teamMatchHandler are listening... |
|
| 101 | 101 | |
| 102 | 102 | // Run for team Matches |
| 103 | - if($matchdata['matchType'] === 'team' || $matchdata['matchType'] === 'both'){ |
|
| 103 | + if ($matchdata['matchType'] === 'team' || $matchdata['matchType'] === 'both') { |
|
| 104 | 104 | |
| 105 | - foreach ($matchdata['teamMatchUp1'] as $teamKey => $team){ |
|
| 105 | + foreach ($matchdata['teamMatchUp1'] as $teamKey => $team) { |
|
| 106 | 106 | $matchUp1[] = $this->search($matchdata['player'], 'team', $team); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | //Save matchUp 1 |
| 110 | - $match1['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 110 | + $match1['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 111 | 111 | $match1['team_id'] = $matchUp1[0][0]['team']; |
| 112 | 112 | $match1['player1'] = $matchUp1[0][0]['player_id']; |
| 113 | - if(isset($matchUp1[0][1]['player_id'])){ |
|
| 113 | + if (isset($matchUp1[0][1]['player_id'])) { |
|
| 114 | 114 | $match1['player2'] = $matchUp1[0][1]['player_id']; |
| 115 | 115 | } |
| 116 | 116 | $match1['opponent'] = $matchUp1[1][0]['team']; |
| 117 | 117 | $this->teammatch->create($match1); //save to match table |
| 118 | 118 | |
| 119 | - $match1['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 119 | + $match1['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 120 | 120 | $match1['team_id'] = $matchUp1[1][0]['team']; |
| 121 | 121 | $match1['player1'] = $matchUp1[1][0]['player_id']; |
| 122 | - if(isset($matchUp1[1][1]['player_id'])){ |
|
| 122 | + if (isset($matchUp1[1][1]['player_id'])) { |
|
| 123 | 123 | $match1['player2'] = $matchUp1[1][1]['player_id']; |
| 124 | 124 | } |
| 125 | 125 | $match1['opponent'] = $matchUp1[0][0]['team']; |
| 126 | 126 | $this->teammatch->create($match1); //save to match table |
| 127 | 127 | |
| 128 | 128 | |
| 129 | - foreach ($matchdata['teamMatchUp2'] as $teamKey => $team){ |
|
| 129 | + foreach ($matchdata['teamMatchUp2'] as $teamKey => $team) { |
|
| 130 | 130 | $matchUp2[] = $this->search($matchdata['player'], 'team', $team); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | //Save matchUp 2 |
| 134 | - $match2['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 134 | + $match2['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 135 | 135 | $match2['team_id'] = $matchUp2[0][0]['team']; |
| 136 | 136 | $match2['player1'] = $matchUp2[0][0]['player_id']; |
| 137 | - if(isset($matchUp2[0][1]['player_id'])){ |
|
| 137 | + if (isset($matchUp2[0][1]['player_id'])) { |
|
| 138 | 138 | $match2['player2'] = $matchUp2[0][1]['player_id']; |
| 139 | 139 | } |
| 140 | 140 | $match2['opponent'] = $matchUp2[1][0]['team']; |
| 141 | 141 | $this->teammatch->create($match2); //save to match table |
| 142 | 142 | |
| 143 | - $match2['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 143 | + $match2['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 144 | 144 | $match2['team_id'] = $matchUp2[1][0]['team']; |
| 145 | 145 | $match2['player1'] = $matchUp2[1][0]['player_id']; |
| 146 | - if(isset($matchUp2[1][1]['player_id'])){ |
|
| 146 | + if (isset($matchUp2[1][1]['player_id'])) { |
|
| 147 | 147 | $match2['player2'] = $matchUp2[1][1]['player_id']; |
| 148 | 148 | } |
| 149 | 149 | $match2['opponent'] = $matchUp2[0][0]['team']; |
| 150 | 150 | $this->teammatch->create($match2); //save to match table |
| 151 | 151 | |
| 152 | 152 | |
| 153 | - foreach ($matchdata['teamMatchUp3'] as $teamKey => $team){ |
|
| 153 | + foreach ($matchdata['teamMatchUp3'] as $teamKey => $team) { |
|
| 154 | 154 | $matchUp3[] = $this->search($matchdata['player'], 'team', $team); |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | //Save matchUp 3 |
| 158 | - $match3['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 158 | + $match3['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 159 | 159 | $match3['team_id'] = $matchUp3[0][0]['team']; |
| 160 | 160 | $match3['player1'] = $matchUp3[0][0]['player_id']; |
| 161 | - if(isset($matchUp3[0][1]['player_id'])){ |
|
| 161 | + if (isset($matchUp3[0][1]['player_id'])) { |
|
| 162 | 162 | $match3['player2'] = $matchUp3[0][1]['player_id']; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | $match3['opponent'] = $matchUp3[1][0]['team']; |
| 166 | 166 | $this->teammatch->create($match3); //save to match table |
| 167 | 167 | |
| 168 | - $match3['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 168 | + $match3['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
|
| 169 | 169 | $match3['team_id'] = $matchUp3[1][0]['team']; |
| 170 | 170 | $match3['player1'] = $matchUp3[1][0]['player_id']; |
| 171 | - if(isset($matchUp3[1][1]['player_id'])){ |
|
| 171 | + if (isset($matchUp3[1][1]['player_id'])) { |
|
| 172 | 172 | $match3['player2'] = $matchUp3[1][1]['player_id']; |
| 173 | 173 | } |
| 174 | 174 | $match3['opponent'] = $matchUp3[0][0]['team']; |
@@ -201,11 +201,11 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | |
| 203 | 203 | $lowGross = array(); |
| 204 | - foreach ($matchRound as $key => $match){ |
|
| 204 | + foreach ($matchRound as $key => $match) { |
|
| 205 | 205 | $lowGross[$match['player']->id] = $match['score']; |
| 206 | 206 | } |
| 207 | 207 | $arrayLowGross = array_keys($lowGross, min($lowGross)); |
| 208 | - foreach($arrayLowGross as $key => $lowgrossPlayer) { |
|
| 208 | + foreach ($arrayLowGross as $key => $lowgrossPlayer) { |
|
| 209 | 209 | $grossWinner = new Grosswinner; |
| 210 | 210 | $grossWinner->player_id = $lowgrossPlayer; |
| 211 | 211 | $grossWinner->match_id = $matchdata['match']; |
@@ -216,19 +216,19 @@ discard block |
||
| 216 | 216 | |
| 217 | 217 | //Calculate NET winner |
| 218 | 218 | $lowNet = array(); |
| 219 | - $scores =array(); |
|
| 220 | - foreach ($matchRound as $key => $match){ |
|
| 221 | - $netScore = ($match['score'] - round($match['player']->handicap,0)); //calculate net score |
|
| 219 | + $scores = array(); |
|
| 220 | + foreach ($matchRound as $key => $match) { |
|
| 221 | + $netScore = ($match['score'] - round($match['player']->handicap, 0)); //calculate net score |
|
| 222 | 222 | $lowNet[$match['player']->id] = $netScore; |
| 223 | 223 | } |
| 224 | 224 | $arrayLowNet = array_keys($lowNet, min($lowNet)); |
| 225 | 225 | |
| 226 | - foreach($arrayLowNet as $key => $lownetPlayer) { |
|
| 226 | + foreach ($arrayLowNet as $key => $lownetPlayer) { |
|
| 227 | 227 | $netWinner = new Netwinner; |
| 228 | 228 | $netWinner->player_id = $lownetPlayer; |
| 229 | 229 | $netWinner->match_id = $matchdata['match']; |
| 230 | 230 | $netWinner->score = $lowNet[$lownetPlayer]; |
| 231 | - $netWinner->money = $this->prizeMoney->getlowScore() / count($arrayLowNet); |
|
| 231 | + $netWinner->money = $this->prizeMoney->getlowScore() / count($arrayLowNet); |
|
| 232 | 232 | $netWinner->save(); |
| 233 | 233 | } |
| 234 | 234 | |
@@ -239,25 +239,25 @@ discard block |
||
| 239 | 239 | $match = $this->match->find($matchdata['match']); |
| 240 | 240 | $aPlayers = array(); |
| 241 | 241 | $bPlayers = array(); |
| 242 | - foreach($match->players as $player) |
|
| 242 | + foreach ($match->players as $player) |
|
| 243 | 243 | { |
| 244 | - if($player->pivot->level_id == 1){ |
|
| 244 | + if ($player->pivot->level_id == 1) { |
|
| 245 | 245 | $aPlayers[] = $player->pivot->player_id; |
| 246 | 246 | |
| 247 | 247 | } |
| 248 | - if($player->pivot->level_id == 2){ |
|
| 248 | + if ($player->pivot->level_id == 2) { |
|
| 249 | 249 | $bPlayers[] = $player->pivot->player_id; |
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | //Create Skins arrays |
| 254 | 254 | //player_id, 'holescores' |
| 255 | - foreach($matchRound as $key => $round) { |
|
| 256 | - if (in_array($round->player_id,$aPlayers)){ |
|
| 255 | + foreach ($matchRound as $key => $round) { |
|
| 256 | + if (in_array($round->player_id, $aPlayers)) { |
|
| 257 | 257 | $aPlayersSkins[$key]['player_id'] = $round->player_id; |
| 258 | 258 | $aPlayersSkins[$key]['holescores'] = $round->holescores; |
| 259 | 259 | } |
| 260 | - if (in_array($round->player_id,$bPlayers)){ |
|
| 260 | + if (in_array($round->player_id, $bPlayers)) { |
|
| 261 | 261 | $bPlayersSkins[$key]['player_id'] = $round->player_id; |
| 262 | 262 | $bPlayersSkins[$key]['holescores'] = $round->holescores; |
| 263 | 263 | } |
@@ -265,19 +265,19 @@ discard block |
||
| 265 | 265 | |
| 266 | 266 | //Run A Skins analysis |
| 267 | 267 | $scores = array(); |
| 268 | - foreach($aPlayersSkins as $key => $playerSkin){ |
|
| 269 | - foreach($playerSkin['holescores'] as $hole => $holescore){ |
|
| 268 | + foreach ($aPlayersSkins as $key => $playerSkin) { |
|
| 269 | + foreach ($playerSkin['holescores'] as $hole => $holescore) { |
|
| 270 | 270 | $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score']; |
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - foreach($scores as $hole_id => $hole) { |
|
| 274 | + foreach ($scores as $hole_id => $hole) { |
|
| 275 | 275 | $minScore = min($hole); |
| 276 | 276 | $winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score |
| 277 | 277 | } |
| 278 | 278 | $aSkinsWon = 0; |
| 279 | - foreach($winners as $key => $winner) { |
|
| 280 | - if(count($winner) === 1) { |
|
| 279 | + foreach ($winners as $key => $winner) { |
|
| 280 | + if (count($winner) === 1) { |
|
| 281 | 281 | //post to DB |
| 282 | 282 | $skinWinner = new Skin; |
| 283 | 283 | $skinWinner->player_id = $winner[0]; |
@@ -291,19 +291,19 @@ discard block |
||
| 291 | 291 | |
| 292 | 292 | //Run B Skins analysis |
| 293 | 293 | $scores = array(); |
| 294 | - foreach($bPlayersSkins as $key => $playerSkin){ |
|
| 295 | - foreach($playerSkin['holescores'] as $hole => $holescore){ |
|
| 294 | + foreach ($bPlayersSkins as $key => $playerSkin) { |
|
| 295 | + foreach ($playerSkin['holescores'] as $hole => $holescore) { |
|
| 296 | 296 | $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score']; |
| 297 | 297 | } |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - foreach($scores as $hole_id => $hole) { |
|
| 300 | + foreach ($scores as $hole_id => $hole) { |
|
| 301 | 301 | $minScore = min($hole); |
| 302 | 302 | $winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score |
| 303 | 303 | } |
| 304 | 304 | $bSkinsWon = 0; |
| 305 | - foreach($winners as $key => $winner) { |
|
| 306 | - if(count($winner) === 1) { |
|
| 305 | + foreach ($winners as $key => $winner) { |
|
| 306 | + if (count($winner) === 1) { |
|
| 307 | 307 | //post to DB |
| 308 | 308 | $skinWinner = new Skin; |
| 309 | 309 | $skinWinner->player_id = $winner[0]; |
@@ -315,34 +315,34 @@ discard block |
||
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - $match = Match::find($matchdata['match']); |
|
| 318 | + $match = Match::find($matchdata['match']); |
|
| 319 | 319 | |
| 320 | 320 | //Need to add Carry over money if there no skins are won |
| 321 | 321 | //check for carry over money |
| 322 | 322 | $skinsamoney = $match->skinsamoney; // + carryover A money if any |
| 323 | 323 | $skinsbmoney = $match->skinsbmoney; // + carryover B money if any |
| 324 | 324 | |
| 325 | - if($aSkinsWon > 0) { |
|
| 325 | + if ($aSkinsWon > 0) { |
|
| 326 | 326 | $moneyperskinA = $skinsamoney / $aSkinsWon; |
| 327 | 327 | |
| 328 | 328 | $aSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 1)->get(); |
| 329 | - foreach ($aSkins as $askin){ |
|
| 329 | + foreach ($aSkins as $askin) { |
|
| 330 | 330 | $askin->money = $moneyperskinA; |
| 331 | 331 | $askin->save(); |
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - if($bSkinsWon > 0) { |
|
| 335 | + if ($bSkinsWon > 0) { |
|
| 336 | 336 | $moneyperskinB = $skinsbmoney / $bSkinsWon; |
| 337 | 337 | |
| 338 | 338 | $bSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 2)->get(); |
| 339 | - foreach ($bSkins as $bskin){ |
|
| 339 | + foreach ($bSkins as $bskin) { |
|
| 340 | 340 | $bskin->money = $moneyperskinB; |
| 341 | 341 | $bskin->save(); |
| 342 | 342 | } |
| 343 | 343 | } |
| 344 | 344 | //foreach player in pivot table create player and run handicap analysis |
| 345 | - foreach($match->players as $matchplayer) |
|
| 345 | + foreach ($match->players as $matchplayer) |
|
| 346 | 346 | { |
| 347 | 347 | $player = Player::find($matchplayer->pivot->player_id); |
| 348 | 348 | $handicap = new Handicap($player); |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | */ |
| 364 | 364 | public function get($matchid) |
| 365 | 365 | { |
| 366 | - $matchdata = $this->matchRepo->get($matchid); |
|
| 366 | + $matchdata = $this->matchRepo->get($matchid); |
|
| 367 | 367 | return $matchdata; |
| 368 | 368 | } |
| 369 | 369 | |
@@ -17,8 +17,7 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * Our MatchService, containing all useful methods for business logic around Matches |
| 19 | 19 | */ |
| 20 | -class MatchService |
|
| 21 | -{ |
|
| 20 | +class MatchService { |
|
| 22 | 21 | // Containing our matchRepository to make all our database calls to |
| 23 | 22 | protected $matchRepo; |
| 24 | 23 | |
@@ -67,11 +66,10 @@ discard block |
||
| 67 | 66 | $aPlayerCount = 0; |
| 68 | 67 | |
| 69 | 68 | $bPlayerCount = 0; |
| 70 | - foreach($matchdata['player'] as $player){ |
|
| 71 | - if ($player['level_id'] == '1'){ |
|
| 69 | + foreach($matchdata['player'] as $player) { |
|
| 70 | + if ($player['level_id'] == '1') { |
|
| 72 | 71 | $aPlayerCount++; |
| 73 | - } |
|
| 74 | - else { |
|
| 72 | + } else { |
|
| 75 | 73 | $bPlayerCount++; |
| 76 | 74 | } |
| 77 | 75 | $totalPlayers++; |
@@ -100,9 +98,9 @@ discard block |
||
| 100 | 98 | $this->events->fire('match.create', array($matchdata)); // MatchHandler and teamMatchHandler are listening... |
| 101 | 99 | |
| 102 | 100 | // Run for team Matches |
| 103 | - if($matchdata['matchType'] === 'team' || $matchdata['matchType'] === 'both'){ |
|
| 101 | + if($matchdata['matchType'] === 'team' || $matchdata['matchType'] === 'both') { |
|
| 104 | 102 | |
| 105 | - foreach ($matchdata['teamMatchUp1'] as $teamKey => $team){ |
|
| 103 | + foreach ($matchdata['teamMatchUp1'] as $teamKey => $team) { |
|
| 106 | 104 | $matchUp1[] = $this->search($matchdata['player'], 'team', $team); |
| 107 | 105 | } |
| 108 | 106 | |
@@ -110,7 +108,7 @@ discard block |
||
| 110 | 108 | $match1['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
| 111 | 109 | $match1['team_id'] = $matchUp1[0][0]['team']; |
| 112 | 110 | $match1['player1'] = $matchUp1[0][0]['player_id']; |
| 113 | - if(isset($matchUp1[0][1]['player_id'])){ |
|
| 111 | + if(isset($matchUp1[0][1]['player_id'])) { |
|
| 114 | 112 | $match1['player2'] = $matchUp1[0][1]['player_id']; |
| 115 | 113 | } |
| 116 | 114 | $match1['opponent'] = $matchUp1[1][0]['team']; |
@@ -119,14 +117,14 @@ discard block |
||
| 119 | 117 | $match1['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
| 120 | 118 | $match1['team_id'] = $matchUp1[1][0]['team']; |
| 121 | 119 | $match1['player1'] = $matchUp1[1][0]['player_id']; |
| 122 | - if(isset($matchUp1[1][1]['player_id'])){ |
|
| 120 | + if(isset($matchUp1[1][1]['player_id'])) { |
|
| 123 | 121 | $match1['player2'] = $matchUp1[1][1]['player_id']; |
| 124 | 122 | } |
| 125 | 123 | $match1['opponent'] = $matchUp1[0][0]['team']; |
| 126 | 124 | $this->teammatch->create($match1); //save to match table |
| 127 | 125 | |
| 128 | 126 | |
| 129 | - foreach ($matchdata['teamMatchUp2'] as $teamKey => $team){ |
|
| 127 | + foreach ($matchdata['teamMatchUp2'] as $teamKey => $team) { |
|
| 130 | 128 | $matchUp2[] = $this->search($matchdata['player'], 'team', $team); |
| 131 | 129 | } |
| 132 | 130 | |
@@ -134,7 +132,7 @@ discard block |
||
| 134 | 132 | $match2['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
| 135 | 133 | $match2['team_id'] = $matchUp2[0][0]['team']; |
| 136 | 134 | $match2['player1'] = $matchUp2[0][0]['player_id']; |
| 137 | - if(isset($matchUp2[0][1]['player_id'])){ |
|
| 135 | + if(isset($matchUp2[0][1]['player_id'])) { |
|
| 138 | 136 | $match2['player2'] = $matchUp2[0][1]['player_id']; |
| 139 | 137 | } |
| 140 | 138 | $match2['opponent'] = $matchUp2[1][0]['team']; |
@@ -143,14 +141,14 @@ discard block |
||
| 143 | 141 | $match2['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
| 144 | 142 | $match2['team_id'] = $matchUp2[1][0]['team']; |
| 145 | 143 | $match2['player1'] = $matchUp2[1][0]['player_id']; |
| 146 | - if(isset($matchUp2[1][1]['player_id'])){ |
|
| 144 | + if(isset($matchUp2[1][1]['player_id'])) { |
|
| 147 | 145 | $match2['player2'] = $matchUp2[1][1]['player_id']; |
| 148 | 146 | } |
| 149 | 147 | $match2['opponent'] = $matchUp2[0][0]['team']; |
| 150 | 148 | $this->teammatch->create($match2); //save to match table |
| 151 | 149 | |
| 152 | 150 | |
| 153 | - foreach ($matchdata['teamMatchUp3'] as $teamKey => $team){ |
|
| 151 | + foreach ($matchdata['teamMatchUp3'] as $teamKey => $team) { |
|
| 154 | 152 | $matchUp3[] = $this->search($matchdata['player'], 'team', $team); |
| 155 | 153 | } |
| 156 | 154 | |
@@ -158,7 +156,7 @@ discard block |
||
| 158 | 156 | $match3['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
| 159 | 157 | $match3['team_id'] = $matchUp3[0][0]['team']; |
| 160 | 158 | $match3['player1'] = $matchUp3[0][0]['player_id']; |
| 161 | - if(isset($matchUp3[0][1]['player_id'])){ |
|
| 159 | + if(isset($matchUp3[0][1]['player_id'])) { |
|
| 162 | 160 | $match3['player2'] = $matchUp3[0][1]['player_id']; |
| 163 | 161 | } |
| 164 | 162 | |
@@ -168,7 +166,7 @@ discard block |
||
| 168 | 166 | $match3['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
| 169 | 167 | $match3['team_id'] = $matchUp3[1][0]['team']; |
| 170 | 168 | $match3['player1'] = $matchUp3[1][0]['player_id']; |
| 171 | - if(isset($matchUp3[1][1]['player_id'])){ |
|
| 169 | + if(isset($matchUp3[1][1]['player_id'])) { |
|
| 172 | 170 | $match3['player2'] = $matchUp3[1][1]['player_id']; |
| 173 | 171 | } |
| 174 | 172 | $match3['opponent'] = $matchUp3[0][0]['team']; |
@@ -201,7 +199,7 @@ discard block |
||
| 201 | 199 | |
| 202 | 200 | |
| 203 | 201 | $lowGross = array(); |
| 204 | - foreach ($matchRound as $key => $match){ |
|
| 202 | + foreach ($matchRound as $key => $match) { |
|
| 205 | 203 | $lowGross[$match['player']->id] = $match['score']; |
| 206 | 204 | } |
| 207 | 205 | $arrayLowGross = array_keys($lowGross, min($lowGross)); |
@@ -217,7 +215,7 @@ discard block |
||
| 217 | 215 | //Calculate NET winner |
| 218 | 216 | $lowNet = array(); |
| 219 | 217 | $scores =array(); |
| 220 | - foreach ($matchRound as $key => $match){ |
|
| 218 | + foreach ($matchRound as $key => $match) { |
|
| 221 | 219 | $netScore = ($match['score'] - round($match['player']->handicap,0)); //calculate net score |
| 222 | 220 | $lowNet[$match['player']->id] = $netScore; |
| 223 | 221 | } |
@@ -239,13 +237,12 @@ discard block |
||
| 239 | 237 | $match = $this->match->find($matchdata['match']); |
| 240 | 238 | $aPlayers = array(); |
| 241 | 239 | $bPlayers = array(); |
| 242 | - foreach($match->players as $player) |
|
| 243 | - { |
|
| 244 | - if($player->pivot->level_id == 1){ |
|
| 240 | + foreach($match->players as $player) { |
|
| 241 | + if($player->pivot->level_id == 1) { |
|
| 245 | 242 | $aPlayers[] = $player->pivot->player_id; |
| 246 | 243 | |
| 247 | 244 | } |
| 248 | - if($player->pivot->level_id == 2){ |
|
| 245 | + if($player->pivot->level_id == 2) { |
|
| 249 | 246 | $bPlayers[] = $player->pivot->player_id; |
| 250 | 247 | } |
| 251 | 248 | } |
@@ -253,11 +250,11 @@ discard block |
||
| 253 | 250 | //Create Skins arrays |
| 254 | 251 | //player_id, 'holescores' |
| 255 | 252 | foreach($matchRound as $key => $round) { |
| 256 | - if (in_array($round->player_id,$aPlayers)){ |
|
| 253 | + if (in_array($round->player_id,$aPlayers)) { |
|
| 257 | 254 | $aPlayersSkins[$key]['player_id'] = $round->player_id; |
| 258 | 255 | $aPlayersSkins[$key]['holescores'] = $round->holescores; |
| 259 | 256 | } |
| 260 | - if (in_array($round->player_id,$bPlayers)){ |
|
| 257 | + if (in_array($round->player_id,$bPlayers)) { |
|
| 261 | 258 | $bPlayersSkins[$key]['player_id'] = $round->player_id; |
| 262 | 259 | $bPlayersSkins[$key]['holescores'] = $round->holescores; |
| 263 | 260 | } |
@@ -265,8 +262,8 @@ discard block |
||
| 265 | 262 | |
| 266 | 263 | //Run A Skins analysis |
| 267 | 264 | $scores = array(); |
| 268 | - foreach($aPlayersSkins as $key => $playerSkin){ |
|
| 269 | - foreach($playerSkin['holescores'] as $hole => $holescore){ |
|
| 265 | + foreach($aPlayersSkins as $key => $playerSkin) { |
|
| 266 | + foreach($playerSkin['holescores'] as $hole => $holescore) { |
|
| 270 | 267 | $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score']; |
| 271 | 268 | } |
| 272 | 269 | } |
@@ -291,8 +288,8 @@ discard block |
||
| 291 | 288 | |
| 292 | 289 | //Run B Skins analysis |
| 293 | 290 | $scores = array(); |
| 294 | - foreach($bPlayersSkins as $key => $playerSkin){ |
|
| 295 | - foreach($playerSkin['holescores'] as $hole => $holescore){ |
|
| 291 | + foreach($bPlayersSkins as $key => $playerSkin) { |
|
| 292 | + foreach($playerSkin['holescores'] as $hole => $holescore) { |
|
| 296 | 293 | $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score']; |
| 297 | 294 | } |
| 298 | 295 | } |
@@ -326,7 +323,7 @@ discard block |
||
| 326 | 323 | $moneyperskinA = $skinsamoney / $aSkinsWon; |
| 327 | 324 | |
| 328 | 325 | $aSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 1)->get(); |
| 329 | - foreach ($aSkins as $askin){ |
|
| 326 | + foreach ($aSkins as $askin) { |
|
| 330 | 327 | $askin->money = $moneyperskinA; |
| 331 | 328 | $askin->save(); |
| 332 | 329 | } |
@@ -336,14 +333,13 @@ discard block |
||
| 336 | 333 | $moneyperskinB = $skinsbmoney / $bSkinsWon; |
| 337 | 334 | |
| 338 | 335 | $bSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 2)->get(); |
| 339 | - foreach ($bSkins as $bskin){ |
|
| 336 | + foreach ($bSkins as $bskin) { |
|
| 340 | 337 | $bskin->money = $moneyperskinB; |
| 341 | 338 | $bskin->save(); |
| 342 | 339 | } |
| 343 | 340 | } |
| 344 | 341 | //foreach player in pivot table create player and run handicap analysis |
| 345 | - foreach($match->players as $matchplayer) |
|
| 346 | - { |
|
| 342 | + foreach($match->players as $matchplayer) { |
|
| 347 | 343 | $player = Player::find($matchplayer->pivot->player_id); |
| 348 | 344 | $handicap = new Handicap($player); |
| 349 | 345 | $player->handicap = $handicap->calculate(); |