Completed
Push — master ( d565f6...12549b )
by Michael
02:45
created
app/controllers/TeamMatchesController.php 3 patches
Indentation   +263 added lines, -263 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,249 +56,249 @@  discard block
 block discarded – undo
56 56
 	{
57 57
 
58 58
 
59
-        $group = Input::get('group');
60
-
59
+		$group = Input::get('group');
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
-            $team1Bonus = null;
135
-            $team2Bonus = null;
136
-
137
-            if($team1Scores[8] != null && $team2Scores[8] != null){
138
-                if($team1Points > $team2Points){
139
-                    $team1Points = $team1Points + 1;
140
-                    $team1Bonus = 1;
141
-                }
142
-                if($team2Points > $team1Points){
143
-                    $team2Points = $team2Points + 1;
144
-                    $team2Bonus = 1;
145
-                }
146
-                if($team1Points == $team2Points){
147
-                    $team1Points = $team1Points + .5;
148
-                    $team1Bonus = .5;
149
-                    $team2Points = $team2Points + .5;
150
-                    $team2Bonus = .5;
151
-                }
152
-            }
153
-
154
-            //Save Points in Teammatches
155
-            Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team1Id)->update(array('pointsWon' => $team1Points));
156
-            Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team2Id)->update(array('pointsWon' => $team2Points));
157
-
158
-
159
-        //Need to determine if same amount of scores are in both
160
-        // If not then do not return
161
-
162
-        foreach($team1Scores as $key=>$teamScore){
163
-            if($teamScore <= 0){
164
-                $team1Scores[$key] = '';
165
-            }
166
-        }
167
-        $team1Net = array_sum($team1Scores);
168
-
169
-
170
-        foreach($team2Scores as $key=>$teamScore){
171
-            if($teamScore <= 0){
172
-                $team2Scores[$key] = '';
173
-            }
174
-        }
175
-        $team2Net = array_sum($team2Scores);
176
-
177
-
178
-        $team[0] = [
179
-            "team" =>  $team1Name[0]['name'],
180
-            "hole1" => $team1Scores[0],
181
-            "hole2" => $team1Scores[1],
182
-            "hole3" => $team1Scores[2],
183
-            "hole4" => $team1Scores[3],
184
-            "hole5" => $team1Scores[4],
185
-            "hole6" => $team1Scores[5],
186
-            "hole7" => $team1Scores[6],
187
-            "hole8" => $team1Scores[7],
188
-            "hole9" => $team1Scores[8],
189
-            "bonus" => $team1Bonus,
190
-            "points" => $team1Points,
191
-            "netscore" => $team1Net
192
-        ];
193
-
194
-        $team[1] = [
195
-            "team" =>  $team2Name[0]['name'],
196
-            "hole1" => $team2Scores[0],
197
-            "hole2" => $team2Scores[1],
198
-            "hole3" => $team2Scores[2],
199
-            "hole4" => $team2Scores[3],
200
-            "hole5" => $team2Scores[4],
201
-            "hole6" => $team2Scores[5],
202
-            "hole7" => $team2Scores[6],
203
-            "hole8" => $team2Scores[7],
204
-            "hole9" => $team2Scores[8],
205
-            "bonus" => $team2Bonus,
206
-            "points" => $team2Points,
207
-            "netscore" => $team2Net,
208
-        ];
209
-
210
-        $data['data'] = $team;
211
-        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
+			$team1Bonus = null;
135
+			$team2Bonus = null;
136
+
137
+			if($team1Scores[8] != null && $team2Scores[8] != null){
138
+				if($team1Points > $team2Points){
139
+					$team1Points = $team1Points + 1;
140
+					$team1Bonus = 1;
141
+				}
142
+				if($team2Points > $team1Points){
143
+					$team2Points = $team2Points + 1;
144
+					$team2Bonus = 1;
145
+				}
146
+				if($team1Points == $team2Points){
147
+					$team1Points = $team1Points + .5;
148
+					$team1Bonus = .5;
149
+					$team2Points = $team2Points + .5;
150
+					$team2Bonus = .5;
151
+				}
152
+			}
153
+
154
+			//Save Points in Teammatches
155
+			Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team1Id)->update(array('pointsWon' => $team1Points));
156
+			Teammatch::where('match_id', '=', $id)->where('team_id', '=', $team2Id)->update(array('pointsWon' => $team2Points));
157
+
158
+
159
+		//Need to determine if same amount of scores are in both
160
+		// If not then do not return
161
+
162
+		foreach($team1Scores as $key=>$teamScore){
163
+			if($teamScore <= 0){
164
+				$team1Scores[$key] = '';
165
+			}
166
+		}
167
+		$team1Net = array_sum($team1Scores);
168
+
169
+
170
+		foreach($team2Scores as $key=>$teamScore){
171
+			if($teamScore <= 0){
172
+				$team2Scores[$key] = '';
173
+			}
174
+		}
175
+		$team2Net = array_sum($team2Scores);
176
+
177
+
178
+		$team[0] = [
179
+			"team" =>  $team1Name[0]['name'],
180
+			"hole1" => $team1Scores[0],
181
+			"hole2" => $team1Scores[1],
182
+			"hole3" => $team1Scores[2],
183
+			"hole4" => $team1Scores[3],
184
+			"hole5" => $team1Scores[4],
185
+			"hole6" => $team1Scores[5],
186
+			"hole7" => $team1Scores[6],
187
+			"hole8" => $team1Scores[7],
188
+			"hole9" => $team1Scores[8],
189
+			"bonus" => $team1Bonus,
190
+			"points" => $team1Points,
191
+			"netscore" => $team1Net
192
+		];
193
+
194
+		$team[1] = [
195
+			"team" =>  $team2Name[0]['name'],
196
+			"hole1" => $team2Scores[0],
197
+			"hole2" => $team2Scores[1],
198
+			"hole3" => $team2Scores[2],
199
+			"hole4" => $team2Scores[3],
200
+			"hole5" => $team2Scores[4],
201
+			"hole6" => $team2Scores[5],
202
+			"hole7" => $team2Scores[6],
203
+			"hole8" => $team2Scores[7],
204
+			"hole9" => $team2Scores[8],
205
+			"bonus" => $team2Bonus,
206
+			"points" => $team2Points,
207
+			"netscore" => $team2Net,
208
+		];
209
+
210
+		$data['data'] = $team;
211
+		return $data;
212 212
 	}
