Completed
Push — master ( eac09e...d565f6 )
by Michael
03:18
created
app/controllers/TeamMatchesController.php 3 patches
Indentation   +247 added lines, -247 removed lines patch added patch discarded remove patch
@@ -6,14 +6,14 @@  discard block
 block discarded – undo
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
@@ -56,234 +56,234 @@  discard block
 block discarded – undo
56 56
 	{
57 57
 
58 58
 
59
-        $group = Input::get('group');
59
+		$group = Input::get('group');
60 60
 
61 61
 
62
-        $groupPlayers = $this->matchRoundRepo->matchGroup($id, $group);
62
+		$groupPlayers = $this->matchRoundRepo->matchGroup($id, $group);
63 63
 
64
-        //Create Player data
65
-        $matchUp = array();
66
-        foreach($groupPlayers as $key=>$groupPlayer){
67
-            $matchUp[$key]['player'] = $groupPlayer->pivot->player_id;
68
-            $matchUp[$key]['matchHandicap'] = round($groupPlayer->pivot->handicap ,0);
69
-            foreach ($groupPlayer->round as $round){
70
-                $matchUp[$key]['team'] = $round->team_id;
71
-                $matchUp[$key]['course'] = $round->course_id;
72
-                $matchUp[$key]['holescores'] = $round->holescores;
73
-            }
74
-
75
-        }
76
-
77
-        // Change lowest handicap to ZERO and change others to reflect it
78
-            foreach($matchUp as $key=>$match){
79
-                $matchHandicaps[] = $match['matchHandicap'];
80
-            }
81
-            $lowestMatchHandicap = min($matchHandicaps);
82
-            //handicap change
83
-            $handicapChange = $lowestMatchHandicap * -1;
84
-            foreach($matchUp as $key=>$match){
85
-                $matchUp[$key]['matchHandicap'] = $match['matchHandicap'] + $handicapChange;
86
-            }
87
-
88
-
89
-        // Separate two teams
90
-
91
-        foreach($matchUp as $key=>$item){
92
-            $teamIds[$key] = $item['team'];
93
-        }
94
-        sort($teamIds);
95
-        $teamIds = array_slice($teamIds, 1, -1);
96
-        $team1Id = $teamIds[0];
97
-        $team2Id = $teamIds[1];
98
-
99
-        $team1 = array();
100
-        $team2 = array();
101
-
102
-        foreach($matchUp as $key=>$match){
103
-            if($match['team'] ==$team1Id ){
104
-                $team1[] = $matchUp[$key];
105
-            } else {
106
-                $team2[] = $matchUp[$key];
107
-            }
108
-        }
109
-
110
-
111
-        $team1Name = Team::select('name')->where('id', '=', $team1Id)->get()->toArray();
112
-        foreach($matchUp as $key=>$match){
113
-            if($match['team'] == $team1[0]['team']){
114
-                $team1[] = $match;
115
-                unset($matchUp[$key]);
116
-            }
117
-        }
118
-
119
-        $team2 = $matchUp;
120
-
121
-        $team2Name = Team::select('name')->where('id', '=', $team2Id)->get()->toArray();
122
-
123
-            $holesData = Hole::select('handicap')->where('course_id', '=', $team1[0]['course'])->get();
124
-
125
-            $team1Scores = $this->getTeamNetScore($team1, $holesData);
126
-            $team2Scores = $this->getTeamNetScore($team2, $holesData);
127
-
128
-            $team1Points = $this->calculatePoints($team1Scores, $team2Scores);
129
-            $team2Points = $this->calculatePoints($team2Scores, $team1Scores);
130
-
131
-            // Bonus point logic
132
-            // Occurs after 9th hole score is added to both teams
133
-
134
-            if($team1Scores[8] != null && $team2Scores[8] != null){
135
-                if($team1Points > $team2Points){
136
-                    $team1Points = $team1Points + 1;
137
-                }
138
-                if($team2Points > $team1Points){
139
-                    $team2Points = $team2Points + 1;
140
-                }
141
-                if($team1Points == $team2Points){
142
-                    $team1Points = $team1Points + .5;
143
-                    $team2Points = $team2Points + .5;
144
-                }
145
-            }
146
-
147
-            //Save Points in Teammatches
148
-            Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team1Id)->update(array('pointsWon' => $team1Points));
149
-            Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team2Id)->update(array('pointsWon' => $team2Points));
150
-
151
-
152
-        //Need to determine if same amount of scores are in both
153
-        // If not then do not return
154
-
155
-            foreach($team1Scores as $key=>$teamScore){
156
-                if($teamScore <= 0){
157
-                    $team1Scores[$key] = '';
158
-                }
159
-            }
160
-
161
-        foreach($team2Scores as $key=>$teamScore){
162
-            if($teamScore <= 0){
163
-                $team2Scores[$key] = '';
164
-            }
165
-        }
166
-
167
-        $team[0] = [
168
-            "team" =>  $team1Name[0]['name'],
169
-            "hole1" => $team1Scores[0],
170
-            "hole2" => $team1Scores[1],
171
-            "hole3" => $team1Scores[2],
172
-            "hole4" => $team1Scores[3],
173
-            "hole5" => $team1Scores[4],
174
-            "hole6" => $team1Scores[5],
175
-            "hole7" => $team1Scores[6],
176
-            "hole8" => $team1Scores[7],
177
-            "hole9" => $team1Scores[8],
178
-            "points" =>$team1Points
179
-        ];
180
-
181
-        $team[1] = [
182
-            "team" =>  $team2Name[0]['name'],
183
-            "hole1" => $team2Scores[0],
184
-            "hole2" => $team2Scores[1],
185
-            "hole3" => $team2Scores[2],
186
-            "hole4" => $team2Scores[3],
187
-            "hole5" => $team2Scores[4],
188
-            "hole6" => $team2Scores[5],
189
-            "hole7" => $team2Scores[6],
190
-            "hole8" => $team2Scores[7],
191
-            "hole9" => $team2Scores[8],
192
-            "points" => $team2Points
193
-        ];
194
-
195
-        $data['data'] = $team;
196
-        return $data;
64
+		//Create Player data
65
+		$matchUp = array();
66
+		foreach($groupPlayers as $key=>$groupPlayer){
67
+			$matchUp[$key]['player'] = $groupPlayer->pivot->player_id;
68
+			$matchUp[$key]['matchHandicap'] = round($groupPlayer->pivot->handicap ,0);
69
+			foreach ($groupPlayer->round as $round){
70
+				$matchUp[$key]['team'] = $round->team_id;
71
+				$matchUp[$key]['course'] = $round->course_id;
72
+				$matchUp[$key]['holescores'] = $round->holescores;
73
+			}
74
+
75
+		}
76
+
77
+		// Change lowest handicap to ZERO and change others to reflect it
78
+			foreach($matchUp as $key=>$match){
79
+				$matchHandicaps[] = $match['matchHandicap'];
80
+			}
81
+			$lowestMatchHandicap = min($matchHandicaps);
82
+			//handicap change
83
+			$handicapChange = $lowestMatchHandicap * -1;
84
+			foreach($matchUp as $key=>$match){
85
+				$matchUp[$key]['matchHandicap'] = $match['matchHandicap'] + $handicapChange;
86
+			}
87
+
88
+
89
+		// Separate two teams
90
+
91
+		foreach($matchUp as $key=>$item){
92
+			$teamIds[$key] = $item['team'];
93
+		}
94
+		sort($teamIds);
95
+		$teamIds = array_slice($teamIds, 1, -1);
96
+		$team1Id = $teamIds[0];
97
+		$team2Id = $teamIds[1];
98
+
99
+		$team1 = array();
100
+		$team2 = array();
101
+
102
+		foreach($matchUp as $key=>$match){
103
+			if($match['team'] ==$team1Id ){
104
+				$team1[] = $matchUp[$key];
105
+			} else {
106
+				$team2[] = $matchUp[$key];
107
+			}
108
+		}
109
+
110
+
111
+		$team1Name = Team::select('name')->where('id', '=', $team1Id)->get()->toArray();
112
+		foreach($matchUp as $key=>$match){
113
+			if($match['team'] == $team1[0]['team']){
114
+				$team1[] = $match;
115
+				unset($matchUp[$key]);
116
+			}
117
+		}
118
+
119
+		$team2 = $matchUp;
120
+
121
+		$team2Name = Team::select('name')->where('id', '=', $team2Id)->get()->toArray();
122
+
123
+			$holesData = Hole::select('handicap')->where('course_id', '=', $team1[0]['course'])->get();
124
+
125
+			$team1Scores = $this->getTeamNetScore($team1, $holesData);
126
+			$team2Scores = $this->getTeamNetScore($team2, $holesData);
127
+
128
+			$team1Points = $this->calculatePoints($team1Scores, $team2Scores);
129
+			$team2Points = $this->calculatePoints($team2Scores, $team1Scores);
130
+
131
+			// Bonus point logic
132
+			// Occurs after 9th hole score is added to both teams
133
+
134
+			if($team1Scores[8] != null && $team2Scores[8] != null){
135
+				if($team1Points > $team2Points){
136
+					$team1Points = $team1Points + 1;
137
+				}
138
+				if($team2Points > $team1Points){
139
+					$team2Points = $team2Points + 1;
140
+				}
141
+				if($team1Points == $team2Points){
142
+					$team1Points = $team1Points + .5;
143
+					$team2Points = $team2Points + .5;
144
+				}
145
+			}
146
+
147
+			//Save Points in Teammatches
148
+			Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team1Id)->update(array('pointsWon' => $team1Points));
149
+			Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team2Id)->update(array('pointsWon' => $team2Points));
150
+
151
+
152
+		//Need to determine if same amount of scores are in both
153
+		// If not then do not return
154
+
155
+			foreach($team1Scores as $key=>$teamScore){
156
+				if($teamScore <= 0){
157
+					$team1Scores[$key] = '';
158
+				}
159
+			}
160
+
161
+		foreach($team2Scores as $key=>$teamScore){
162
+			if($teamScore <= 0){
163
+				$team2Scores[$key] = '';
164
+			}
165
+		}
166
+
167
+		$team[0] = [
168
+			"team" =>  $team1Name[0]['name'],
169
+			"hole1" => $team1Scores[0],
170
+			"hole2" => $team1Scores[1],
171
+			"hole3" => $team1Scores[2],
172
+			"hole4" => $team1Scores[3],
173
+			"hole5" => $team1Scores[4],
174
+			"hole6" => $team1Scores[5],
175
+			"hole7" => $team1Scores[6],
176
+			"hole8" => $team1Scores[7],
177
+			"hole9" => $team1Scores[8],
178
+			"points" =>$team1Points
179
+		];
180
+
181
+		$team[1] = [
182
+			"team" =>  $team2Name[0]['name'],
183
+			"hole1" => $team2Scores[0],
184
+			"hole2" => $team2Scores[1],
185
+			"hole3" => $team2Scores[2],
186
+			"hole4" => $team2Scores[3],
187
+			"hole5" => $team2Scores[4],
188
+			"hole6" => $team2Scores[5],
189
+			"hole7" => $team2Scores[6],
190
+			"hole8" => $team2Scores[7],
191
+			"hole9" => $team2Scores[8],
192
+			"points" => $team2Points
193
+		];
194
+
195
+		$data['data'] = $team;
196
+		return $data;
197 197
 	}
