Completed
Push — master ( 3652cb...b61055 )
by Michael
03:07
created
app/library/Classes/Statistics/LeagueStatisticsEloquent.php 1 patch
Spacing   +88 added lines, -88 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,28 +246,28 @@  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';
256
+		$date1 = $year.'-12-31';
257 257
 		$date2 = $date1 - 1;
258 258
 		$date2 .= '-01-01';
259 259
 		// Get players match scores
260 260
 		$rounds = Round::with('player')
261 261
 			->where('player_id', '=', $playerId)
262 262
 			->where('date', '<', $date1)
263
-			->where('date','>', $date2)
263
+			->where('date', '>', $date2)
264 264
 			->whereNotNull('match_id')->get();
265 265
 
266 266
 		//for each round get match handicap
267 267
 		$rounds->map(function($round)
268 268
 		{
269
-			$playerMatch = Player::find($round->player_id)->matches()->where('match_player.match_id','=', $round->match_id)->get();
270
-			foreach($playerMatch as $player){
269
+			$playerMatch = Player::find($round->player_id)->matches()->where('match_player.match_id', '=', $round->match_id)->get();
270
+			foreach ($playerMatch as $player) {
271 271
 				$handicap = $player['pivot']['handicap'];
272 272
 				$round->handicap = $handicap;
273 273
 			}
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 
293 293
 		return $rounds;
294 294
 	}
295
-	public function netScoresByPlayerTopYear($playerId,$top, $year)
295
+	public function netScoresByPlayerTopYear($playerId, $top, $year)
296 296
 	{
297 297
 		$netScores = $this->netScoresByPlayerYear($playerId, $year);
298 298
 		return $netScores->take($top);
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 		$players = Player::all();
305 305
 
306 306
 		$netScores = new \Illuminate\Support\Collection();
307
-		foreach($players as $player){
307
+		foreach ($players as $player) {
308 308
 			$netScores->push($this->netScoresByPlayer($player->id));
309 309
 		}
310 310
 		return $netScores;
@@ -316,9 +316,9 @@  discard block
 block discarded – undo
316 316
 		$players = Player::all();
317 317
 
318 318
 		$netScores = new \Illuminate\Support\Collection();
319
-		foreach($players as $player){
319
+		foreach ($players as $player) {
320 320
 			$netScore = $this->netScoresByPlayerTop($player->id, $number);
321
-			if(!$netScore->isEmpty()){
321
+			if ( ! $netScore->isEmpty()) {
322 322
 				$netScores->push($netScore);
323 323
 			}
324 324
 		}
@@ -331,20 +331,20 @@  discard block
 block discarded – undo
331 331
 		$players = Player::all();
332 332
 
333 333
 		$netScores = new \Illuminate\Support\Collection();
334
-		foreach($players as $player){
335
-			$netScores->push($this->netScoresByPlayerYear($player->id,$year));
334
+		foreach ($players as $player) {
335
+			$netScores->push($this->netScoresByPlayerYear($player->id, $year));
336 336
 		}
337 337
 		return $netScores;
338 338
 	}
339
-	public function netScoresLeagueTopYear($top,$year)
339
+	public function netScoresLeagueTopYear($top, $year)
340 340
 	{
341 341
 		//get players
342 342
 		$players = Player::all();
343 343
 
344 344
 		$netScores = new \Illuminate\Support\Collection();
345
-		foreach($players as $player){
345
+		foreach ($players as $player) {
346 346
 			$netScore = $this->netScoresByPlayerTopYear($player->id, $top, $year);
347
-			if(!$netScore->isEmpty()){
347
+			if ( ! $netScore->isEmpty()) {
348 348
 				$netScores->push($netScore);
349 349
 			}
350 350
 		}
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 		$players = Player::all();
359 359
 
360 360
 		$cumulativeNetScores = new \Illuminate\Support\Collection();
361
-		foreach($players as $player){
361
+		foreach ($players as $player) {
362 362
 			$cumulativeNetScores->push($this->netCumulativeByPlayer($player->id));
363 363
 		}
364 364
 		return $cumulativeNetScores;
@@ -369,9 +369,9 @@  discard block
 block discarded – undo
369 369
 		$players = Player::all();
370 370
 
371 371
 		$cumulativeNetScores = new \Illuminate\Support\Collection();
372
-		foreach($players as $player){
372
+		foreach ($players as $player) {
373 373
 			$netScore = $this->netCumulativeByPlayerTop($player->id, $top);
374
-			if($netScore->isEmpty() == false){
374
+			if ($netScore->isEmpty() == false) {
375 375
 				$cumulativeNetScores->push($netScore);
376 376
 			}
377 377
 		}
@@ -381,9 +381,9 @@  discard block
 block discarded – undo
381 381
 	public function netCumulativeByPlayer($playerId)
382 382
 	{
383 383
 		$netScores = $this->netScoresByPlayer($playerId);
384
-		$cumulativeNet= new \Illuminate\Support\Collection();
384
+		$cumulativeNet = new \Illuminate\Support\Collection();
385 385
 
386
-		if($netScores->count() > 0){
386
+		if ($netScores->count() > 0) {
387 387
 			$netScore = $netScores->first();
388 388
 
389 389
 			$totalNetScore = $netScores->sum('netScore');
@@ -397,9 +397,9 @@  discard block
 block discarded – undo
397 397
 	public function netCumulativeByPlayerTop($playerId, $top)
398 398
 	{
399 399
 		$netScores = $this->netScoresByPlayerTop($playerId, $top);
400
-		$cumulativeNet= new \Illuminate\Support\Collection();
400
+		$cumulativeNet = new \Illuminate\Support\Collection();
401 401
 
402
-		if($netScores->count() > 0){
402
+		if ($netScores->count() > 0) {
403 403
 			$netScore = $netScores->first();
404 404
 
405 405
 			$totalNetScore = $netScores->sum('netScore');
@@ -416,32 +416,32 @@  discard block
 block discarded – undo
416 416
 		$players = Player::all();
417 417
 
418 418
 		$cumulativeNetScores = new \Illuminate\Support\Collection();
419
-		foreach($players as $player){
420
-			$cumulativeNetScores->push($this->netCumulativeByPlayerYear($player->id,$year));
419
+		foreach ($players as $player) {
420
+			$cumulativeNetScores->push($this->netCumulativeByPlayerYear($player->id, $year));
421 421
 		}
422 422
 		return $cumulativeNetScores;
423 423
 	}
424
-	public function netCumulativeTopYear($top,$year)
424
+	public function netCumulativeTopYear($top, $year)
425 425
 	{
426 426
 		//get players
427 427
 		$players = Player::all();
428 428
 
429 429
 		$cumulativeNetScores = new \Illuminate\Support\Collection();
430
-		foreach($players as $player){
430
+		foreach ($players as $player) {
431 431
 			$netScore = $this->netCumulativeByPlayerTopYear($player->id, $top, $year);
432
-			if($netScore->isEmpty() == false){
432
+			if ($netScore->isEmpty() == false) {
433 433
 				$cumulativeNetScores->push($netScore);
434 434
 			}
435 435
 		}
436 436
 
437 437
 		return $cumulativeNetScores;
438 438
 	}
439
-	public function netCumulativeByPlayerYear($playerId,$year)
439
+	public function netCumulativeByPlayerYear($playerId, $year)
440 440
 	{
441 441
 		$netScores = $this->netScoresByPlayerYear($playerId, $year);
442
-		$cumulativeNet= new \Illuminate\Support\Collection();
442
+		$cumulativeNet = new \Illuminate\Support\Collection();
443 443
 
444
-		if($netScores->count() > 0){
444
+		if ($netScores->count() > 0) {
445 445
 			$netScore = $netScores->first();
446 446
 
447 447
 			$totalNetScore = $netScores->sum('netScore');
@@ -452,12 +452,12 @@  discard block
 block discarded – undo
452 452
 
453 453
 		return $cumulativeNet;
454 454
 	}
455
-	public function netCumulativeByPlayerTopYear($playerId,$top,$year)
455
+	public function netCumulativeByPlayerTopYear($playerId, $top, $year)
456 456
 	{
457 457
 		$netScores = $this->netScoresByPlayerTopYear($playerId, $top, $year);
458
-		$cumulativeNet= new \Illuminate\Support\Collection();
458
+		$cumulativeNet = new \Illuminate\Support\Collection();
459 459
 
460
-		if($netScores->count() > 0){
460
+		if ($netScores->count() > 0) {
461 461
 			$netScore = $netScores->first();
462 462
 
463 463
 			$totalNetScore = $netScores->sum('netScore');
Please login to merge, or discard this patch.