Completed
Push — master ( 681b35...6327cf )
by Michael
02:56
created
app/library/Services/MatchService.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -286,7 +286,7 @@
 block discarded – undo
286 286
     /**
287 287
      * Method to get match from input Match data
288 288
      *
289
-     * @param mixed $matchdata
289
+     * @param mixed $matchid
290 290
      * @return JSON object
291 291
      */
292 292
     public function get($matchid)
Please login to merge, or discard this patch.
Indentation   +274 added lines, -274 removed lines patch added patch discarded remove patch
@@ -19,279 +19,279 @@
 block discarded – undo
19 19
  */
20 20
 class MatchService
21 21
 {
22
-    // Containing our matchRepository to make all our database calls to
23
-    protected $matchRepo;
24
-
25
-    /**
26
-     * Loads our $matchRepo
27
-     *
28
-     * @param MatchRepository $matchRepo
29
-     * @return MatchService
30
-     */
31
-    public function __construct(MatchRoundRepository $matchRoundRepo,
32
-                                MatchRepository $matchRepo,
33
-                                PrizeMoney $prizeMoney,
34
-                                Player $player,
35
-                                Match $match,
36
-                                CtpRepository $ctp,
37
-                                Dispatcher $events,
38
-                                Purse $purse)
39
-    {
40
-        $this->matchRoundRepo = $matchRoundRepo;
41
-        $this->matchRepo = $matchRepo;
42
-        $this->prizeMoney = $prizeMoney;
43
-        $this->player = $player;
44
-        $this->match = $match;
45
-        $this->ctp = $ctp;
46
-        $this->events = $events;
47
-        $this->purse = $purse;
48
-    }
49
-
50
-    /**
51
-     * Method to create match from input Match data
52
-     *
53
-     * @param mixed $matchdata
54
-     * @return
55
-     */
56
-    public function create($matchdata)
57
-    {
58
-
59
-        //calculate money with purse
60
-        $this->purse->setPurse($matchdata['purse']);
61
-        echo $this->purse->getPurse();  exit();
62
-        $this->prizeMoney->setPurse($matchdata['purse']);
63
-
64
-
65
-        $matchdata['purse'] = number_format($matchdata['purse'], 2);
66
-        $matchdata['grossmoney'] = $this->prizeMoney->getlowScore();
67
-        $matchdata['netmoney'] = $this->prizeMoney->getlowScore();
68
-
69
-        //How many A and B players
70
-        $totalPlayers = 0;
71
-
72
-        $aPlayerCount = 0;
22
+	// Containing our matchRepository to make all our database calls to
23
+	protected $matchRepo;
24
+
25
+	/**
26
+	 * Loads our $matchRepo
27
+	 *
28
+	 * @param MatchRepository $matchRepo
29
+	 * @return MatchService
30
+	 */
31
+	public function __construct(MatchRoundRepository $matchRoundRepo,
32
+								MatchRepository $matchRepo,
33
+								PrizeMoney $prizeMoney,
34
+								Player $player,
35
+								Match $match,
36
+								CtpRepository $ctp,
37
+								Dispatcher $events,
38
+								Purse $purse)
39
+	{
40
+		$this->matchRoundRepo = $matchRoundRepo;
41
+		$this->matchRepo = $matchRepo;
42
+		$this->prizeMoney = $prizeMoney;
43
+		$this->player = $player;
44
+		$this->match = $match;
45
+		$this->ctp = $ctp;
46
+		$this->events = $events;
47
+		$this->purse = $purse;
48
+	}
49
+
50
+	/**
51
+	 * Method to create match from input Match data
52
+	 *
53
+	 * @param mixed $matchdata
54
+	 * @return
55
+	 */
56
+	public function create($matchdata)
57
+	{
58
+
59
+		//calculate money with purse
60
+		$this->purse->setPurse($matchdata['purse']);
61
+		echo $this->purse->getPurse();  exit();
62
+		$this->prizeMoney->setPurse($matchdata['purse']);
63
+
64
+
65
+		$matchdata['purse'] = number_format($matchdata['purse'], 2);
66
+		$matchdata['grossmoney'] = $this->prizeMoney->getlowScore();
67
+		$matchdata['netmoney'] = $this->prizeMoney->getlowScore();
68
+
69
+		//How many A and B players
70
+		$totalPlayers = 0;
71
+
72
+		$aPlayerCount = 0;
73 73
         
74
-        $bPlayerCount = 0;
75
-        foreach($matchdata['player'] as $player){
76
-            if ($player['level_id'] == '1'){
77
-                $aPlayerCount++;
78
-            }
79
-            else {
80
-                $bPlayerCount++;
81
-            }
82
-            $totalPlayers++;
83
-        }
84
-
85
-        //Calculate Skins money based on how many players in each group
86
-
87
-        $matchdata['skinsamoney'] = $this->prizeMoney->skinsGroupPot($matchdata['purse'], $totalPlayers, $aPlayerCount);
88
-        $matchdata['skinsbmoney'] = $this->prizeMoney->skinsGroupPot($matchdata['purse'], $totalPlayers, $bPlayerCount);
89
-        //check for carry over money and if there is add it to skins money
90
-        $carryOver = new CarryOver;
91
-        $carryOverMoney = $carryOver->calculate();
92
-        $matchdata['skinsamoney'] +=  $carryOverMoney[1];
93
-        $matchdata['skinsbmoney'] +=  $carryOverMoney[2];
94
-
95
-        //append current handicap and set winnings to 0 for each player
96
-        foreach ($matchdata['player'] as $key=>$player) {
97
-            //get each player's current handicap
98
-            $currentPlayer = $this->player->find($player['player_id']);
99
-            $matchdata['player'][$key]['handicap'] = $currentPlayer->handicap;
100
-            $matchdata['player'][$key]['winnings'] = 0;
101
-        }// End foreach
102
-
103
-        $matchid = $this->matchRepo->create($matchdata);
104
-        $matchdata['match_id'] = $matchid;
105
-        $this->events->fire('match.create', array($matchdata));
106
-    }
107
-
108
-    public function finalize($matchdata)
109
-    {
110
-        // post CTP1 and CTP2
111
-        $ctp1 = array(
112
-            'match_id' => $matchdata['match'],
113
-            'player_id' => $matchdata['ctp1'],
114
-            'hole_id' => $matchdata['ctp1hole'],
115
-            'money' => $this->prizeMoney->getCtp()
116
-        );
117
-        $this->ctp->create($ctp1);
118
-        $ctp2 = array(
119
-            'match_id' => $matchdata['match'],
120
-            'player_id' => $matchdata['ctp2'],
121
-            'hole_id' => $matchdata['ctp2hole'],
122
-            'money' => $this->prizeMoney->getCtp()
123
-        );
124
-        $this->ctp->create($ctp2);
125
-
126
-        //calculate Gross winner and post to grossWinnersTable
127
-
128
-        $matchRound = $this->matchRoundRepo->getByMatch($matchdata['match']);
129
-
130
-
131
-        $lowGross = array();
132
-        foreach ($matchRound as $key => $match){
133
-            $lowGross[$match['player']->id] = $match['score'];
134
-        }
135
-        $arrayLowGross = array_keys($lowGross, min($lowGross));
136
-        foreach($arrayLowGross as $key => $lowgrossPlayer) {
137
-            $grossWinner = new Grosswinner;
138
-            $grossWinner->player_id = $lowgrossPlayer;
139
-            $grossWinner->match_id = $matchdata['match'];
140
-            $grossWinner->score = $lowGross[$lowgrossPlayer];
141
-            $grossWinner->money = $this->prizeMoney->getlowScore() / count($arrayLowGross);
142
-            $grossWinner->save();
143
-        }
144
-
145
-        //Calculate NET winner
146
-        $lowNet = array();
147
-        $scores =array();
148
-        foreach ($matchRound as $key => $match){
149
-            $netScore = ($match['score'] - round($match['player']->handicap,0)); //calculate net score
150
-            $lowNet[$match['player']->id] = $netScore;
151
-        }
152
-        $arrayLowNet = array_keys($lowNet, min($lowNet));
153
-
154
-        foreach($arrayLowNet as $key => $lownetPlayer) {
155
-            $netWinner = new Netwinner;
156
-            $netWinner->player_id = $lownetPlayer;
157
-            $netWinner->match_id = $matchdata['match'];
158
-            $netWinner->score = $lowNet[$lownetPlayer];
159
-            $netWinner->money = $this->prizeMoney->getlowScore() /  count($arrayLowNet);
160
-            $netWinner->save();
161
-        }
162
-
163
-        //Calculate Skins
164
-
165
-        //determine A and B players
166
-        //using pivot table match_player
167
-        $match = $this->match->find($matchdata['match']);
168
-        $aPlayers = array();
169
-        $bPlayers = array();
170
-        foreach($match->players as $player)
171
-        {
172
-            if($player->pivot->level_id == 1){
173
-                $aPlayers[] = $player->pivot->player_id;
174
-
175
-            }
176
-            if($player->pivot->level_id == 2){
177
-                $bPlayers[] = $player->pivot->player_id;
178
-            }
179
-        }
180
-
181
-        //Create Skins arrays
182
-        //player_id, 'holescores'
183
-        foreach($matchRound as $key => $round) {
184
-            if (in_array($round->player_id,$aPlayers)){
185
-                $aPlayersSkins[$key]['player_id'] = $round->player_id;
186
-                $aPlayersSkins[$key]['holescores'] = $round->holescores;
187
-            }
188
-            if (in_array($round->player_id,$bPlayers)){
189
-                $bPlayersSkins[$key]['player_id'] = $round->player_id;
190
-                $bPlayersSkins[$key]['holescores'] = $round->holescores;
191
-            }
192
-        }
193
-
194
-        //Run A Skins analysis
195
-        $scores = array();
196
-        foreach($aPlayersSkins as $key => $playerSkin){
197
-            foreach($playerSkin['holescores'] as $hole => $holescore){
198
-                $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score'];
199
-            }
200
-        }
201
-
202
-        foreach($scores as $hole_id => $hole) {
203
-            $minScore = min($hole);
204
-            $winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score
205
-        }
206
-        $aSkinsWon = 0;
207
-        foreach($winners as $key => $winner) {
208
-            if(count($winner)  ===  1) {
209
-                //post to DB
210
-                $skinWinner = new Skin;
211
-                $skinWinner->player_id = $winner[0];
212
-                $skinWinner->level_id = 1;
213
-                $skinWinner->match_id = intval($matchdata['match']);
214
-                $skinWinner->hole_id = $key;
215
-                $skinWinner->save();
216
-                $aSkinsWon++;
217
-            }
218
-        }
219
-
220
-        //Run B Skins analysis
221
-        $scores = array();
222
-        foreach($bPlayersSkins as $key => $playerSkin){
223
-            foreach($playerSkin['holescores'] as $hole => $holescore){
224
-                $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score'];
225
-            }
226
-        }
227
-
228
-        foreach($scores as $hole_id => $hole) {
229
-            $minScore = min($hole);
230
-            $winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score
231
-        }
232
-        $bSkinsWon = 0;
233
-        foreach($winners as $key => $winner) {
234
-            if(count($winner)  ===  1) {
235
-                //post to DB
236
-                $skinWinner = new Skin;
237
-                $skinWinner->player_id = $winner[0];
238
-                $skinWinner->level_id = 2;
239
-                $skinWinner->match_id = intval($matchdata['match']);
240
-                $skinWinner->hole_id = $key;
241
-                $skinWinner->save();
242
-                $bSkinsWon++;
243
-            }
244
-        }
245
-
246
-        $match =  Match::find($matchdata['match']);
247
-
248
-        //Need to add Carry over money if there no skins are won
249
-        //check for carry over money
250
-        $skinsamoney = $match->skinsamoney; // + carryover A money if any
251
-        $skinsbmoney = $match->skinsbmoney; // + carryover B money if any
252
-
253
-        if($aSkinsWon > 0) {
254
-            $moneyperskinA = $skinsamoney / $aSkinsWon;
255
-
256
-            $aSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 1)->get();
257
-            foreach ($aSkins as $askin){
258
-                $askin->money = $moneyperskinA;
259
-                $askin->save();
260
-            }
261
-        }
262
-
263
-        if($bSkinsWon > 0) {
264
-            $moneyperskinB = $skinsbmoney / $bSkinsWon;
265
-
266
-            $bSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 2)->get();
267
-            foreach ($bSkins as $bskin){
268
-                $bskin->money = $moneyperskinB;
269
-                $bskin->save();
270
-            }
271
-        }
272
-        //foreach player in pivot table create player and run handicap analysis
273
-        foreach($match->players as $matchplayer)
274
-        {
275
-            $player = Player::find($matchplayer->pivot->player_id);
276
-            $handicap = new Handicap($player);
277
-            $player->handicap = $handicap->calculate();
278
-            $player->save();
279
-        }
280
-
281
-        //Fire event to calculate money won and add to pivot table match_player
282
-        $this->events->fire('match.finalize', $match);
283
-
284
-    }
285
-
286
-    /**
287
-     * Method to get match from input Match data
288
-     *
289
-     * @param mixed $matchdata
290
-     * @return JSON object
291
-     */
292
-    public function get($matchid)
293
-    {
294
-        $matchdata =  $this->matchRepo->get($matchid);
295
-        return $matchdata;
296
-    }
74
+		$bPlayerCount = 0;
75
+		foreach($matchdata['player'] as $player){
76
+			if ($player['level_id'] == '1'){
77
+				$aPlayerCount++;
78
+			}
79
+			else {
80
+				$bPlayerCount++;
81
+			}
82
+			$totalPlayers++;
83
+		}
84
+
85
+		//Calculate Skins money based on how many players in each group
86
+
87
+		$matchdata['skinsamoney'] = $this->prizeMoney->skinsGroupPot($matchdata['purse'], $totalPlayers, $aPlayerCount);
88
+		$matchdata['skinsbmoney'] = $this->prizeMoney->skinsGroupPot($matchdata['purse'], $totalPlayers, $bPlayerCount);
89
+		//check for carry over money and if there is add it to skins money
90
+		$carryOver = new CarryOver;
91
+		$carryOverMoney = $carryOver->calculate();
92
+		$matchdata['skinsamoney'] +=  $carryOverMoney[1];
93
+		$matchdata['skinsbmoney'] +=  $carryOverMoney[2];
94
+
95
+		//append current handicap and set winnings to 0 for each player
96
+		foreach ($matchdata['player'] as $key=>$player) {
97
+			//get each player's current handicap
98
+			$currentPlayer = $this->player->find($player['player_id']);
99
+			$matchdata['player'][$key]['handicap'] = $currentPlayer->handicap;
100
+			$matchdata['player'][$key]['winnings'] = 0;
101
+		}// End foreach
102
+
103
+		$matchid = $this->matchRepo->create($matchdata);
104
+		$matchdata['match_id'] = $matchid;
105
+		$this->events->fire('match.create', array($matchdata));
106
+	}
107
+
108
+	public function finalize($matchdata)
109
+	{
110
+		// post CTP1 and CTP2
111
+		$ctp1 = array(
112
+			'match_id' => $matchdata['match'],
113
+			'player_id' => $matchdata['ctp1'],
114
+			'hole_id' => $matchdata['ctp1hole'],
115
+			'money' => $this->prizeMoney->getCtp()
116
+		);
117
+		$this->ctp->create($ctp1);
118
+		$ctp2 = array(
119
+			'match_id' => $matchdata['match'],
120
+			'player_id' => $matchdata['ctp2'],
121
+			'hole_id' => $matchdata['ctp2hole'],
122
+			'money' => $this->prizeMoney->getCtp()
123
+		);
124
+		$this->ctp->create($ctp2);
125
+
126
+		//calculate Gross winner and post to grossWinnersTable
127
+
128
+		$matchRound = $this->matchRoundRepo->getByMatch($matchdata['match']);
129
+
130
+
131
+		$lowGross = array();
132
+		foreach ($matchRound as $key => $match){
133
+			$lowGross[$match['player']->id] = $match['score'];
134
+		}
135
+		$arrayLowGross = array_keys($lowGross, min($lowGross));
136
+		foreach($arrayLowGross as $key => $lowgrossPlayer) {
137
+			$grossWinner = new Grosswinner;
138
+			$grossWinner->player_id = $lowgrossPlayer;
139
+			$grossWinner->match_id = $matchdata['match'];
140
+			$grossWinner->score = $lowGross[$lowgrossPlayer];
141
+			$grossWinner->money = $this->prizeMoney->getlowScore() / count($arrayLowGross);
142
+			$grossWinner->save();
143
+		}
144
+
145
+		//Calculate NET winner
146
+		$lowNet = array();
147
+		$scores =array();
148
+		foreach ($matchRound as $key => $match){
149
+			$netScore = ($match['score'] - round($match['player']->handicap,0)); //calculate net score
150
+			$lowNet[$match['player']->id] = $netScore;
151
+		}
152
+		$arrayLowNet = array_keys($lowNet, min($lowNet));
153
+
154
+		foreach($arrayLowNet as $key => $lownetPlayer) {
155
+			$netWinner = new Netwinner;
156
+			$netWinner->player_id = $lownetPlayer;
157
+			$netWinner->match_id = $matchdata['match'];
158
+			$netWinner->score = $lowNet[$lownetPlayer];
159
+			$netWinner->money = $this->prizeMoney->getlowScore() /  count($arrayLowNet);
160
+			$netWinner->save();
161
+		}
162
+
163
+		//Calculate Skins
164
+
165
+		//determine A and B players
166
+		//using pivot table match_player
167
+		$match = $this->match->find($matchdata['match']);
168
+		$aPlayers = array();
169
+		$bPlayers = array();
170
+		foreach($match->players as $player)
171
+		{
172
+			if($player->pivot->level_id == 1){
173
+				$aPlayers[] = $player->pivot->player_id;
174
+
175
+			}
176
+			if($player->pivot->level_id == 2){
177
+				$bPlayers[] = $player->pivot->player_id;
178
+			}
179
+		}
180
+
181
+		//Create Skins arrays
182
+		//player_id, 'holescores'
183
+		foreach($matchRound as $key => $round) {
184
+			if (in_array($round->player_id,$aPlayers)){
185
+				$aPlayersSkins[$key]['player_id'] = $round->player_id;
186
+				$aPlayersSkins[$key]['holescores'] = $round->holescores;
187
+			}
188
+			if (in_array($round->player_id,$bPlayers)){
189
+				$bPlayersSkins[$key]['player_id'] = $round->player_id;
190
+				$bPlayersSkins[$key]['holescores'] = $round->holescores;
191
+			}
192
+		}
193
+
194
+		//Run A Skins analysis
195
+		$scores = array();
196
+		foreach($aPlayersSkins as $key => $playerSkin){
197
+			foreach($playerSkin['holescores'] as $hole => $holescore){
198
+				$scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score'];
199
+			}
200
+		}
201
+
202
+		foreach($scores as $hole_id => $hole) {
203
+			$minScore = min($hole);
204
+			$winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score
205
+		}
206
+		$aSkinsWon = 0;
207
+		foreach($winners as $key => $winner) {
208
+			if(count($winner)  ===  1) {
209
+				//post to DB
210
+				$skinWinner = new Skin;
211
+				$skinWinner->player_id = $winner[0];
212
+				$skinWinner->level_id = 1;
213
+				$skinWinner->match_id = intval($matchdata['match']);
214
+				$skinWinner->hole_id = $key;
215
+				$skinWinner->save();
216
+				$aSkinsWon++;
217
+			}
218
+		}
219
+
220
+		//Run B Skins analysis
221
+		$scores = array();
222
+		foreach($bPlayersSkins as $key => $playerSkin){
223
+			foreach($playerSkin['holescores'] as $hole => $holescore){
224
+				$scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score'];
225
+			}
226
+		}
227
+
228
+		foreach($scores as $hole_id => $hole) {
229
+			$minScore = min($hole);
230
+			$winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score
231
+		}
232
+		$bSkinsWon = 0;
233
+		foreach($winners as $key => $winner) {
234
+			if(count($winner)  ===  1) {
235
+				//post to DB
236
+				$skinWinner = new Skin;
237
+				$skinWinner->player_id = $winner[0];
238
+				$skinWinner->level_id = 2;
239
+				$skinWinner->match_id = intval($matchdata['match']);
240
+				$skinWinner->hole_id = $key;
241
+				$skinWinner->save();
242
+				$bSkinsWon++;
243
+			}
244
+		}
245
+
246
+		$match =  Match::find($matchdata['match']);
247
+
248
+		//Need to add Carry over money if there no skins are won
249
+		//check for carry over money
250
+		$skinsamoney = $match->skinsamoney; // + carryover A money if any
251
+		$skinsbmoney = $match->skinsbmoney; // + carryover B money if any
252
+
253
+		if($aSkinsWon > 0) {
254
+			$moneyperskinA = $skinsamoney / $aSkinsWon;
255
+
256
+			$aSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 1)->get();
257
+			foreach ($aSkins as $askin){
258
+				$askin->money = $moneyperskinA;
259
+				$askin->save();
260
+			}
261
+		}
262
+
263
+		if($bSkinsWon > 0) {
264
+			$moneyperskinB = $skinsbmoney / $bSkinsWon;
265
+
266
+			$bSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 2)->get();
267
+			foreach ($bSkins as $bskin){
268
+				$bskin->money = $moneyperskinB;
269
+				$bskin->save();
270
+			}
271
+		}
272
+		//foreach player in pivot table create player and run handicap analysis
273
+		foreach($match->players as $matchplayer)
274
+		{
275
+			$player = Player::find($matchplayer->pivot->player_id);
276
+			$handicap = new Handicap($player);
277
+			$player->handicap = $handicap->calculate();
278
+			$player->save();
279
+		}
280
+
281
+		//Fire event to calculate money won and add to pivot table match_player
282
+		$this->events->fire('match.finalize', $match);
283
+
284
+	}
285
+
286
+	/**
287
+	 * Method to get match from input Match data
288
+	 *
289
+	 * @param mixed $matchdata
290
+	 * @return JSON object
291
+	 */
292
+	public function get($matchid)
293
+	{
294
+		$matchdata =  $this->matchRepo->get($matchid);
295
+		return $matchdata;
296
+	}
297 297
 }
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 
59 59
         //calculate money with purse