198 198
 
199
-    private function getTeamNetScore($team, $holesData)
200
-    {
201
-        foreach($team as $key=>$item){
202
-            // Create holes array for NET
203
-            $holes = array();
204
-            $i = 1;
205
-            foreach($holesData as $key=>$holeData){
206
-                $holes[$i] = $holeData->handicap;
207
-                $i++;
208
-            }
209
-
210
-            // Create stroke array - how many to take away from score
211
-            $strokeArray = [
212
-                1 => 0,
213
-                2 => 0,
214
-                3 => 0,
215
-                4 => 0,
216
-                5 => 0,
217
-                6 => 0,
218
-                7 => 0,
219
-                8 => 0,
220
-                9 => 0
221
-            ];
222
-            //Create array of strokes
223
-            for($counter = $item['matchHandicap']; $counter > 0; $counter--){
224
-                if($counter > 9){
225
-                    $newCounter = $counter - 9;
226
-                    while($newCounter > 0) {
227
-                        $strokeArray[$newCounter] = $strokeArray[$newCounter] + 1;
228
-                        $counter--;
229
-                        $newCounter--;
230
-                    }
231
-                }
232
-                $strokeArray[$counter] = $strokeArray[$counter] + 1;
233
-            }
234
-            // Plus handicaps don't hit previous loop so need its own
235
-            //Plus handicap logic
236
-
237
-            foreach($strokeArray as $strokeKey=>$stroke){
238
-                $holeKey = array_search($strokeKey,$holes);
239
-                $holes[$holeKey] = $stroke;
240
-            }
241
-
242
-            ///now have array of strokes to subtract
243
-            //get array of holescores
244
-
245
-            $holeScores = $item['holescores'];
246
-            foreach($holeScores as $key=>$holeScore){
247
-                //check if new score is less PlayerScores
248
-                if(isset($teamScores[$key])){ // 2nd time in for hole
249
-
250
-                    //set temp handi score
251
-                    $tempScore = $holeScore['score'] - $holes[$key+1];
252
-                    if($teamScores[$key] >= $tempScore){
253
-                        $teamScores[$key] = $holeScore['score'] - $holes[$key+1];
254
-                    }
255
-                } else{ // first time in for hole
256
-                    if($holeScore['score'] != null){
257
-                        $teamScores[$key] = $holeScore['score'] - $holes[$key+1];
258
-                    } else{
259
-                        $teamScores[$key] = null;
260
-                    }
261
-                }
262
-            }
263
-
264
-        }
265
-        return $teamScores;
266
-    }
267
-
268
-    private function calculatePoints($team, $opponent)
269
-    {
270
-        $points = 0;
271
-        $teamTotalPoints = 0;
272
-        $opponentTotalPoints = 0;
273
-        foreach ($team as $key=>$score){
274
-            if($score != null){
275
-                if($score < $opponent[$key]){
276
-                    $points++;
277
-                }
278
-                if($score == $opponent[$key]){
279
-                    $points = $points + .5;
280
-                }
281
-            }
282
-
283
-        }
284
-
285
-        return $points;
286
-    }
199
+	private function getTeamNetScore($team, $holesData)
200
+	{
201
+		foreach($team as $key=>$item){
202
+			// Create holes array for NET
203
+			$holes = array();
204
+			$i = 1;
205
+			foreach($holesData as $key=>$holeData){
206
+				$holes[$i] = $holeData->handicap;
207
+				$i++;
208
+			}
209
+
210
+			// Create stroke array - how many to take away from score
211
+			$strokeArray = [
212
+				1 => 0,
213
+				2 => 0,
214
+				3 => 0,
215
+				4 => 0,
216
+				5 => 0,
217
+				6 => 0,
218
+				7 => 0,
219
+				8 => 0,
220
+				9 => 0
221
+			];
222
+			//Create array of strokes
223
+			for($counter = $item['matchHandicap']; $counter > 0; $counter--){
224
+				if($counter > 9){
225
+					$newCounter = $counter - 9;
226
+					while($newCounter > 0) {
227
+						$strokeArray[$newCounter] = $strokeArray[$newCounter] + 1;
228
+						$counter--;
229
+						$newCounter--;
230
+					}
231
+				}
232
+				$strokeArray[$counter] = $strokeArray[$counter] + 1;
233
+			}
234
+			// Plus handicaps don't hit previous loop so need its own
235
+			//Plus handicap logic
236
+
237
+			foreach($strokeArray as $strokeKey=>$stroke){
238
+				$holeKey = array_search($strokeKey,$holes);
239
+				$holes[$holeKey] = $stroke;
240
+			}
241
+
242
+			///now have array of strokes to subtract
243
+			//get array of holescores
244
+
245
+			$holeScores = $item['holescores'];
246
+			foreach($holeScores as $key=>$holeScore){
247
+				//check if new score is less PlayerScores
248
+				if(isset($teamScores[$key])){ // 2nd time in for hole
249
+
250
+					//set temp handi score
251
+					$tempScore = $holeScore['score'] - $holes[$key+1];
252
+					if($teamScores[$key] >= $tempScore){
253
+						$teamScores[$key] = $holeScore['score'] - $holes[$key+1];
254
+					}
255
+				} else{ // first time in for hole
256
+					if($holeScore['score'] != null){
257
+						$teamScores[$key] = $holeScore['score'] - $holes[$key+1];
258
+					} else{
259
+						$teamScores[$key] = null;
260
+					}
261
+				}
262
+			}
263
+
264
+		}
265
+		return $teamScores;
266
+	}
267
+
268
+	private function calculatePoints($team, $opponent)
269
+	{
270
+		$points = 0;
271
+		$teamTotalPoints = 0;
272
+		$opponentTotalPoints = 0;
273
+		foreach ($team as $key=>$score){
274
+			if($score != null){
275
+				if($score < $opponent[$key]){
276
+					$points++;
277
+				}
278
+				if($score == $opponent[$key]){
279
+					$points = $points + .5;
280
+				}
281
+			}
282
+
283
+		}
284
+
285
+		return $points;
286
+	}
287 287
 