213 213
 
214
-    private function getTeamNetScore($team, $holesData)
215
-    {
216
-        foreach($team as $key=>$item){
217
-            // Create holes array for NET
218
-            $holes = array();
219
-            $i = 1;
220
-            foreach($holesData as $key=>$holeData){
221
-                $holes[$i] = $holeData->handicap;
222
-                $i++;
223
-            }
224
-
225
-            // Create stroke array - how many to take away from score
226
-            $strokeArray = [
227
-                1 => 0,
228
-                2 => 0,
229
-                3 => 0,
230
-                4 => 0,
231
-                5 => 0,
232
-                6 => 0,
233
-                7 => 0,
234
-                8 => 0,
235
-                9 => 0
236
-            ];
237
-            //Create array of strokes
238
-            for($counter = $item['matchHandicap']; $counter > 0; $counter--){
239
-                if($counter > 9){
240
-                    $newCounter = $counter - 9;
241
-                    while($newCounter > 0) {
242
-                        $strokeArray[$newCounter] = $strokeArray[$newCounter] + 1;
243
-                        $counter--;
244
-                        $newCounter--;
245
-                    }
246
-                }
247
-                $strokeArray[$counter] = $strokeArray[$counter] + 1;
248
-            }
249
-            // Plus handicaps don't hit previous loop so need its own
250
-            //Plus handicap logic
251
-
252
-            foreach($strokeArray as $strokeKey=>$stroke){
253
-                $holeKey = array_search($strokeKey,$holes);
254
-                $holes[$holeKey] = $stroke;
255
-            }
256
-
257
-            ///now have array of strokes to subtract
258
-            //get array of holescores
259
-
260
-            $holeScores = $item['holescores'];
261
-            foreach($holeScores as $key=>$holeScore){
262
-                //check if new score is less PlayerScores
263
-                if(isset($teamScores[$key])){ // 2nd time in for hole
264
-
265
-                    //set temp handi score
266
-                    $tempScore = $holeScore['score'] - $holes[$key+1];
267
-                    if($teamScores[$key] >= $tempScore){
268
-                        $teamScores[$key] = $holeScore['score'] - $holes[$key+1];
269
-                    }
270
-                } else{ // first time in for hole
271
-                    if($holeScore['score'] != null){
272
-                        $teamScores[$key] = $holeScore['score'] - $holes[$key+1];
273
-                    } else{
274
-                        $teamScores[$key] = null;
275
-                    }
276
-                }
277
-            }
278
-
279
-        }
280
-        return $teamScores;
281
-    }
282
-
283
-    private function calculatePoints($team, $opponent)
284
-    {
285
-        $points = 0;
286
-        $teamTotalPoints = 0;
287
-        $opponentTotalPoints = 0;
288
-        foreach ($team as $key=>$score){
289
-            if($score != null){
290
-                if($score < $opponent[$key]){
291
-                    $points++;
292
-                }
293
-                if($score == $opponent[$key]){
294
-                    $points = $points + .5;
295
-                }
296
-            }
297
-
298
-        }
299
-
300
-        return $points;
301
-    }
214
+	private function getTeamNetScore($team, $holesData)
215
+	{
216
+		foreach($team as $key=>$item){
217
+			// Create holes array for NET
218
+			$holes = array();
219
+			$i = 1;
220
+			foreach($holesData as $key=>$holeData){
221
+				$holes[$i] = $holeData->handicap;
222
+				$i++;
223
+			}
224
+
225
+			// Create stroke array - how many to take away from score
226
+			$strokeArray = [
227
+				1 => 0,
228
+				2 => 0,
229
+				3 => 0,
230
+				4 => 0,
231
+				5 => 0,
232
+				6 => 0,
233
+				7 => 0,
234
+				8 => 0,
235
+				9 => 0
236
+			];
237
+			//Create array of strokes
238
+			for($counter = $item['matchHandicap']; $counter > 0; $counter--){
239
+				if($counter > 9){
240
+					$newCounter = $counter - 9;
241
+					while($newCounter > 0) {
242
+						$strokeArray[$newCounter] = $strokeArray[$newCounter] + 1;
243
+						$counter--;
244
+						$newCounter--;
245
+					}
246
+				}
247
+				$strokeArray[$counter] = $strokeArray[$counter] + 1;
248
+			}
249
+			// Plus handicaps don't hit previous loop so need its own
250
+			//Plus handicap logic
251
+
252
+			foreach($strokeArray as $strokeKey=>$stroke){
253
+				$holeKey = array_search($strokeKey,$holes);
254
+				$holes[$holeKey] = $stroke;
255
+			}
256
+
257
+			///now have array of strokes to subtract
258
+			//get array of holescores
259
+
260
+			$holeScores = $item['holescores'];
261
+			foreach($holeScores as $key=>$holeScore){
262
+				//check if new score is less PlayerScores
263
+				if(isset($teamScores[$key])){ // 2nd time in for hole
264
+
265
+					//set temp handi score
266
+					$tempScore = $holeScore['score'] - $holes[$key+1];
267
+					if($teamScores[$key] >= $tempScore){
268
+						$teamScores[$key] = $holeScore['score'] - $holes[$key+1];
269
+					}
270
+				} else{ // first time in for hole
271
+					if($holeScore['score'] != null){
272
+						$teamScores[$key] = $holeScore['score'] - $holes[$key+1];
273
+					} else{
274
+						$teamScores[$key] = null;
275
+					}
276
+				}
277
+			}
278
+
279
+		}
280
+		return $teamScores;
281
+	}
282
+
283
+	private function calculatePoints($team, $opponent)
284
+	{
285
+		$points = 0;
286
+		$teamTotalPoints = 0;
287
+		$opponentTotalPoints = 0;
288
+		foreach ($team as $key=>$score){
289
+			if($score != null){
290
+				if($score < $opponent[$key]){
291
+					$points++;
292
+				}
293
+				if($score == $opponent[$key]){
294
+					$points = $points + .5;
295
+				}
296
+			}
297
+
298
+		}
299
+
300
+		return $points;
301
+	}
302 302
 