60 60
         $this->purse->setPurse($matchdata['purse']);
61
-        echo $this->purse->getPurse();  exit();
61
+        echo $this->purse->getPurse(); exit();
62 62
         $this->prizeMoney->setPurse($matchdata['purse']);
63 63
 
64 64
 
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
         $aPlayerCount = 0;
73 73
         
74 74
         $bPlayerCount = 0;
75
-        foreach($matchdata['player'] as $player){
76
-            if ($player['level_id'] == '1'){
75
+        foreach ($matchdata['player'] as $player) {
76
+            if ($player['level_id'] == '1') {
77 77
                 $aPlayerCount++;
78 78
             }
79 79
             else {
@@ -89,8 +89,8 @@  discard block
 block discarded – undo
89 89
         //check for carry over money and if there is add it to skins money
90 90
         $carryOver = new CarryOver;
91 91
         $carryOverMoney = $carryOver->calculate();
92
-        $matchdata['skinsamoney'] +=  $carryOverMoney[1];
93
-        $matchdata['skinsbmoney'] +=  $carryOverMoney[2];
92
+        $matchdata['skinsamoney'] += $carryOverMoney[1];
93
+        $matchdata['skinsbmoney'] += $carryOverMoney[2];
94 94
 
95 95
         //append current handicap and set winnings to 0 for each player
96 96
         foreach ($matchdata['player'] as $key=>$player) {
@@ -129,11 +129,11 @@  discard block
 block discarded – undo
129 129
 
130 130
 
131 131
         $lowGross = array();
132
-        foreach ($matchRound as $key => $match){
132
+        foreach ($matchRound as $key => $match) {
133 133
             $lowGross[$match['player']->id] = $match['score'];
134 134
         }
135 135
         $arrayLowGross = array_keys($lowGross, min($lowGross));
136
-        foreach($arrayLowGross as $key => $lowgrossPlayer) {
136
+        foreach ($arrayLowGross as $key => $lowgrossPlayer) {
137 137
             $grossWinner = new Grosswinner;
138 138
             $grossWinner->player_id = $lowgrossPlayer;
139 139
             $grossWinner->match_id = $matchdata['match'];
@@ -144,19 +144,19 @@  discard block
 block discarded – undo
144 144
 
145 145
         //Calculate NET winner
146 146
         $lowNet = array();
147
-        $scores =array();
148
-        foreach ($matchRound as $key => $match){
149
-            $netScore = ($match['score'] - round($match['player']->handicap,0)); //calculate net score
147
+        $scores = array();
148
+        foreach ($matchRound as $key => $match) {
149
+            $netScore = ($match['score'] - round($match['player']->handicap, 0)); //calculate net score
150 150
             $lowNet[$match['player']->id] = $netScore;
151 151
         }
152 152
         $arrayLowNet = array_keys($lowNet, min($lowNet));
153 153
 
154
-        foreach($arrayLowNet as $key => $lownetPlayer) {
154
+        foreach ($arrayLowNet as $key => $lownetPlayer) {
155 155
             $netWinner = new Netwinner;
156 156
             $netWinner->player_id = $lownetPlayer;
157 157
             $netWinner->match_id = $matchdata['match'];
158 158
             $netWinner->score = $lowNet[$lownetPlayer];
159
-            $netWinner->money = $this->prizeMoney->getlowScore() /  count($arrayLowNet);
159
+            $netWinner->money = $this->prizeMoney->getlowScore() / count($arrayLowNet);
160 160
             $netWinner->save();
161 161
         }
162 162
 
@@ -167,25 +167,25 @@  discard block
 block discarded – undo
167 167
         $match = $this->match->find($matchdata['match']);
168 168
         $aPlayers = array();
169 169
         $bPlayers = array();
170
-        foreach($match->players as $player)
170
+        foreach ($match->players as $player)
171 171
         {
172
-            if($player->pivot->level_id == 1){
172
+            if ($player->pivot->level_id == 1) {
173 173
                 $aPlayers[] = $player->pivot->player_id;
174 174
 
175 175
             }
176
-            if($player->pivot->level_id == 2){
176
+            if ($player->pivot->level_id == 2) {
177 177
                 $bPlayers[] = $player->pivot->player_id;
178 178
             }
179 179
         }
180 180
 
181 181
         //Create Skins arrays
182 182
         //player_id, 'holescores'
183
-        foreach($matchRound as $key => $round) {
184
-            if (in_array($round->player_id,$aPlayers)){
183
+        foreach ($matchRound as $key => $round) {
184
+            if (in_array($round->player_id, $aPlayers)) {
185 185
                 $aPlayersSkins[$key]['player_id'] = $round->player_id;
186 186
                 $aPlayersSkins[$key]['holescores'] = $round->holescores;
187 187
             }
188
-            if (in_array($round->player_id,$bPlayers)){
188
+            if (in_array($round->player_id, $bPlayers)) {
189 189
                 $bPlayersSkins[$key]['player_id'] = $round->player_id;
190 190
                 $bPlayersSkins[$key]['holescores'] = $round->holescores;
191 191
             }
@@ -193,19 +193,19 @@  discard block
 block discarded – undo
193 193
 
194 194
         //Run A Skins analysis
195 195
         $scores = array();
196
-        foreach($aPlayersSkins as $key => $playerSkin){
197
-            foreach($playerSkin['holescores'] as $hole => $holescore){
196
+        foreach ($aPlayersSkins as $key => $playerSkin) {
197
+            foreach ($playerSkin['holescores'] as $hole => $holescore) {
198 198
                 $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score'];
199 199
             }
200 200
         }
201 201
 
202
-        foreach($scores as $hole_id => $hole) {
202
+        foreach ($scores as $hole_id => $hole) {
203 203
             $minScore = min($hole);
204 204
             $winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score
205 205
         }
206 206
         $aSkinsWon = 0;
207
-        foreach($winners as $key => $winner) {
208
-            if(count($winner)  ===  1) {
207
+        foreach ($winners as $key => $winner) {
208
+            if (count($winner) === 1) {
209 209
                 //post to DB
210 210
                 $skinWinner = new Skin;
211 211
                 $skinWinner->player_id = $winner[0];
@@ -219,19 +219,19 @@  discard block
 block discarded – undo
219 219
 
220 220
         //Run B Skins analysis
221 221
         $scores = array();
222
-        foreach($bPlayersSkins as $key => $playerSkin){
223
-            foreach($playerSkin['holescores'] as $hole => $holescore){
222
+        foreach ($bPlayersSkins as $key => $playerSkin) {
223
+            foreach ($playerSkin['holescores'] as $hole => $holescore) {
224 224
                 $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score'];
225 225
             }
226 226
         }
227 227
 
228
-        foreach($scores as $hole_id => $hole) {
228
+        foreach ($scores as $hole_id => $hole) {
229 229
             $minScore = min($hole);
230 230
             $winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score
231 231
         }
232 232
         $bSkinsWon = 0;
233
-        foreach($winners as $key => $winner) {
234
-            if(count($winner)  ===  1) {
233
+        foreach ($winners as $key => $winner) {
234
+            if (count($winner) === 1) {
235 235
                 //post to DB
236 236
                 $skinWinner = new Skin;
237 237
                 $skinWinner->player_id = $winner[0];
@@ -243,34 +243,34 @@  discard block
 block discarded – undo
243 243
             }
244 244
         }
245 245
 
246
-        $match =  Match::find($matchdata['match']);
246
+        $match = Match::find($matchdata['match']);
247 247
 
248 248
         //Need to add Carry over money if there no skins are won
249 249
         //check for carry over money
250 250
         $skinsamoney = $match->skinsamoney; // + carryover A money if any
251 251
         $skinsbmoney = $match->skinsbmoney; // + carryover B money if any
252 252
 
253
-        if($aSkinsWon > 0) {
253
+        if ($aSkinsWon > 0) {
254 254
             $moneyperskinA = $skinsamoney / $aSkinsWon;
255 255
 
256 256
             $aSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 1)->get();
257
-            foreach ($aSkins as $askin){
257
+            foreach ($aSkins as $askin) {
258 258
                 $askin->money = $moneyperskinA;
259 259
                 $askin->save();
260 260
             }
261 261
         }
262 262
 
263
-        if($bSkinsWon > 0) {
263
+        if ($bSkinsWon > 0) {
264 264
             $moneyperskinB = $skinsbmoney / $bSkinsWon;
265 265
 
266 266
             $bSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 2)->get();
267
-            foreach ($bSkins as $bskin){
267
+            foreach ($bSkins as $bskin) {
268 268
                 $bskin->money = $moneyperskinB;
269 269
                 $bskin->save();
270 270
             }
271 271
         }
272 272
         //foreach player in pivot table create player and run handicap analysis
273
-        foreach($match->players as $matchplayer)
273
+        foreach ($match->players as $matchplayer)
274 274
         {
275 275
             $player = Player::find($matchplayer->pivot->player_id);
276 276
             $handicap = new Handicap($player);
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
      */
292 292
     public function get($matchid)
293 293
     {
294
-        $matchdata =  $this->matchRepo->get($matchid);
294
+        $matchdata = $this->matchRepo->get($matchid);
295 295
         return $matchdata;
296 296
     }
297 297
 }
Please login to merge, or discard this patch.