288 288
 	/**
289 289
 	 * Show the form for editing the specified resource.
@@ -321,22 +321,22 @@  discard block
 block discarded – undo
321 321
 	}
322 322
 
323 323
 	public function getPointsByYear($year)
324
-    {
325
-        $teamMatches = Teammatch::select('team_id','pointsWon')->whereYear('created_at', '=', $year)->with('team')->get();
326
-        foreach($teamMatches as $key=>$teamMatch){
327
-            $pointsData[$key]['name'] = $teamMatch['team']['name'];
328
-            $pointsData[$key]['points'] =  Teammatch::select('team_id','pointsWon')
329
-                ->where('team_id', '=', $teamMatch->team_id)
330
-                ->whereYear('created_at', '=', $year)
331
-                ->with('team')
332
-                ->sum('pointsWon');
333
-
334
-        }
335
-
336
-        $pointsData = array_map("unserialize", array_unique(array_map("serialize", $pointsData)));
337
-        $data['data'] = $pointsData;
338
-        return $data;
339
-    }
324
+	{
325
+		$teamMatches = Teammatch::select('team_id','pointsWon')->whereYear('created_at', '=', $year)->with('team')->get();
326
+		foreach($teamMatches as $key=>$teamMatch){
327
+			$pointsData[$key]['name'] = $teamMatch['team']['name'];
328
+			$pointsData[$key]['points'] =  Teammatch::select('team_id','pointsWon')
329
+				->where('team_id', '=', $teamMatch->team_id)
330
+				->whereYear('created_at', '=', $year)
331
+				->with('team')
332
+				->sum('pointsWon');
333
+
334
+		}
335
+
336
+		$pointsData = array_map("unserialize", array_unique(array_map("serialize", $pointsData)));
337
+		$data['data'] = $pointsData;
338
+		return $data;
339
+	}
340 340
 
341 341
 
342 342
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -63,10 +63,10 @@  discard block
 block discarded – undo
63 63
 
64 64
         //Create Player data
65 65
         $matchUp = array();
66
-        foreach($groupPlayers as $key=>$groupPlayer){
66
+        foreach ($groupPlayers as $key=>$groupPlayer) {
67 67
             $matchUp[$key]['player'] = $groupPlayer->pivot->player_id;
68
-            $matchUp[$key]['matchHandicap'] = round($groupPlayer->pivot->handicap ,0);
69
-            foreach ($groupPlayer->round as $round){
68
+            $matchUp[$key]['matchHandicap'] = round($groupPlayer->pivot->handicap, 0);
69
+            foreach ($groupPlayer->round as $round) {
70 70
                 $matchUp[$key]['team'] = $round->team_id;
71 71
                 $matchUp[$key]['course'] = $round->course_id;
72 72
                 $matchUp[$key]['holescores'] = $round->holescores;
@@ -75,20 +75,20 @@  discard block
 block discarded – undo
75 75
         }
76 76
 
77 77
         // Change lowest handicap to ZERO and change others to reflect it
78
-            foreach($matchUp as $key=>$match){
78
+            foreach ($matchUp as $key=>$match) {
79 79
                 $matchHandicaps[] = $match['matchHandicap'];
80 80
             }
81 81
             $lowestMatchHandicap = min($matchHandicaps);
82 82
             //handicap change
83 83
             $handicapChange = $lowestMatchHandicap * -1;
84
-            foreach($matchUp as $key=>$match){
84
+            foreach ($matchUp as $key=>$match) {
85 85
                 $matchUp[$key]['matchHandicap'] = $match['matchHandicap'] + $handicapChange;
86 86
             }
87 87
 
88 88
 
89 89
         // Separate two teams
90 90
 
91
-        foreach($matchUp as $key=>$item){
91
+        foreach ($matchUp as $key=>$item) {
92 92
             $teamIds[$key] = $item['team'];
93 93
         }
94 94
         sort($teamIds);
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
         $team1 = array();
100 100
         $team2 = array();
101 101
 
102
-        foreach($matchUp as $key=>$match){
103
-            if($match['team'] ==$team1Id ){
102
+        foreach ($matchUp as $key=>$match) {
103
+            if ($match['team'] == $team1Id) {
104 104
                 $team1[] = $matchUp[$key];
105 105
             } else {
106 106
                 $team2[] = $matchUp[$key];
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
 
110 110
 
111 111
         $team1Name = Team::select('name')->where('id', '=', $team1Id)->get()->toArray();
112
-        foreach($matchUp as $key=>$match){
113
-            if($match['team'] == $team1[0]['team']){
112
+        foreach ($matchUp as $key=>$match) {
113
+            if ($match['team'] == $team1[0]['team']) {
114 114
                 $team1[] = $match;
115 115
                 unset($matchUp[$key]);
116 116
             }
@@ -131,14 +131,14 @@  discard block
 block discarded – undo
131 131
             // Bonus point logic
132 132
             // Occurs after 9th hole score is added to both teams
133 133
 
134
-            if($team1Scores[8] != null && $team2Scores[8] != null){
135
-                if($team1Points > $team2Points){
134
+            if ($team1Scores[8] != null && $team2Scores[8] != null) {
135
+                if ($team1Points > $team2Points) {
136 136
                     $team1Points = $team1Points + 1;
137 137
                 }
138
-                if($team2Points > $team1Points){
138
+                if ($team2Points > $team1Points) {
139 139
                     $team2Points = $team2Points + 1;
140 140
                 }
141
-                if($team1Points == $team2Points){
141
+                if ($team1Points == $team2Points) {
142 142
                     $team1Points = $team1Points + .5;
143 143
                     $team2Points = $team2Points + .5;
144 144
                 }
@@ -152,14 +152,14 @@  discard block
 block discarded – undo
152 152
         //Need to determine if same amount of scores are in both
153 153
         // If not then do not return
154 154
 
155
-            foreach($team1Scores as $key=>$teamScore){
156
-                if($teamScore <= 0){
155
+            foreach ($team1Scores as $key=>$teamScore) {
156
+                if ($teamScore <= 0) {
157 157
                     $team1Scores[$key] = '';
158 158
                 }
159 159
             }
160 160
 
161
-        foreach($team2Scores as $key=>$teamScore){
162
-            if($teamScore <= 0){
161
+        foreach ($team2Scores as $key=>$teamScore) {
162
+            if ($teamScore <= 0) {
163 163
                 $team2Scores[$key] = '';
164 164
             }
165 165
         }
@@ -198,11 +198,11 @@  discard block
 block discarded – undo
198 198
 
199 199
     private function getTeamNetScore($team, $holesData)
200 200
     {
201
-        foreach($team as $key=>$item){
201
+        foreach ($team as $key=>$item) {
202 202
             // Create holes array for NET
203 203
             $holes = array();
204 204
             $i = 1;
205
-            foreach($holesData as $key=>$holeData){
205
+            foreach ($holesData as $key=>$holeData) {
206 206
                 $holes[$i] = $holeData->handicap;
207 207
                 $i++;
208 208
             }
@@ -220,10 +220,10 @@  discard block
 block discarded – undo
220 220
                 9 => 0
221 221
             ];
222 222
             //Create array of strokes
223
-            for($counter = $item['matchHandicap']; $counter > 0; $counter--){
224
-                if($counter > 9){
223
+            for ($counter = $item['matchHandicap']; $counter > 0; $counter--) {
224
+                if ($counter > 9) {
225 225
                     $newCounter = $counter - 9;
226
-                    while($newCounter > 0) {
226
+                    while ($newCounter > 0) {
227 227
                         $strokeArray[$newCounter] = $strokeArray[$newCounter] + 1;
228 228
                         $counter--;
229 229
                         $newCounter--;
@@ -234,8 +234,8 @@  discard block
 block discarded – undo
234 234
             // Plus handicaps don't hit previous loop so need its own
235 235
             //Plus handicap logic
236 236
 
237
-            foreach($strokeArray as $strokeKey=>$stroke){
238
-                $holeKey = array_search($strokeKey,$holes);
237
+            foreach ($strokeArray as $strokeKey=>$stroke) {
238
+                $holeKey = array_search($strokeKey, $holes);
239 239
                 $holes[$holeKey] = $stroke;
240 240
             }
241 241
 
@@ -243,19 +243,19 @@  discard block
 block discarded – undo
243 243
             //get array of holescores
244 244
 
245 245
             $holeScores = $item['holescores'];
246
-            foreach($holeScores as $key=>$holeScore){
246
+            foreach ($holeScores as $key=>$holeScore) {
247 247
                 //check if new score is less PlayerScores
248
-                if(isset($teamScores[$key])){ // 2nd time in for hole
248
+                if (isset($teamScores[$key])) { // 2nd time in for hole
249 249
 
250 250
                     //set temp handi score
251
-                    $tempScore = $holeScore['score'] - $holes[$key+1];
252
-                    if($teamScores[$key] >= $tempScore){
253
-                        $teamScores[$key] = $holeScore['score'] - $holes[$key+1];
251
+                    $tempScore = $holeScore['score'] - $holes[$key + 1];
252
+                    if ($teamScores[$key] >= $tempScore) {
253
+                        $teamScores[$key] = $holeScore['score'] - $holes[$key + 1];
254 254
                     }
255
-                } else{ // first time in for hole
256
-                    if($holeScore['score'] != null){
257
-                        $teamScores[$key] = $holeScore['score'] - $holes[$key+1];
258
-                    } else{
255
+                } else { // first time in for hole
256
+                    if ($holeScore['score'] != null) {
257
+                        $teamScores[$key] = $holeScore['score'] - $holes[$key + 1];
258
+                    } else {
259 259
                         $teamScores[$key] = null;
260 260
                     }
261 261
                 }
@@ -270,12 +270,12 @@  discard block
 block discarded – undo
270 270
         $points = 0;
271 271
         $teamTotalPoints = 0;
272 272
         $opponentTotalPoints = 0;
273
-        foreach ($team as $key=>$score){
274
-            if($score != null){
275
-                if($score < $opponent[$key]){
273
+        foreach ($team as $key=>$score) {
274
+            if ($score != null) {
275
+                if ($score < $opponent[$key]) {
276 276
                     $points++;
277 277
                 }
278
-                if($score == $opponent[$key]){
278
+                if ($score == $opponent[$key]) {
279 279
                     $points = $points + .5;
280 280
                 }
281 281
             }
@@ -322,10 +322,10 @@  discard block
 block discarded – undo
322 322
 
323 323
 	public function getPointsByYear($year)
324 324
     {
325
-        $teamMatches = Teammatch::select('team_id','pointsWon')->whereYear('created_at', '=', $year)->with('team')->get();
326
-        foreach($teamMatches as $key=>$teamMatch){
325
+        $teamMatches = Teammatch::select('team_id', 'pointsWon')->whereYear('created_at', '=', $year)->with('team')->get();
326
+        foreach ($teamMatches as $key=>$teamMatch) {
327 327
             $pointsData[$key]['name'] = $teamMatch['team']['name'];
328
-            $pointsData[$key]['points'] =  Teammatch::select('team_id','pointsWon')
328
+            $pointsData[$key]['points'] = Teammatch::select('team_id', 'pointsWon')
329 329
                 ->where('team_id', '=', $teamMatch->team_id)
330 330
                 ->whereYear('created_at', '=', $year)
331 331
                 ->with('team')
Please login to merge, or discard this patch.
Braces   +36 added lines, -34 removed lines patch added patch discarded remove patch
@@ -63,10 +63,10 @@  discard block
 block discarded – undo
63 63
 
64 64
         //Create Player data
65 65
         $matchUp = array();
66
-        foreach($groupPlayers as $key=>$groupPlayer){
66
+        foreach($groupPlayers as $key=>$groupPlayer) {
67 67
             $matchUp[$key]['player'] = $groupPlayer->pivot->player_id;
68 68
             $matchUp[$key]['matchHandicap'] = round($groupPlayer->pivot->handicap ,0);
69
-            foreach ($groupPlayer->round as $round){
69
+            foreach ($groupPlayer->round as $round) {
70 70
                 $matchUp[$key]['team'] = $round->team_id;
71 71
                 $matchUp[$key]['course'] = $round->course_id;
72 72
                 $matchUp[$key]['holescores'] = $round->holescores;
@@ -75,20 +75,20 @@  discard block
 block discarded – undo
75 75
         }
76 76
 
77 77
         // Change lowest handicap to ZERO and change others to reflect it
78
-            foreach($matchUp as $key=>$match){
78
+            foreach($matchUp as $key=>$match) {
79 79
                 $matchHandicaps[] = $match['matchHandicap'];
80 80
             }
81 81
             $lowestMatchHandicap = min($matchHandicaps);
82 82
             //handicap change
83 83
             $handicapChange = $lowestMatchHandicap * -1;
84
-            foreach($matchUp as $key=>$match){
84
+            foreach($matchUp as $key=>$match) {
85 85
                 $matchUp[$key]['matchHandicap'] = $match['matchHandicap'] + $handicapChange;
86 86
             }
87 87
 
88 88
 
89 89
         // Separate two teams
90 90
 
91
-        foreach($matchUp as $key=>$item){
91
+        foreach($matchUp as $key=>$item) {
92 92
             $teamIds[$key] = $item['team'];
93 93
         }
94 94
         sort($teamIds);
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
         $team1 = array();
100 100
         $team2 = array();
101 101
 
102
-        foreach($matchUp as $key=>$match){
103
-            if($match['team'] ==$team1Id ){
102
+        foreach($matchUp as $key=>$match) {
103
+            if($match['team'] ==$team1Id ) {
104 104
                 $team1[] = $matchUp[$key];
105 105
             } else {
106 106
                 $team2[] = $matchUp[$key];
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
 
110 110
 
111 111
         $team1Name = Team::select('name')->where('id', '=', $team1Id)->get()->toArray();
112
-        foreach($matchUp as $key=>$match){
113
-            if($match['team'] == $team1[0]['team']){
112
+        foreach($matchUp as $key=>$match) {
113
+            if($match['team'] == $team1[0]['team']) {
114 114
                 $team1[] = $match;
115 115
                 unset($matchUp[$key]);
116 116
             }
@@ -131,14 +131,14 @@  discard block
 block discarded – undo
131 131
             // Bonus point logic
132 132
             // Occurs after 9th hole score is added to both teams
133 133
 
134
-            if($team1Scores[8] != null && $team2Scores[8] != null){
135
-                if($team1Points > $team2Points){
134
+            if($team1Scores[8] != null && $team2Scores[8] != null) {
135
+                if($team1Points > $team2Points) {
136 136
                     $team1Points = $team1Points + 1;
137 137
                 }
138
-                if($team2Points > $team1Points){
138
+                if($team2Points > $team1Points) {
139 139
                     $team2Points = $team2Points + 1;
140 140
                 }
141
-                if($team1Points == $team2Points){
141
+                if($team1Points == $team2Points) {
142 142
                     $team1Points = $team1Points + .5;
143 143
                     $team2Points = $team2Points + .5;
144 144
                 }
@@ -152,14 +152,14 @@  discard block
 block discarded – undo
152 152
         //Need to determine if same amount of scores are in both
153 153
         // If not then do not return
154 154
 
155
-            foreach($team1Scores as $key=>$teamScore){
156
-                if($teamScore <= 0){
155
+            foreach($team1Scores as $key=>$teamScore) {
156
+                if($teamScore <= 0) {
157 157
                     $team1Scores[$key] = '';
158 158
                 }
159 159
             }
160 160
 
161
-        foreach($team2Scores as $key=>$teamScore){
162
-            if($teamScore <= 0){
161
+        foreach($team2Scores as $key=>$teamScore) {
162
+            if($teamScore <= 0) {
163 163
                 $team2Scores[$key] = '';
164 164
             }
165 165
         }
@@ -198,11 +198,11 @@  discard block
 block discarded – undo
198 198
 
199 199
     private function getTeamNetScore($team, $holesData)
200 200
     {
201
-        foreach($team as $key=>$item){
201
+        foreach($team as $key=>$item) {
202 202
             // Create holes array for NET
203 203
             $holes = array();
204 204
             $i = 1;
205
-            foreach($holesData as $key=>$holeData){
205
+            foreach($holesData as $key=>$holeData) {
206 206
                 $holes[$i] = $holeData->handicap;
207 207
                 $i++;
208 208
             }
@@ -220,8 +220,8 @@  discard block
 block discarded – undo
220 220
                 9 => 0
221 221
             ];
222 222
             //Create array of strokes
223
-            for($counter = $item['matchHandicap']; $counter > 0; $counter--){
224
-                if($counter > 9){
223
+            for($counter = $item['matchHandicap']; $counter > 0; $counter--) {
224
+                if($counter > 9) {
225 225
                     $newCounter = $counter - 9;
226 226
                     while($newCounter > 0) {
227 227
                         $strokeArray[$newCounter] = $strokeArray[$newCounter] + 1;
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
             // Plus handicaps don't hit previous loop so need its own
235 235
             //Plus handicap logic
236 236
 
237
-            foreach($strokeArray as $strokeKey=>$stroke){
237
+            foreach($strokeArray as $strokeKey=>$stroke) {
238 238
                 $holeKey = array_search($strokeKey,$holes);
239 239
                 $holes[$holeKey] = $stroke;
240 240
             }
@@ -243,19 +243,21 @@  discard block
 block discarded – undo
243 243
             //get array of holescores
244 244
 
245 245
             $holeScores = $item['holescores'];
246
-            foreach($holeScores as $key=>$holeScore){
246
+            foreach($holeScores as $key=>$holeScore) {
247 247
                 //check if new score is less PlayerScores
248
-                if(isset($teamScores[$key])){ // 2nd time in for hole
248
+                if(isset($teamScores[$key])) {
249
+// 2nd time in for hole
249 250
 
250 251
                     //set temp handi score
251 252
                     $tempScore = $holeScore['score'] - $holes[$key+1];
252
-                    if($teamScores[$key] >= $tempScore){
253
+                    if($teamScores[$key] >= $tempScore) {
253 254
                         $teamScores[$key] = $holeScore['score'] - $holes[$key+1];
254 255
                     }
255
-                } else{ // first time in for hole
256
-                    if($holeScore['score'] != null){
256
+                } else {
257
+// first time in for hole
258
+                    if($holeScore['score'] != null) {
257 259
                         $teamScores[$key] = $holeScore['score'] - $holes[$key+1];
258
-                    } else{
260
+                    } else {
259 261
                         $teamScores[$key] = null;
260 262
                     }
261 263
                 }
@@ -270,12 +272,12 @@  discard block
 block discarded – undo
270 272
         $points = 0;
271 273
         $teamTotalPoints = 0;
272 274
         $opponentTotalPoints = 0;
273
-        foreach ($team as $key=>$score){
274
-            if($score != null){
275
-                if($score < $opponent[$key]){
275
+        foreach ($team as $key=>$score) {
276
+            if($score != null) {
277
+                if($score < $opponent[$key]) {
276 278
                     $points++;
277 279
                 }
278
-                if($score == $opponent[$key]){
280
+                if($score == $opponent[$key]) {
279 281
                     $points = $points + .5;
280 282
                 }
281 283
             }
@@ -321,9 +323,9 @@  discard block
 block discarded – undo
321 323
 	}
322 324
 
323 325
 	public function getPointsByYear($year)
324
-    {
326
+	{
325 327
         $teamMatches = Teammatch::select('team_id','pointsWon')->whereYear('created_at', '=', $year)->with('team')->get();
326
-        foreach($teamMatches as $key=>$teamMatch){
328
+        foreach($teamMatches as $key=>$teamMatch) {
327 329
             $pointsData[$key]['name'] = $teamMatch['team']['name'];
328 330
             $pointsData[$key]['points'] =  Teammatch::select('team_id','pointsWon')
329 331
                 ->where('team_id', '=', $teamMatch->team_id)
Please login to merge, or discard this patch.