Completed
Push — master ( 4cfbbb...f01b2c )
by Michael
03:02
created
app/library/Classes/Statistics/LeagueStatisticsEloquent.php 1 patch
Spacing   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -12,12 +12,12 @@  discard block
 block discarded – undo
12 12
 {
13 13
     public function topFiveLowestScores()
14 14
     {
15
-        return Round::with('player','course')->orderBy('score')->take(5)->get();
15
+        return Round::with('player', 'course')->orderBy('score')->take(5)->get();
16 16
     }
17 17
     public function topFiveLowestScoresByYear($year)
18 18
     {
19
-        $date1 = $year . '-01-01';
20
-        $date2 = $year . '-12-31';
19
+        $date1 = $year.'-01-01';
20
+        $date2 = $year.'-12-31';
21 21
         return Round::with('player', 'course')
22 22
             ->where('match_id', '>', '0')
23 23
             ->where('date', '>=', $date1)
@@ -31,23 +31,23 @@  discard block
 block discarded – undo
31 31
         //Get players
32 32
         //For each player where match > 0 select scores and average them
33 33
         //Store in players array
34
-        $date1 = $year . '-01-01';
35
-        $date2 = $year . '-12-31';
34
+        $date1 = $year.'-01-01';
35
+        $date2 = $year.'-12-31';
36 36
         $players = Player::all();
37 37
         $average = array();
38 38
         $i = 0;
39
-        foreach($players as $key => $player) {
39
+        foreach ($players as $key => $player) {
40 40
             $rounds = Round::where('match_id', '>', '0')
41 41
                 ->where('player_id', '=', $player->id)
42 42
                 ->where('date', '>=', $date1)
43 43
                 ->where('date', '<=', $date2)
44 44
                 ->get();
45 45
             $scores = array();
46
-			foreach($rounds as $round) {
46
+			foreach ($rounds as $round) {
47 47
 				$scores[] = $round->score;
48 48
 			}
49
-            if(count($scores) > 0) {
50
-                $average[$i]['average'] = round((array_sum($scores) / count($scores)) ,2);
49
+            if (count($scores) > 0) {
50
+                $average[$i]['average'] = round((array_sum($scores) / count($scores)), 2);
51 51
                 $average[$i]['player_id'] = $player->id;
52 52
                 $average[$i]['name'] = $player->name;
53 53
                 $average[$i]['rounds'] = count($scores);
@@ -59,26 +59,26 @@  discard block
 block discarded – undo
59 59
     }
60 60
     public function topFiveNetScoresByYear($year)
61 61
     {
62
-		$date1 = $year . '-01-01';
63
-		$date2 = $year . '-12-31';
62
+		$date1 = $year.'-01-01';
63
+		$date2 = $year.'-12-31';
64 64
 
65
-		return Netwinner::with('player','match','match.course')
65
+		return Netwinner::with('player', 'match', 'match.course')
66 66
 				->where('created_at', '>=', $date1)
67 67
 				->where('created_at', '<=', $date2)
68 68
 				->orderBy('score')->take(5)->get();
69 69
     }
70 70
     public function mostSkinsByYear($year)
71 71
     {
72
-        $year = $year . '-01-01';
72
+        $year = $year.'-01-01';
73 73
         $players = Player::all();
74 74
         $i = 0;
75 75
         $skinsCount = array();
76
-        foreach($players as $key => $player) {
77
-            $skins = Skin::with('player','level')
76
+        foreach ($players as $key => $player) {
77
+            $skins = Skin::with('player', 'level')
78 78
                 ->where('player_id', '=', $player->id)
79 79
                 ->where('created_at', '>', $year)
80 80
                 ->get();
81
-            if(count($skins) > 0) {
81
+            if (count($skins) > 0) {
82 82
                 $skinsCount[$i]['skins'] = $skins->count();
83 83
                 $skinsCount[$i]['name'] = $player->name;
84 84
                 $i++;
@@ -87,66 +87,66 @@  discard block
 block discarded – undo
87 87
         array_multisort($skinsCount, SORT_DESC);
88 88
         return $skinsCount;
89 89
     }
90
-    public function totalEagles($year){}
90
+    public function totalEagles($year) {}
91 91
     public function totalBirdies($year)
92 92
 	{
93
-		$year = $year . '-01-01';
94
-		$holescores = Holescore::with('round.player','hole')
93
+		$year = $year.'-01-01';
94
+		$holescores = Holescore::with('round.player', 'hole')
95 95
 			->where('created_at', '>', $year)
96 96
 			->get();
97 97
 		$allBirdies = array();
98
-		foreach($holescores as $key => $holescore) {
99
-			if($holescore['round']['match_id'] != null){
100
-				if( ($holescore['hole']['par'] - $holescore['score']) === 1) {
101
-						$allBirdies[]= $holescore['round']['player']['name'];
98
+		foreach ($holescores as $key => $holescore) {
99
+			if ($holescore['round']['match_id'] != null) {
100
+				if (($holescore['hole']['par'] - $holescore['score']) === 1) {
101
+						$allBirdies[] = $holescore['round']['player']['name'];
102 102
 				}
103 103
 			}
104 104
 		}
105
-		$i =0;
105
+		$i = 0;
106 106
 		$newArray = array_count_values($allBirdies);
107 107
 			$birds = array();
108 108
 			foreach ($newArray as $key => $value) {
109 109
 				$birds[$i]['name'] = $key;
110
-				$birds[$i]['birds'] =$value;
110
+				$birds[$i]['birds'] = $value;
111 111
 				$i++;
112 112
 			}
113 113
 			return $birds;
114 114
 	}
115 115
     public function totalPars($year)
116 116
 	{
117
-		$year = $year . '-01-01';
118
-		$holescores = Holescore::with('round.player','hole')
117
+		$year = $year.'-01-01';
118
+		$holescores = Holescore::with('round.player', 'hole')
119 119
 			->where('created_at', '>', $year)
120 120
 			->get();
121 121
 		$allPars = array();
122
-		foreach($holescores as $key => $holescore) {
123
-			if($holescore['round']['match_id'] != null){
124
-				if( ($holescore['hole']['par'] - $holescore['score']) === 0) {
125
-						$allPars[]= $holescore['round']['player']['name'];
122
+		foreach ($holescores as $key => $holescore) {
123
+			if ($holescore['round']['match_id'] != null) {
124
+				if (($holescore['hole']['par'] - $holescore['score']) === 0) {
125
+						$allPars[] = $holescore['round']['player']['name'];
126 126
 				}
127 127
 			}
128 128
 		}
129
-		$i =0;
129
+		$i = 0;
130 130
 		$newArray = array_count_values($allPars);
131 131
 			$pars = array();
132 132
 			foreach ($newArray as $key => $value) {
133 133
 				$pars[$i]['name'] = $key;
134
-				$pars[$i]['pars'] =$value;
134
+				$pars[$i]['pars'] = $value;
135 135
 				$i++;
136 136
 			}
137 137
 			return $pars;
138 138
 	}
139 139
     public function totalBogeys($year)
140 140
 	{
141
-		$year = $year . '-01-01';
142
-		$holescores = Holescore::with('round.player','hole')
141
+		$year = $year.'-01-01';
142
+		$holescores = Holescore::with('round.player', 'hole')
143 143
 			->where('created_at', '>', $year)
144 144
 			->get();
145 145
 		$allBogeys = array();
146
-		foreach($holescores as $key => $holescore) {
147
-			if($holescore['round']['match_id'] != null){
148
-				if( ($holescore['score'] - $holescore['hole']['par']) === 1) {
149
-						$allBogeys[]= $holescore['round']['player']['name'];
146
+		foreach ($holescores as $key => $holescore) {
147
+			if ($holescore['round']['match_id'] != null) {
148
+				if (($holescore['score'] - $holescore['hole']['par']) === 1) {
149
+						$allBogeys[] = $holescore['round']['player']['name'];
150 150
 				}
151 151
 			}
152 152
 		}
@@ -155,22 +155,22 @@  discard block
 block discarded – undo
155 155
 		$bogeys = array();
156 156
 			foreach ($newArray as $key => $value) {
157 157
 				$bogeys[$i]['name'] = $key;
158
-				$bogeys[$i]['bogeys'] =$value;
158
+				$bogeys[$i]['bogeys'] = $value;
159 159
 				$i++;
160 160
 			}
161 161
 		return $bogeys;
162 162
 	}
163 163
     public function totalDoubles($year)
164 164
 	{
165
-		$year = $year . '-01-01';
166
-		$holescores = Holescore::with('round.player','hole')
165
+		$year = $year.'-01-01';
166
+		$holescores = Holescore::with('round.player', 'hole')
167 167
 			->where('created_at', '>', $year)
168 168
 			->get();
169 169
 		$allDoubles = array();
170
-		foreach($holescores as $key => $holescore) {
171
-			if($holescore['round']['match_id'] != null){
172
-				if( ($holescore['score'] - $holescore['hole']['par']) === 2) {
173
-						$allDoubles[]= $holescore['round']['player']['name'];
170
+		foreach ($holescores as $key => $holescore) {
171
+			if ($holescore['round']['match_id'] != null) {
172
+				if (($holescore['score'] - $holescore['hole']['par']) === 2) {
173
+						$allDoubles[] = $holescore['round']['player']['name'];
174 174
 				}
175 175
 			}
176 176
 		}
@@ -179,22 +179,22 @@  discard block
 block discarded – undo
179 179
 			$doubles = array();
180 180
 			foreach ($newArray as $key => $value) {
181 181
 				$doubles[$i]['name'] = $key;
182
-				$doubles[$i]['doubles'] =$value;
182
+				$doubles[$i]['doubles'] = $value;
183 183
 				$i++;
184 184
 			}
185 185
 		return $doubles;
186 186
 	}
187 187
     public function totalOthers($year)
188 188
 	{
189
-		$year = $year . '-01-01';
190
-		$holescores = Holescore::with('round.player','hole')
189
+		$year = $year.'-01-01';
190
+		$holescores = Holescore::with('round.player', 'hole')
191 191
 			->where('created_at', '>', $year)
192 192
 			->get();
193 193
 		$allOthers = array();
194
-		foreach($holescores as $key => $holescore) {
195
-			if($holescore['round']['match_id'] != null){
196
-				if( ($holescore['score'] - $holescore['hole']['par']) > 2) {
197
-					$allOthers[]= $holescore['round']['player']['name'];
194
+		foreach ($holescores as $key => $holescore) {
195
+			if ($holescore['round']['match_id'] != null) {
196
+				if (($holescore['score'] - $holescore['hole']['par']) > 2) {
197
+					$allOthers[] = $holescore['round']['player']['name'];
198 198
 				}
199 199
 			}
200 200
 		}
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 		$others = array();
204 204
 			foreach ($newArray as $key => $value) {
205 205
 				$others[$i]['name'] = $key;
206
-				$others[$i]['others'] =$value;
206
+				$others[$i]['others'] = $value;
207 207
 				$i++;
208 208
 			}
209 209
 		return $others;
@@ -219,8 +219,8 @@  discard block
 block discarded – undo
219 219
 		//for each round get match handicap
220 220
 		$rounds->map(function($round)
221 221
 		{
222
-			$playerMatch = Player::find($round->player_id)->matches()->where('match_player.match_id','=', $round->match_id)->get();
223
-			foreach($playerMatch as $player){
222
+			$playerMatch = Player::find($round->player_id)->matches()->where('match_player.match_id', '=', $round->match_id)->get();
223
+			foreach ($playerMatch as $player) {
224 224
 				$handicap = $player['pivot']['handicap'];
225 225
 				$round->handicap = $handicap;
226 226
 			}
@@ -246,15 +246,15 @@  discard block
 block discarded – undo
246 246
 		return $rounds;
247 247
 
248 248
 	}
249
-	public function netScoresByPlayerTop($playerId,$top)
249
+	public function netScoresByPlayerTop($playerId, $top)
250 250
 	{
251 251
 		$netScores = $this->netScoresByPlayer($playerId);
252 252
 		return $netScores->take($top);
253 253
 	}
254 254
 	public function netScoresByPlayerYear($playerId, $year)
255 255
 	{
256
-		$date1 = $year . '-12-31';
257
-		$date2 = $year . '-01-01';
256
+		$date1 = $year.'-12-31';
257
+		$date2 = $year.'-01-01';
258 258
 		//$date2 = $date1 - 1;
259 259
 		//$date2 .= '-01-01';
260 260
 
@@ -263,14 +263,14 @@  discard block
 block discarded – undo
263 263
 		$rounds = Round::with('player')
264 264
 			->where('player_id', '=', $playerId)
265 265
 			->where('date', '<', $date1)
266
-			->where('date','>', $date2)
266
+			->where('date', '>', $date2)
267 267
 			->whereNotNull('match_id')->get();
268 268
 
269 269
 		//for each round get match handicap
270 270
 		$rounds->map(function($round)
271 271
 		{
272
-			$playerMatch = Player::find($round->player_id)->matches()->where('match_player.match_id','=', $round->match_id)->get();
273
-			foreach($playerMatch as $player){
272
+			$playerMatch = Player::find($round->player_id)->matches()->where('match_player.match_id', '=', $round->match_id)->get();
273
+			foreach ($playerMatch as $player) {
274 274
 				$handicap = $player['pivot']['handicap'];
275 275
 				$round->handicap = $handicap;
276 276
 			}
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 
296 296
 		return $rounds;
297 297
 	}
298
-	public function netScoresByPlayerTopYear($playerId,$top, $year)
298
+	public function netScoresByPlayerTopYear($playerId, $top, $year)
299 299
 	{
300 300
 		$netScores = $this->netScoresByPlayerYear($playerId, $year);
301 301
 		return $netScores->take($top);
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 		$players = Player::all();
308 308
 
309 309
 		$netScores = new \Illuminate\Support\Collection();
310
-		foreach($players as $player){
310
+		foreach ($players as $player) {
311 311
 			$netScores->push($this->netScoresByPlayer($player->id));
312 312
 		}
313 313
 		return $netScores;
@@ -319,9 +319,9 @@  discard block
 block discarded – undo
319 319
 		$players = Player::all();
320 320
 
321 321
 		$netScores = new \Illuminate\Support\Collection();
322
-		foreach($players as $player){
322
+		foreach ($players as $player) {
323 323
 			$netScore = $this->netScoresByPlayerTop($player->id, $number);
324
-			if(!$netScore->isEmpty()){
324
+			if ( ! $netScore->isEmpty()) {
325 325
 				$netScores->push($netScore);
326 326
 			}
327 327
 		}
@@ -334,20 +334,20 @@  discard block
 block discarded – undo
334 334
 		$players = Player::all();
335 335
 
336 336
 		$netScores = new \Illuminate\Support\Collection();
337
-		foreach($players as $player){
338
-			$netScores->push($this->netScoresByPlayerYear($player->id,$year));
337
+		foreach ($players as $player) {
338
+			$netScores->push($this->netScoresByPlayerYear($player->id, $year));
339 339
 		}
340 340
 		return $netScores;
341 341
 	}
342
-	public function netScoresLeagueTopYear($top,$year)
342
+	public function netScoresLeagueTopYear($top, $year)
343 343
 	{
344 344
 		//get players
345 345
 		$players = Player::all();
346 346
 
347 347
 		$netScores = new \Illuminate\Support\Collection();
348
-		foreach($players as $player){
348
+		foreach ($players as $player) {
349 349
 			$netScore = $this->netScoresByPlayerTopYear($player->id, $top, $year);
350
-			if(!$netScore->isEmpty()){
350
+			if ( ! $netScore->isEmpty()) {
351 351
 				$netScores->push($netScore);
352 352
 			}
353 353
 		}
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 		$players = Player::all();
362 362
 
363 363
 		$cumulativeNetScores = new \Illuminate\Support\Collection();
364
-		foreach($players as $player){
364
+		foreach ($players as $player) {
365 365
 			$cumulativeNetScores->push($this->netCumulativeByPlayer($player->id));
366 366
 		}
367 367
 		return $cumulativeNetScores;
@@ -372,9 +372,9 @@  discard block
 block discarded – undo
372 372
 		$players = Player::all();
373 373
 
374 374
 		$cumulativeNetScores = new \Illuminate\Support\Collection();
375
-		foreach($players as $player){
375
+		foreach ($players as $player) {
376 376
 			$netScore = $this->netCumulativeByPlayerTop($player->id, $top);
377
-			if($netScore->isEmpty() == false){
377
+			if ($netScore->isEmpty() == false) {
378 378
 				$cumulativeNetScores->push($netScore);
379 379
 			}
380 380
 		}
@@ -384,9 +384,9 @@  discard block
 block discarded – undo
384 384
 	public function netCumulativeByPlayer($playerId)
385 385
 	{
386 386
 		$netScores = $this->netScoresByPlayer($playerId);
387
-		$cumulativeNet= new \Illuminate\Support\Collection();
387
+		$cumulativeNet = new \Illuminate\Support\Collection();
388 388
 
389
-		if($netScores->count() > 0){
389
+		if ($netScores->count() > 0) {
390 390
 			$netScore = $netScores->first();
391 391
 
392 392
 			$totalNetScore = $netScores->sum('netScore');
@@ -400,9 +400,9 @@  discard block
 block discarded – undo
400 400
 	public function netCumulativeByPlayerTop($playerId, $top)
401 401
 	{
402 402
 		$netScores = $this->netScoresByPlayerTop($playerId, $top);
403
-		$cumulativeNet= new \Illuminate\Support\Collection();
403
+		$cumulativeNet = new \Illuminate\Support\Collection();
404 404
 
405
-		if($netScores->count() > 0){
405
+		if ($netScores->count() > 0) {
406 406
 			$netScore = $netScores->first();
407 407
 
408 408
 			$totalNetScore = $netScores->sum('netScore');
@@ -419,32 +419,32 @@  discard block
 block discarded – undo
419 419
 		$players = Player::all();
420 420
 
421 421
 		$cumulativeNetScores = new \Illuminate\Support\Collection();
422
-		foreach($players as $player){
423
-			$cumulativeNetScores->push($this->netCumulativeByPlayerYear($player->id,$year));
422
+		foreach ($players as $player) {
423
+			$cumulativeNetScores->push($this->netCumulativeByPlayerYear($player->id, $year));
424 424
 		}
425 425
 		return $cumulativeNetScores;
426 426
 	}
427
-	public function netCumulativeTopYear($top,$year)
427
+	public function netCumulativeTopYear($top, $year)
428 428
 	{
429 429
 		//get players
430 430
 		$players = Player::all();
431 431
 
432 432
 		$cumulativeNetScores = new \Illuminate\Support\Collection();
433
-		foreach($players as $player){
433
+		foreach ($players as $player) {
434 434
 			$netScore = $this->netCumulativeByPlayerTopYear($player->id, $top, $year);
435
-			if($netScore->isEmpty() == false){
435
+			if ($netScore->isEmpty() == false) {
436 436
 				$cumulativeNetScores->push($netScore);
437 437
 			}
438 438
 		}
439 439
 
440 440
 		return $cumulativeNetScores;
441 441
 	}
442
-	public function netCumulativeByPlayerYear($playerId,$year)
442
+	public function netCumulativeByPlayerYear($playerId, $year)
443 443
 	{
444 444
 		$netScores = $this->netScoresByPlayerYear($playerId, $year);
445
-		$cumulativeNet= new \Illuminate\Support\Collection();
445
+		$cumulativeNet = new \Illuminate\Support\Collection();
446 446
 
447
-		if($netScores->count() > 0){
447
+		if ($netScores->count() > 0) {
448 448
 			$netScore = $netScores->first();
449 449
 
450 450
 			$totalNetScore = $netScores->sum('netScore');
@@ -455,12 +455,12 @@  discard block
 block discarded – undo
455 455
 
456 456
 		return $cumulativeNet;
457 457
 	}
458
-	public function netCumulativeByPlayerTopYear($playerId,$top,$year)
458
+	public function netCumulativeByPlayerTopYear($playerId, $top, $year)
459 459
 	{
460 460
 		$netScores = $this->netScoresByPlayerTopYear($playerId, $top, $year);
461
-		$cumulativeNet= new \Illuminate\Support\Collection();
461
+		$cumulativeNet = new \Illuminate\Support\Collection();
462 462
 
463
-		if($netScores->count() > 0){
463
+		if ($netScores->count() > 0) {
464 464
 			$netScore = $netScores->first();
465 465
 
466 466
 			$totalNetScore = $netScores->sum('netScore');
Please login to merge, or discard this patch.