303 303
 	/**
304 304
 	 * Show the form for editing the specified resource.
@@ -336,22 +336,22 @@  discard block
 block discarded – undo
336 336
 	}
337 337
 
338 338
 	public function getPointsByYear($year)
339
-    {
340
-        $teamMatches = Teammatch::select('team_id','pointsWon')->whereYear('created_at', '=', $year)->with('team')->get();
341
-        foreach($teamMatches as $key=>$teamMatch){
342
-            $pointsData[$key]['name'] = $teamMatch['team']['name'];
343
-            $pointsData[$key]['points'] =  Teammatch::select('team_id','pointsWon')
344
-                ->where('team_id', '=', $teamMatch->team_id)
345
-                ->whereYear('created_at', '=', $year)
346
-                ->with('team')
347
-                ->sum('pointsWon');
348
-
349
-        }
350
-
351
-        $pointsData = array_map("unserialize", array_unique(array_map("serialize", $pointsData)));
352
-        $data['data'] = $pointsData;
353
-        return $data;
354
-    }
339
+	{
340
+		$teamMatches = Teammatch::select('team_id','pointsWon')->whereYear('created_at', '=', $year)->with('team')->get();
341
+		foreach($teamMatches as $key=>$teamMatch){
342
+			$pointsData[$key]['name'] = $teamMatch['team']['name'];
343
+			$pointsData[$key]['points'] =  Teammatch::select('team_id','pointsWon')
344
+				->where('team_id', '=', $teamMatch->team_id)
345
+				->whereYear('created_at', '=', $year)
346
+				->with('team')
347
+				->sum('pointsWon');
348
+
349
+		}
350
+
351
+		$pointsData = array_map("unserialize", array_unique(array_map("serialize", $pointsData)));
352
+		$data['data'] = $pointsData;
353
+		return $data;
354
+	}
355 355
 
356 356
 
357 357
 }
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
             }
@@ -134,16 +134,16 @@  discard block
 block discarded – undo
134 134
             $team1Bonus = null;
135 135
             $team2Bonus = null;
136 136
 
137
-            if($team1Scores[8] != null && $team2Scores[8] != null){
138
-                if($team1Points > $team2Points){
137
+            if ($team1Scores[8] != null && $team2Scores[8] != null) {
138
+                if ($team1Points > $team2Points) {
139 139
                     $team1Points = $team1Points + 1;
140 140
                     $team1Bonus = 1;
141 141
                 }
142
-                if($team2Points > $team1Points){
142
+                if ($team2Points > $team1Points) {
143 143
                     $team2Points = $team2Points + 1;
144 144
                     $team2Bonus = 1;
145 145
                 }
146
-                if($team1Points == $team2Points){
146
+                if ($team1Points == $team2Points) {
147 147
                     $team1Points = $team1Points + .5;
148 148
                     $team1Bonus = .5;
149 149
                     $team2Points = $team2Points + .5;
@@ -159,16 +159,16 @@  discard block
 block discarded – undo
159 159
         //Need to determine if same amount of scores are in both
160 160
         // If not then do not return
161 161
 
162
-        foreach($team1Scores as $key=>$teamScore){
163
-            if($teamScore <= 0){
162
+        foreach ($team1Scores as $key=>$teamScore) {
163
+            if ($teamScore <= 0) {
164 164
                 $team1Scores[$key] = '';
165 165
             }
166 166
         }
167 167
         $team1Net = array_sum($team1Scores);
168 168
 
169 169
 
170
-        foreach($team2Scores as $key=>$teamScore){
171
-            if($teamScore <= 0){
170
+        foreach ($team2Scores as $key=>$teamScore) {
171
+            if ($teamScore <= 0) {
172 172
                 $team2Scores[$key] = '';
173 173
             }
174 174
         }
@@ -213,11 +213,11 @@  discard block
 block discarded – undo
213 213
 
214 214
     private function getTeamNetScore($team, $holesData)
215 215
     {
216
-        foreach($team as $key=>$item){
216
+        foreach ($team as $key=>$item) {
217 217
             // Create holes array for NET
218 218
             $holes = array();
219 219
             $i = 1;
220
-            foreach($holesData as $key=>$holeData){
220
+            foreach ($holesData as $key=>$holeData) {
221 221
                 $holes[$i] = $holeData->handicap;
222 222
                 $i++;
223 223
             }
@@ -235,10 +235,10 @@  discard block
 block discarded – undo
235 235
                 9 => 0
236 236
             ];
237 237
             //Create array of strokes
238
-            for($counter = $item['matchHandicap']; $counter > 0; $counter--){
239
-                if($counter > 9){
238
+            for ($counter = $item['matchHandicap']; $counter > 0; $counter--) {
239
+                if ($counter > 9) {
240 240
                     $newCounter = $counter - 9;
241
-                    while($newCounter > 0) {
241
+                    while ($newCounter > 0) {
242 242
                         $strokeArray[$newCounter] = $strokeArray[$newCounter] + 1;
243 243
                         $counter--;
244 244
                         $newCounter--;
@@ -249,8 +249,8 @@  discard block
 block discarded – undo
249 249
             // Plus handicaps don't hit previous loop so need its own
250 250
             //Plus handicap logic
251 251
 
252
-            foreach($strokeArray as $strokeKey=>$stroke){
253
-                $holeKey = array_search($strokeKey,$holes);
252
+            foreach ($strokeArray as $strokeKey=>$stroke) {
253
+                $holeKey = array_search($strokeKey, $holes);
254 254
                 $holes[$holeKey] = $stroke;
255 255
             }
256 256
 
@@ -258,19 +258,19 @@  discard block
 block discarded – undo
258 258
             //get array of holescores
259 259
 
260 260
             $holeScores = $item['holescores'];
261
-            foreach($holeScores as $key=>$holeScore){
261
+            foreach ($holeScores as $key=>$holeScore) {
262 262
                 //check if new score is less PlayerScores
263
-                if(isset($teamScores[$key])){ // 2nd time in for hole
263
+                if (isset($teamScores[$key])) { // 2nd time in for hole
264 264
 
265 265
                     //set temp handi score
266
-                    $tempScore = $holeScore['score'] - $holes[$key+1];
267
-                    if($teamScores[$key] >= $tempScore){
268
-                        $teamScores[$key] = $holeScore['score'] - $holes[$key+1];
266
+                    $tempScore = $holeScore['score'] - $holes[$key + 1];
267
+                    if ($teamScores[$key] >= $tempScore) {
268
+                        $teamScores[$key] = $holeScore['score'] - $holes[$key + 1];
269 269
                     }
270
-                } else{ // first time in for hole
271
-                    if($holeScore['score'] != null){
272
-                        $teamScores[$key] = $holeScore['score'] - $holes[$key+1];
273
-                    } else{
270
+                } else { // first time in for hole
271
+                    if ($holeScore['score'] != null) {
272
+                        $teamScores[$key] = $holeScore['score'] - $holes[$key + 1];
273
+                    } else {
274 274
                         $teamScores[$key] = null;
275 275
                     }
276 276
                 }
@@ -285,12 +285,12 @@  discard block
 block discarded – undo
285 285
         $points = 0;
286 286
         $teamTotalPoints = 0;
287 287
         $opponentTotalPoints = 0;
288
-        foreach ($team as $key=>$score){
289
-            if($score != null){
290
-                if($score < $opponent[$key]){
288
+        foreach ($team as $key=>$score) {
289
+            if ($score != null) {
290
+                if ($score < $opponent[$key]) {
291 291
                     $points++;
292 292
                 }
293
-                if($score == $opponent[$key]){
293
+                if ($score == $opponent[$key]) {
294 294
                     $points = $points + .5;
295 295
                 }
296 296
             }
@@ -337,10 +337,10 @@  discard block
 block discarded – undo
337 337
 
338 338
 	public function getPointsByYear($year)
339 339
     {
340
-        $teamMatches = Teammatch::select('team_id','pointsWon')->whereYear('created_at', '=', $year)->with('team')->get();
341
-        foreach($teamMatches as $key=>$teamMatch){
340
+        $teamMatches = Teammatch::select('team_id', 'pointsWon')->whereYear('created_at', '=', $year)->with('team')->get();
341
+        foreach ($teamMatches as $key=>$teamMatch) {
342 342
             $pointsData[$key]['name'] = $teamMatch['team']['name'];
343
-            $pointsData[$key]['points'] =  Teammatch::select('team_id','pointsWon')
343
+            $pointsData[$key]['points'] = Teammatch::select('team_id', 'pointsWon')
344 344
                 ->where('team_id', '=', $teamMatch->team_id)
345 345
                 ->whereYear('created_at', '=', $year)
346 346
                 ->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
             }
@@ -134,16 +134,16 @@  discard block
 block discarded – undo
134 134
             $team1Bonus = null;
135 135
             $team2Bonus = null;
136 136
 
137
-            if($team1Scores[8] != null && $team2Scores[8] != null){
138
-                if($team1Points > $team2Points){
137
+            if($team1Scores[8] != null && $team2Scores[8] != null) {
138
+                if($team1Points > $team2Points) {
139 139
                     $team1Points = $team1Points + 1;
140 140
                     $team1Bonus = 1;
141 141
                 }
142
-                if($team2Points > $team1Points){
142
+                if($team2Points > $team1Points) {
143 143
                     $team2Points = $team2Points + 1;
144 144
                     $team2Bonus = 1;
145 145
                 }
146
-                if($team1Points == $team2Points){
146
+                if($team1Points == $team2Points) {
147 147
                     $team1Points = $team1Points + .5;
148 148
                     $team1Bonus = .5;
149 149
                     $team2Points = $team2Points + .5;
@@ -159,16 +159,16 @@  discard block
 block discarded – undo
159 159
         //Need to determine if same amount of scores are in both
160 160
         // If not then do not return
161 161
 
162
-        foreach($team1Scores as $key=>$teamScore){
163
-            if($teamScore <= 0){
162
+        foreach($team1Scores as $key=>$teamScore) {
163
+            if($teamScore <= 0) {
164 164
                 $team1Scores[$key] = '';
165 165
             }
166 166
         }
167 167
         $team1Net = array_sum($team1Scores);
168 168
 
169 169
 
170
-        foreach($team2Scores as $key=>$teamScore){
171
-            if($teamScore <= 0){
170
+        foreach($team2Scores as $key=>$teamScore) {
171
+            if($teamScore <= 0) {
172 172
                 $team2Scores[$key] = '';
173 173
             }
174 174
         }
@@ -213,11 +213,11 @@  discard block
 block discarded – undo
213 213
 
214 214
     private function getTeamNetScore($team, $holesData)
215 215
     {
216
-        foreach($team as $key=>$item){
216
+        foreach($team as $key=>$item) {
217 217
             // Create holes array for NET
218 218
             $holes = array();
219 219
             $i = 1;
220
-            foreach($holesData as $key=>$holeData){
220
+            foreach($holesData as $key=>$holeData) {
221 221
                 $holes[$i] = $holeData->handicap;
222 222
                 $i++;
223 223
             }
@@ -235,8 +235,8 @@  discard block
 block discarded – undo
235 235
                 9 => 0
236 236
             ];
237 237
             //Create array of strokes
238
-            for($counter = $item['matchHandicap']; $counter > 0; $counter--){
239
-                if($counter > 9){
238
+            for($counter = $item['matchHandicap']; $counter > 0; $counter--) {
239
+                if($counter > 9) {
240 240
                     $newCounter = $counter - 9;
241 241
                     while($newCounter > 0) {
242 242
                         $strokeArray[$newCounter] = $strokeArray[$newCounter] + 1;
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
             // Plus handicaps don't hit previous loop so need its own
250 250
             //Plus handicap logic
251 251
 
252
-            foreach($strokeArray as $strokeKey=>$stroke){
252
+            foreach($strokeArray as $strokeKey=>$stroke) {
253 253
                 $holeKey = array_search($strokeKey,$holes);
254 254
                 $holes[$holeKey] = $stroke;
255 255
             }
@@ -258,19 +258,21 @@  discard block
 block discarded – undo
258 258
             //get array of holescores
259 259
 
260 260
             $holeScores = $item['holescores'];
261
-            foreach($holeScores as $key=>$holeScore){
261
+            foreach($holeScores as $key=>$holeScore) {
262 262
                 //check if new score is less PlayerScores
263
-                if(isset($teamScores[$key])){ // 2nd time in for hole
263
+                if(isset($teamScores[$key])) {
264
+// 2nd time in for hole
264 265
 
265 266
                     //set temp handi score
266 267
                     $tempScore = $holeScore['score'] - $holes[$key+1];
267
-                    if($teamScores[$key] >= $tempScore){
268
+                    if($teamScores[$key] >= $tempScore) {
268 269
                         $teamScores[$key] = $holeScore['score'] - $holes[$key+1];
269 270
                     }
270
-                } else{ // first time in for hole
271
-                    if($holeScore['score'] != null){
271
+                } else {
272
+// first time in for hole
273
+                    if($holeScore['score'] != null) {
272 274
                         $teamScores[$key] = $holeScore['score'] - $holes[$key+1];
273
-                    } else{
275
+                    } else {
274 276
                         $teamScores[$key] = null;
275 277
                     }
276 278
                 }
@@ -285,12 +287,12 @@  discard block
 block discarded – undo
285 287
         $points = 0;
286 288
         $teamTotalPoints = 0;
287 289
         $opponentTotalPoints = 0;
288
-        foreach ($team as $key=>$score){
289
-            if($score != null){
290
-                if($score < $opponent[$key]){
290
+        foreach ($team as $key=>$score) {
291
+            if($score != null) {
292
+                if($score < $opponent[$key]) {
291 293
                     $points++;
292 294
                 }
293
-                if($score == $opponent[$key]){
295
+                if($score == $opponent[$key]) {
294 296
                     $points = $points + .5;
295 297
                 }
296 298
             }
@@ -336,9 +338,9 @@  discard block
 block discarded – undo
336 338
 	}
337 339
 
338 340
 	public function getPointsByYear($year)
339
-    {
341
+	{
340 342
         $teamMatches = Teammatch::select('team_id','pointsWon')->whereYear('created_at', '=', $year)->with('team')->get();
341
-        foreach($teamMatches as $key=>$teamMatch){
343
+        foreach($teamMatches as $key=>$teamMatch) {
342 344
             $pointsData[$key]['name'] = $teamMatch['team']['name'];
343 345
             $pointsData[$key]['points'] =  Teammatch::select('team_id','pointsWon')
344 346
                 ->where('team_id', '=', $teamMatch->team_id)
Please login to merge, or discard this patch.