Completed
Push — master ( d565f6...12549b )
by Michael
02:45
created
app/models/Round.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
 
28 28
     public function holes()
29 29
     {
30
-        return $this->hasManyThrough('Hole','Holescore');
30
+        return $this->hasManyThrough('Hole', 'Holescore');
31 31
     }
32 32
 
33 33
     public function match()
Please login to merge, or discard this patch.
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -6,33 +6,33 @@
 block discarded – undo
6 6
 	protected $fillable = ['date', 'player_id', 'course_id', 'match_id', 'score', 'esc', 'team_id'];
7 7
 
8 8
 	public function setDateAttribute($date)
9
-    {
9
+	{
10 10
 		$this->attributes['date'] = date('Y-m-d', strtotime(str_replace('-', '/', $date)));
11
-    }
11
+	}
12 12
 
13
-    public function player()
14
-    {
15
-        return $this->belongsTo('Player');
16
-    }
13
+	public function player()
14
+	{
15
+		return $this->belongsTo('Player');
16
+	}
17 17
 
18 18
 	public function course()
19
-    {
20
-        return $this->belongsTo('Course');
21
-    }
22
-
23
-    public function holescores()
24
-    {
25
-        return $this->hasMany('Holescore')->orderBy('id');
26
-    }
27
-
28
-    public function holes()
29
-    {
30
-        return $this->hasManyThrough('Hole','Holescore');
31
-    }
32
-
33
-    public function match()
34
-    {
35
-        return $this->belongsTo('Match');
36
-    }
19
+	{
20
+		return $this->belongsTo('Course');
21
+	}
22
+
23
+	public function holescores()
24
+	{
25
+		return $this->hasMany('Holescore')->orderBy('id');
26
+	}
27
+
28
+	public function holes()
29
+	{
30
+		return $this->hasManyThrough('Hole','Holescore');
31
+	}
32
+
33
+	public function match()
34
+	{
35
+		return $this->belongsTo('Match');
36
+	}
37 37
 
38 38
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,12 +1,11 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-class Round extends Eloquent
4
-{
3
+class Round extends Eloquent {
5 4
 	protected $guarded = ['id'];
6 5
 	protected $fillable = ['date', 'player_id', 'course_id', 'match_id', 'score', 'esc', 'team_id'];
7 6
 
8 7
 	public function setDateAttribute($date)
9
-    {
8
+	{
10 9
 		$this->attributes['date'] = date('Y-m-d', strtotime(str_replace('-', '/', $date)));
11 10
     }
12 11
 
@@ -16,7 +15,7 @@  discard block
 block discarded – undo
16 15
     }
17 16
 
18 17
 	public function course()
19
-    {
18
+	{
20 19
         return $this->belongsTo('Course');
21 20
     }
22 21
 
Please login to merge, or discard this patch.
app/models/Team.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -2,11 +2,11 @@
 block discarded – undo
2 2
 
3 3
 class Team extends Eloquent
4 4
 {
5
-    protected $guarded = ['id'];
6
-    protected $fillable = ['name'];
5
+	protected $guarded = ['id'];
6
+	protected $fillable = ['name'];
7 7
 
8
-    public function players()
9
-    {
10
-        return $this->hasMany('Player');
11
-    }
8
+	public function players()
9
+	{
10
+		return $this->hasMany('Player');
11
+	}
12 12
 }
13 13
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,7 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-class Team extends Eloquent
4
-{
3
+class Team extends Eloquent {
5 4
     protected $guarded = ['id'];
6 5
     protected $fillable = ['name'];
7 6
 
Please login to merge, or discard this patch.
app/library/Services/MatchService.php 4 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
     /**
346 346
      * Method to get match from input Match data
347 347
      *
348
-     * @param mixed $matchdata
348
+     * @param mixed $matchid
349 349
      * @return JSON object
350 350
      */
351 351
     public function get($matchid)
@@ -356,6 +356,9 @@  discard block
 block discarded – undo
356 356
 
357 357
 
358 358
 
359
+    /**
360
+     * @param string $key
361
+     */
359 362
     private function search($array, $key, $value)
360 363
     {
361 364
         $results = array();
Please login to merge, or discard this patch.
Indentation   +349 added lines, -349 removed lines patch added patch discarded remove patch
@@ -19,354 +19,354 @@
 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
-                                Teammatch $teammatch,
38
-                                Dispatcher $events)
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->teammatch = $teammatch;
47
-        $this->events = $events;
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
-        $this->prizeMoney->setPurse($matchdata['purse']);
59
-
60
-        $matchdata['purse'] = number_format($matchdata['purse'], 2);
61
-        $matchdata['grossmoney'] = $this->prizeMoney->getlowScore();
62
-        $matchdata['netmoney'] = $this->prizeMoney->getlowScore();
63
-
64
-        //How many A and B players
65
-        $totalPlayers = 0;
66
-
67
-        $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
+								Teammatch $teammatch,
38
+								Dispatcher $events)
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->teammatch = $teammatch;
47
+		$this->events = $events;
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
+		$this->prizeMoney->setPurse($matchdata['purse']);
59
+
60
+		$matchdata['purse'] = number_format($matchdata['purse'], 2);
61
+		$matchdata['grossmoney'] = $this->prizeMoney->getlowScore();
62
+		$matchdata['netmoney'] = $this->prizeMoney->getlowScore();
63
+
64
+		//How many A and B players
65
+		$totalPlayers = 0;
66
+
67
+		$aPlayerCount = 0;
68 68
         
69
-        $bPlayerCount = 0;
70
-        foreach($matchdata['player'] as $player){
71
-            if ($player['level_id'] == '1'){
72
-                $aPlayerCount++;
73
-            }
74
-            else {
75
-                $bPlayerCount++;
76
-            }
77
-            $totalPlayers++;
78
-        }
79
-
80
-        //Calculate Skins money based on how many players in each group
81
-
82
-        $matchdata['skinsamoney'] = $this->prizeMoney->skinsGroupPot($matchdata['purse'], $totalPlayers, $aPlayerCount);
83
-        $matchdata['skinsbmoney'] = $this->prizeMoney->skinsGroupPot($matchdata['purse'], $totalPlayers, $bPlayerCount);
84
-        //check for carry over money and if there is add it to skins money
85
-        $carryOver = new CarryOver;
86
-        $carryOverMoney = $carryOver->calculate();
87
-        $matchdata['skinsamoney'] +=  $carryOverMoney[1];
88
-        $matchdata['skinsbmoney'] +=  $carryOverMoney[2];
89
-
90
-        //append current handicap and set winnings to 0 for each player
91
-        foreach ($matchdata['player'] as $key=>$player) {
92
-            //get each player's current handicap
93
-            $currentPlayer = $this->player->find($player['player_id']);
94
-            $matchdata['player'][$key]['handicap'] = $currentPlayer->handicap;
95
-            $matchdata['player'][$key]['winnings'] = 0;
96
-        }// End foreach
97
-
98
-        $matchid = $this->matchRepo->create($matchdata);
99
-        $matchdata['match_id'] = $matchid;
100
-        $this->events->fire('match.create', array($matchdata));  // MatchHandler and teamMatchHandler are listening...
101
-
102
-        // Run for team Matches
103
-        if($matchdata['matchType'] === 'team' || $matchdata['matchType'] === 'both'){
104
-
105
-            foreach ($matchdata['teamMatchUp1'] as $teamKey => $team){
106
-                $matchUp1[] = $this->search($matchdata['player'], 'team', $team);
107
-            }
108
-
109
-            //Save matchUp 1
110
-            $match1['match_id'] = $matchdata['match_id'];  // This is generated below and passed to listener
111
-            $match1['team_id'] = $matchUp1[0][0]['team'];
112
-            $match1['player1'] = $matchUp1[0][0]['player_id'];
113
-            $match1['player2'] = $matchUp1[0][1]['player_id'];
114
-            $match1['opponent'] = $matchUp1[1][0]['team'];
115
-            $this->teammatch->create($match1); //save to match table
116
-
117
-            $match1['match_id'] = $matchdata['match_id'];  // This is generated below and passed to listener
118
-            $match1['team_id'] = $matchUp1[1][0]['team'];
119
-            $match1['player1'] = $matchUp1[1][0]['player_id'];
120
-            $match1['player2'] = $matchUp1[1][1]['player_id'];
121
-            $match1['opponent'] = $matchUp1[0][0]['team'];
122
-            $this->teammatch->create($match1); //save to match table
123
-
124
-
125
-            foreach ($matchdata['teamMatchUp2'] as $teamKey => $team){
126
-                $matchUp2[] = $this->search($matchdata['player'], 'team', $team);
127
-            }
128
-
129
-            //Save matchUp 2
130
-            $match2['match_id'] = $matchdata['match_id'];  // This is generated below and passed to listener
131
-            $match2['team_id'] = $matchUp2[0][0]['team'];
132
-            $match2['player1'] = $matchUp2[0][0]['player_id'];
133
-            $match2['player2'] = $matchUp2[0][1]['player_id'];
134
-            $match2['opponent'] = $matchUp2[1][0]['team'];
135
-            $this->teammatch->create($match2); //save to match table
136
-
137
-            $match2['match_id'] = $matchdata['match_id'];  // This is generated below and passed to listener
138
-            $match2['team_id'] = $matchUp2[1][0]['team'];
139
-            $match2['player1'] = $matchUp2[1][0]['player_id'];
140
-            $match2['player2'] = $matchUp2[1][1]['player_id'];
141
-            $match2['opponent'] = $matchUp2[0][0]['team'];
142
-            $this->teammatch->create($match2); //save to match table
143
-
144
-
145
-            foreach ($matchdata['teamMatchUp3'] as $teamKey => $team){
146
-                $matchUp3[] = $this->search($matchdata['player'], 'team', $team);
147
-            }
148
-
149
-            //Save matchUp 3
150
-            $match3['match_id'] = $matchdata['match_id'];  // This is generated below and passed to listener
151
-            $match3['team_id'] = $matchUp3[0][0]['team'];
152
-            $match3['player1'] = $matchUp3[0][0]['player_id'];
153
-            $match3['player2'] = $matchUp3[0][1]['player_id'];
154
-            $match3['opponent'] = $matchUp3[1][0]['team'];
155
-            $this->teammatch->create($match3); //save to match table
156
-
157
-            $match3['match_id'] = $matchdata['match_id'];  // This is generated below and passed to listener
158
-            $match3['team_id'] = $matchUp3[1][0]['team'];
159
-            $match3['player1'] = $matchUp3[1][0]['player_id'];
160
-            $match3['player2'] = $matchUp3[1][1]['player_id'];
161
-            $match3['opponent'] = $matchUp3[0][0]['team'];
162
-            $this->teammatch->create($match3); //save to match table
163
-
164
-        }
165
-    }
166
-
167
-    public function finalize($matchdata)
168
-    {
169
-        // post CTP1 and CTP2
170
-        $ctp1 = array(
171
-            'match_id' => $matchdata['match'],
172
-            'player_id' => $matchdata['ctp1'],
173
-            'hole_id' => $matchdata['ctp1hole'],
174
-            'money' => $this->prizeMoney->getCtp()
175
-        );
176
-        $this->ctp->create($ctp1);
177
-        $ctp2 = array(
178
-            'match_id' => $matchdata['match'],
179
-            'player_id' => $matchdata['ctp2'],
180
-            'hole_id' => $matchdata['ctp2hole'],
181
-            'money' => $this->prizeMoney->getCtp()
182
-        );
183
-        $this->ctp->create($ctp2);
184
-
185
-        //calculate Gross winner and post to grossWinnersTable
186
-
187
-        $matchRound = $this->matchRoundRepo->getByMatch($matchdata['match']);
188
-
189
-
190
-        $lowGross = array();
191
-        foreach ($matchRound as $key => $match){
192
-            $lowGross[$match['player']->id] = $match['score'];
193
-        }
194
-        $arrayLowGross = array_keys($lowGross, min($lowGross));
195
-        foreach($arrayLowGross as $key => $lowgrossPlayer) {
196
-            $grossWinner = new Grosswinner;
197
-            $grossWinner->player_id = $lowgrossPlayer;
198
-            $grossWinner->match_id = $matchdata['match'];
199
-            $grossWinner->score = $lowGross[$lowgrossPlayer];
200
-            $grossWinner->money = $this->prizeMoney->getlowScore() / count($arrayLowGross);
201
-            $grossWinner->save();
202
-        }
203
-
204
-        //Calculate NET winner
205
-        $lowNet = array();
206
-        $scores =array();
207
-        foreach ($matchRound as $key => $match){
208
-            $netScore = ($match['score'] - round($match['player']->handicap,0)); //calculate net score
209
-            $lowNet[$match['player']->id] = $netScore;
210
-        }
211
-        $arrayLowNet = array_keys($lowNet, min($lowNet));
212
-
213
-        foreach($arrayLowNet as $key => $lownetPlayer) {
214
-            $netWinner = new Netwinner;
215
-            $netWinner->player_id = $lownetPlayer;
216
-            $netWinner->match_id = $matchdata['match'];
217
-            $netWinner->score = $lowNet[$lownetPlayer];
218
-            $netWinner->money = $this->prizeMoney->getlowScore() /  count($arrayLowNet);
219
-            $netWinner->save();
220
-        }
221
-
222
-        //Calculate Skins
223
-
224
-        //determine A and B players
225
-        //using pivot table match_player
226
-        $match = $this->match->find($matchdata['match']);
227
-        $aPlayers = array();
228
-        $bPlayers = array();
229
-        foreach($match->players as $player)
230
-        {
231
-            if($player->pivot->level_id == 1){
232
-                $aPlayers[] = $player->pivot->player_id;
233
-
234
-            }
235
-            if($player->pivot->level_id == 2){
236
-                $bPlayers[] = $player->pivot->player_id;
237
-            }
238
-        }
239
-
240
-        //Create Skins arrays
241
-        //player_id, 'holescores'
242
-        foreach($matchRound as $key => $round) {
243
-            if (in_array($round->player_id,$aPlayers)){
244
-                $aPlayersSkins[$key]['player_id'] = $round->player_id;
245
-                $aPlayersSkins[$key]['holescores'] = $round->holescores;
246
-            }
247
-            if (in_array($round->player_id,$bPlayers)){
248
-                $bPlayersSkins[$key]['player_id'] = $round->player_id;
249
-                $bPlayersSkins[$key]['holescores'] = $round->holescores;
250
-            }
251
-        }
252
-
253
-        //Run A Skins analysis
254
-        $scores = array();
255
-        foreach($aPlayersSkins as $key => $playerSkin){
256
-            foreach($playerSkin['holescores'] as $hole => $holescore){
257
-                $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score'];
258
-            }
259
-        }
260
-
261
-        foreach($scores as $hole_id => $hole) {
262
-            $minScore = min($hole);
263
-            $winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score
264
-        }
265
-        $aSkinsWon = 0;
266
-        foreach($winners as $key => $winner) {
267
-            if(count($winner)  ===  1) {
268
-                //post to DB
269
-                $skinWinner = new Skin;
270
-                $skinWinner->player_id = $winner[0];
271
-                $skinWinner->level_id = 1;
272
-                $skinWinner->match_id = intval($matchdata['match']);
273
-                $skinWinner->hole_id = $key;
274
-                $skinWinner->save();
275
-                $aSkinsWon++;
276
-            }
277
-        }
278
-
279
-        //Run B Skins analysis
280
-        $scores = array();
281
-        foreach($bPlayersSkins as $key => $playerSkin){
282
-            foreach($playerSkin['holescores'] as $hole => $holescore){
283
-                $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score'];
284
-            }
285
-        }
286
-
287
-        foreach($scores as $hole_id => $hole) {
288
-            $minScore = min($hole);
289
-            $winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score
290
-        }
291
-        $bSkinsWon = 0;
292
-        foreach($winners as $key => $winner) {
293
-            if(count($winner)  ===  1) {
294
-                //post to DB
295
-                $skinWinner = new Skin;
296
-                $skinWinner->player_id = $winner[0];
297
-                $skinWinner->level_id = 2;
298
-                $skinWinner->match_id = intval($matchdata['match']);
299
-                $skinWinner->hole_id = $key;
300
-                $skinWinner->save();
301
-                $bSkinsWon++;
302
-            }
303
-        }
304
-
305
-        $match =  Match::find($matchdata['match']);
306
-
307
-        //Need to add Carry over money if there no skins are won
308
-        //check for carry over money
309
-        $skinsamoney = $match->skinsamoney; // + carryover A money if any
310
-        $skinsbmoney = $match->skinsbmoney; // + carryover B money if any
311
-
312
-        if($aSkinsWon > 0) {
313
-            $moneyperskinA = $skinsamoney / $aSkinsWon;
314
-
315
-            $aSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 1)->get();
316
-            foreach ($aSkins as $askin){
317
-                $askin->money = $moneyperskinA;
318
-                $askin->save();
319
-            }
320
-        }
321
-
322
-        if($bSkinsWon > 0) {
323
-            $moneyperskinB = $skinsbmoney / $bSkinsWon;
324
-
325
-            $bSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 2)->get();
326
-            foreach ($bSkins as $bskin){
327
-                $bskin->money = $moneyperskinB;
328
-                $bskin->save();
329
-            }
330
-        }
331
-        //foreach player in pivot table create player and run handicap analysis
332
-        foreach($match->players as $matchplayer)
333
-        {
334
-            $player = Player::find($matchplayer->pivot->player_id);
335
-            $handicap = new Handicap($player);
336
-            $player->handicap = $handicap->calculate();
337
-            $player->save();
338
-        }
339
-
340
-        //Fire event to calculate money won and add to pivot table match_player
341
-        $this->events->fire('match.finalize', $match);
342
-
343
-    }
344
-
345
-    /**
346
-     * Method to get match from input Match data
347
-     *
348
-     * @param mixed $matchdata
349
-     * @return JSON object
350
-     */
351
-    public function get($matchid)
352
-    {
353
-        $matchdata =  $this->matchRepo->get($matchid);
354
-        return $matchdata;
355
-    }
356
-
357
-
358
-
359
-    private function search($array, $key, $value)
360
-    {
361
-        $results = array();
362
-        if (is_array($array)) {
363
-            if (isset($array[$key]) && $array[$key] == $value) {
364
-                $results[] = $array;
365
-            }
366
-            foreach ($array as $subarray) {
367
-                $results = array_merge($results, $this->search($subarray, $key, $value));
368
-            }
369
-        }
370
-        return $results;
371
-    }
69
+		$bPlayerCount = 0;
70
+		foreach($matchdata['player'] as $player){
71
+			if ($player['level_id'] == '1'){
72
+				$aPlayerCount++;
73
+			}
74
+			else {
75
+				$bPlayerCount++;
76
+			}
77
+			$totalPlayers++;
78
+		}
79
+
80
+		//Calculate Skins money based on how many players in each group
81
+
82
+		$matchdata['skinsamoney'] = $this->prizeMoney->skinsGroupPot($matchdata['purse'], $totalPlayers, $aPlayerCount);
83
+		$matchdata['skinsbmoney'] = $this->prizeMoney->skinsGroupPot($matchdata['purse'], $totalPlayers, $bPlayerCount);
84
+		//check for carry over money and if there is add it to skins money
85
+		$carryOver = new CarryOver;
86
+		$carryOverMoney = $carryOver->calculate();
87
+		$matchdata['skinsamoney'] +=  $carryOverMoney[1];
88
+		$matchdata['skinsbmoney'] +=  $carryOverMoney[2];
89
+
90
+		//append current handicap and set winnings to 0 for each player
91
+		foreach ($matchdata['player'] as $key=>$player) {
92
+			//get each player's current handicap
93
+			$currentPlayer = $this->player->find($player['player_id']);
94
+			$matchdata['player'][$key]['handicap'] = $currentPlayer->handicap;
95
+			$matchdata['player'][$key]['winnings'] = 0;
96
+		}// End foreach
97
+
98
+		$matchid = $this->matchRepo->create($matchdata);
99
+		$matchdata['match_id'] = $matchid;
100
+		$this->events->fire('match.create', array($matchdata));  // MatchHandler and teamMatchHandler are listening...
101
+
102
+		// Run for team Matches
103
+		if($matchdata['matchType'] === 'team' || $matchdata['matchType'] === 'both'){
104
+
105
+			foreach ($matchdata['teamMatchUp1'] as $teamKey => $team){
106
+				$matchUp1[] = $this->search($matchdata['player'], 'team', $team);
107
+			}
108
+
109
+			//Save matchUp 1
110
+			$match1['match_id'] = $matchdata['match_id'];  // This is generated below and passed to listener
111
+			$match1['team_id'] = $matchUp1[0][0]['team'];
112
+			$match1['player1'] = $matchUp1[0][0]['player_id'];
113
+			$match1['player2'] = $matchUp1[0][1]['player_id'];
114
+			$match1['opponent'] = $matchUp1[1][0]['team'];
115
+			$this->teammatch->create($match1); //save to match table
116
+
117
+			$match1['match_id'] = $matchdata['match_id'];  // This is generated below and passed to listener
118
+			$match1['team_id'] = $matchUp1[1][0]['team'];
119
+			$match1['player1'] = $matchUp1[1][0]['player_id'];
120
+			$match1['player2'] = $matchUp1[1][1]['player_id'];
121
+			$match1['opponent'] = $matchUp1[0][0]['team'];
122
+			$this->teammatch->create($match1); //save to match table
123
+
124
+
125
+			foreach ($matchdata['teamMatchUp2'] as $teamKey => $team){
126
+				$matchUp2[] = $this->search($matchdata['player'], 'team', $team);
127
+			}
128
+
129
+			//Save matchUp 2
130
+			$match2['match_id'] = $matchdata['match_id'];  // This is generated below and passed to listener
131
+			$match2['team_id'] = $matchUp2[0][0]['team'];
132
+			$match2['player1'] = $matchUp2[0][0]['player_id'];
133
+			$match2['player2'] = $matchUp2[0][1]['player_id'];
134
+			$match2['opponent'] = $matchUp2[1][0]['team'];
135
+			$this->teammatch->create($match2); //save to match table
136
+
137
+			$match2['match_id'] = $matchdata['match_id'];  // This is generated below and passed to listener
138
+			$match2['team_id'] = $matchUp2[1][0]['team'];
139
+			$match2['player1'] = $matchUp2[1][0]['player_id'];
140
+			$match2['player2'] = $matchUp2[1][1]['player_id'];
141
+			$match2['opponent'] = $matchUp2[0][0]['team'];
142
+			$this->teammatch->create($match2); //save to match table
143
+
144
+
145
+			foreach ($matchdata['teamMatchUp3'] as $teamKey => $team){
146
+				$matchUp3[] = $this->search($matchdata['player'], 'team', $team);
147
+			}
148
+
149
+			//Save matchUp 3
150
+			$match3['match_id'] = $matchdata['match_id'];  // This is generated below and passed to listener
151
+			$match3['team_id'] = $matchUp3[0][0]['team'];
152
+			$match3['player1'] = $matchUp3[0][0]['player_id'];
153
+			$match3['player2'] = $matchUp3[0][1]['player_id'];
154
+			$match3['opponent'] = $matchUp3[1][0]['team'];
155
+			$this->teammatch->create($match3); //save to match table
156
+
157
+			$match3['match_id'] = $matchdata['match_id'];  // This is generated below and passed to listener
158
+			$match3['team_id'] = $matchUp3[1][0]['team'];
159
+			$match3['player1'] = $matchUp3[1][0]['player_id'];
160
+			$match3['player2'] = $matchUp3[1][1]['player_id'];
161
+			$match3['opponent'] = $matchUp3[0][0]['team'];
162
+			$this->teammatch->create($match3); //save to match table
163
+
164
+		}
165
+	}
166
+
167
+	public function finalize($matchdata)
168
+	{
169
+		// post CTP1 and CTP2
170
+		$ctp1 = array(
171
+			'match_id' => $matchdata['match'],
172
+			'player_id' => $matchdata['ctp1'],
173
+			'hole_id' => $matchdata['ctp1hole'],
174
+			'money' => $this->prizeMoney->getCtp()
175
+		);
176
+		$this->ctp->create($ctp1);
177
+		$ctp2 = array(
178
+			'match_id' => $matchdata['match'],
179
+			'player_id' => $matchdata['ctp2'],
180
+			'hole_id' => $matchdata['ctp2hole'],
181
+			'money' => $this->prizeMoney->getCtp()
182
+		);
183
+		$this->ctp->create($ctp2);
184
+
185
+		//calculate Gross winner and post to grossWinnersTable
186
+
187
+		$matchRound = $this->matchRoundRepo->getByMatch($matchdata['match']);
188
+
189
+
190
+		$lowGross = array();
191
+		foreach ($matchRound as $key => $match){
192
+			$lowGross[$match['player']->id] = $match['score'];
193
+		}
194
+		$arrayLowGross = array_keys($lowGross, min($lowGross));
195
+		foreach($arrayLowGross as $key => $lowgrossPlayer) {
196
+			$grossWinner = new Grosswinner;
197
+			$grossWinner->player_id = $lowgrossPlayer;
198
+			$grossWinner->match_id = $matchdata['match'];
199
+			$grossWinner->score = $lowGross[$lowgrossPlayer];
200
+			$grossWinner->money = $this->prizeMoney->getlowScore() / count($arrayLowGross);
201
+			$grossWinner->save();
202
+		}
203
+
204
+		//Calculate NET winner
205
+		$lowNet = array();
206
+		$scores =array();
207
+		foreach ($matchRound as $key => $match){
208
+			$netScore = ($match['score'] - round($match['player']->handicap,0)); //calculate net score
209
+			$lowNet[$match['player']->id] = $netScore;
210
+		}
211
+		$arrayLowNet = array_keys($lowNet, min($lowNet));
212
+
213
+		foreach($arrayLowNet as $key => $lownetPlayer) {
214
+			$netWinner = new Netwinner;
215
+			$netWinner->player_id = $lownetPlayer;
216
+			$netWinner->match_id = $matchdata['match'];
217
+			$netWinner->score = $lowNet[$lownetPlayer];
218
+			$netWinner->money = $this->prizeMoney->getlowScore() /  count($arrayLowNet);
219
+			$netWinner->save();
220
+		}
221
+
222
+		//Calculate Skins
223
+
224
+		//determine A and B players
225
+		//using pivot table match_player
226
+		$match = $this->match->find($matchdata['match']);
227
+		$aPlayers = array();
228
+		$bPlayers = array();
229
+		foreach($match->players as $player)
230
+		{
231
+			if($player->pivot->level_id == 1){
232
+				$aPlayers[] = $player->pivot->player_id;
233
+
234
+			}
235
+			if($player->pivot->level_id == 2){
236
+				$bPlayers[] = $player->pivot->player_id;
237
+			}
238
+		}
239
+
240
+		//Create Skins arrays
241
+		//player_id, 'holescores'
242
+		foreach($matchRound as $key => $round) {
243
+			if (in_array($round->player_id,$aPlayers)){
244
+				$aPlayersSkins[$key]['player_id'] = $round->player_id;
245
+				$aPlayersSkins[$key]['holescores'] = $round->holescores;
246
+			}
247
+			if (in_array($round->player_id,$bPlayers)){
248
+				$bPlayersSkins[$key]['player_id'] = $round->player_id;
249
+				$bPlayersSkins[$key]['holescores'] = $round->holescores;
250
+			}
251
+		}
252
+
253
+		//Run A Skins analysis
254
+		$scores = array();
255
+		foreach($aPlayersSkins as $key => $playerSkin){
256
+			foreach($playerSkin['holescores'] as $hole => $holescore){
257
+				$scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score'];
258
+			}
259
+		}
260
+
261
+		foreach($scores as $hole_id => $hole) {
262
+			$minScore = min($hole);
263
+			$winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score
264
+		}
265
+		$aSkinsWon = 0;
266
+		foreach($winners as $key => $winner) {
267
+			if(count($winner)  ===  1) {
268
+				//post to DB
269
+				$skinWinner = new Skin;
270
+				$skinWinner->player_id = $winner[0];
271
+				$skinWinner->level_id = 1;
272
+				$skinWinner->match_id = intval($matchdata['match']);
273
+				$skinWinner->hole_id = $key;
274
+				$skinWinner->save();
275
+				$aSkinsWon++;
276
+			}
277
+		}
278
+
279
+		//Run B Skins analysis
280
+		$scores = array();
281
+		foreach($bPlayersSkins as $key => $playerSkin){
282
+			foreach($playerSkin['holescores'] as $hole => $holescore){
283
+				$scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score'];
284
+			}
285
+		}
286
+
287
+		foreach($scores as $hole_id => $hole) {
288
+			$minScore = min($hole);
289
+			$winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score
290
+		}
291
+		$bSkinsWon = 0;
292
+		foreach($winners as $key => $winner) {
293
+			if(count($winner)  ===  1) {
294
+				//post to DB
295
+				$skinWinner = new Skin;
296
+				$skinWinner->player_id = $winner[0];
297
+				$skinWinner->level_id = 2;
298
+				$skinWinner->match_id = intval($matchdata['match']);
299
+				$skinWinner->hole_id = $key;
300
+				$skinWinner->save();
301
+				$bSkinsWon++;
302
+			}
303
+		}
304
+
305
+		$match =  Match::find($matchdata['match']);
306
+
307
+		//Need to add Carry over money if there no skins are won
308
+		//check for carry over money
309
+		$skinsamoney = $match->skinsamoney; // + carryover A money if any
310
+		$skinsbmoney = $match->skinsbmoney; // + carryover B money if any
311
+
312
+		if($aSkinsWon > 0) {
313
+			$moneyperskinA = $skinsamoney / $aSkinsWon;
314
+
315
+			$aSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 1)->get();
316
+			foreach ($aSkins as $askin){
317
+				$askin->money = $moneyperskinA;
318
+				$askin->save();
319
+			}
320
+		}
321
+
322
+		if($bSkinsWon > 0) {
323
+			$moneyperskinB = $skinsbmoney / $bSkinsWon;
324
+
325
+			$bSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 2)->get();
326
+			foreach ($bSkins as $bskin){
327
+				$bskin->money = $moneyperskinB;
328
+				$bskin->save();
329
+			}
330
+		}
331
+		//foreach player in pivot table create player and run handicap analysis
332
+		foreach($match->players as $matchplayer)
333
+		{
334
+			$player = Player::find($matchplayer->pivot->player_id);
335
+			$handicap = new Handicap($player);
336
+			$player->handicap = $handicap->calculate();
337
+			$player->save();
338
+		}
339
+
340
+		//Fire event to calculate money won and add to pivot table match_player
341
+		$this->events->fire('match.finalize', $match);
342
+
343
+	}
344
+
345
+	/**
346
+	 * Method to get match from input Match data
347
+	 *
348
+	 * @param mixed $matchdata
349
+	 * @return JSON object
350
+	 */
351
+	public function get($matchid)
352
+	{
353
+		$matchdata =  $this->matchRepo->get($matchid);
354
+		return $matchdata;
355
+	}
356
+
357
+
358
+
359
+	private function search($array, $key, $value)
360
+	{
361
+		$results = array();
362
+		if (is_array($array)) {
363
+			if (isset($array[$key]) && $array[$key] == $value) {
364
+				$results[] = $array;
365
+			}
366
+			foreach ($array as $subarray) {
367
+				$results = array_merge($results, $this->search($subarray, $key, $value));
368
+			}
369
+		}
370
+		return $results;
371
+	}
372 372
 }
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
         $aPlayerCount = 0;
68 68
         
69 69
         $bPlayerCount = 0;
70
-        foreach($matchdata['player'] as $player){
71
-            if ($player['level_id'] == '1'){
70
+        foreach ($matchdata['player'] as $player) {
71
+            if ($player['level_id'] == '1') {
72 72
                 $aPlayerCount++;
73 73
             }
74 74
             else {
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
         //check for carry over money and if there is add it to skins money
85 85
         $carryOver = new CarryOver;
86 86
         $carryOverMoney = $carryOver->calculate();
87
-        $matchdata['skinsamoney'] +=  $carryOverMoney[1];
88
-        $matchdata['skinsbmoney'] +=  $carryOverMoney[2];
87
+        $matchdata['skinsamoney'] += $carryOverMoney[1];
88
+        $matchdata['skinsbmoney'] += $carryOverMoney[2];
89 89
 
90 90
         //append current handicap and set winnings to 0 for each player
91 91
         foreach ($matchdata['player'] as $key=>$player) {
@@ -97,24 +97,24 @@  discard block
 block discarded – undo
97 97
 
98 98
         $matchid = $this->matchRepo->create($matchdata);
99 99
         $matchdata['match_id'] = $matchid;
100
-        $this->events->fire('match.create', array($matchdata));  // MatchHandler and teamMatchHandler are listening...
100
+        $this->events->fire('match.create', array($matchdata)); // MatchHandler and teamMatchHandler are listening...
101 101
 
102 102
         // Run for team Matches
103
-        if($matchdata['matchType'] === 'team' || $matchdata['matchType'] === 'both'){
103
+        if ($matchdata['matchType'] === 'team' || $matchdata['matchType'] === 'both') {
104 104
 
105
-            foreach ($matchdata['teamMatchUp1'] as $teamKey => $team){
105
+            foreach ($matchdata['teamMatchUp1'] as $teamKey => $team) {
106 106
                 $matchUp1[] = $this->search($matchdata['player'], 'team', $team);
107 107
             }
108 108
 
109 109
             //Save matchUp 1
110
-            $match1['match_id'] = $matchdata['match_id'];  // This is generated below and passed to listener
110
+            $match1['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener
111 111
             $match1['team_id'] = $matchUp1[0][0]['team'];
112 112
             $match1['player1'] = $matchUp1[0][0]['player_id'];
113 113
             $match1['player2'] = $matchUp1[0][1]['player_id'];
114 114
             $match1['opponent'] = $matchUp1[1][0]['team'];
115 115
             $this->teammatch->create($match1); //save to match table
116 116
 
117
-            $match1['match_id'] = $matchdata['match_id'];  // This is generated below and passed to listener
117
+            $match1['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener
118 118
             $match1['team_id'] = $matchUp1[1][0]['team'];
119 119
             $match1['player1'] = $matchUp1[1][0]['player_id'];
120 120
             $match1['player2'] = $matchUp1[1][1]['player_id'];
@@ -122,19 +122,19 @@  discard block
 block discarded – undo
122 122
             $this->teammatch->create($match1); //save to match table
123 123
 
124 124
 
125
-            foreach ($matchdata['teamMatchUp2'] as $teamKey => $team){
125
+            foreach ($matchdata['teamMatchUp2'] as $teamKey => $team) {
126 126
                 $matchUp2[] = $this->search($matchdata['player'], 'team', $team);
127 127
             }
128 128
 
129 129
             //Save matchUp 2
130
-            $match2['match_id'] = $matchdata['match_id'];  // This is generated below and passed to listener
130
+            $match2['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener
131 131
             $match2['team_id'] = $matchUp2[0][0]['team'];
132 132
             $match2['player1'] = $matchUp2[0][0]['player_id'];
133 133
             $match2['player2'] = $matchUp2[0][1]['player_id'];
134 134
             $match2['opponent'] = $matchUp2[1][0]['team'];
135 135
             $this->teammatch->create($match2); //save to match table
136 136
 
137
-            $match2['match_id'] = $matchdata['match_id'];  // This is generated below and passed to listener
137
+            $match2['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener
138 138
             $match2['team_id'] = $matchUp2[1][0]['team'];
139 139
             $match2['player1'] = $matchUp2[1][0]['player_id'];
140 140
             $match2['player2'] = $matchUp2[1][1]['player_id'];
@@ -142,19 +142,19 @@  discard block
 block discarded – undo
142 142
             $this->teammatch->create($match2); //save to match table
143 143
 
144 144
 
145
-            foreach ($matchdata['teamMatchUp3'] as $teamKey => $team){
145
+            foreach ($matchdata['teamMatchUp3'] as $teamKey => $team) {
146 146
                 $matchUp3[] = $this->search($matchdata['player'], 'team', $team);
147 147
             }
148 148
 
149 149
             //Save matchUp 3
150
-            $match3['match_id'] = $matchdata['match_id'];  // This is generated below and passed to listener
150
+            $match3['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener
151 151
             $match3['team_id'] = $matchUp3[0][0]['team'];
152 152
             $match3['player1'] = $matchUp3[0][0]['player_id'];
153 153
             $match3['player2'] = $matchUp3[0][1]['player_id'];
154 154
             $match3['opponent'] = $matchUp3[1][0]['team'];
155 155
             $this->teammatch->create($match3); //save to match table
156 156
 
157
-            $match3['match_id'] = $matchdata['match_id'];  // This is generated below and passed to listener
157
+            $match3['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener
158 158
             $match3['team_id'] = $matchUp3[1][0]['team'];
159 159
             $match3['player1'] = $matchUp3[1][0]['player_id'];
160 160
             $match3['player2'] = $matchUp3[1][1]['player_id'];
@@ -188,11 +188,11 @@  discard block
 block discarded – undo
188 188
 
189 189
 
190 190
         $lowGross = array();
191
-        foreach ($matchRound as $key => $match){
191
+        foreach ($matchRound as $key => $match) {
192 192
             $lowGross[$match['player']->id] = $match['score'];
193 193
         }
194 194
         $arrayLowGross = array_keys($lowGross, min($lowGross));
195
-        foreach($arrayLowGross as $key => $lowgrossPlayer) {
195
+        foreach ($arrayLowGross as $key => $lowgrossPlayer) {
196 196
             $grossWinner = new Grosswinner;
197 197
             $grossWinner->player_id = $lowgrossPlayer;
198 198
             $grossWinner->match_id = $matchdata['match'];
@@ -203,19 +203,19 @@  discard block
 block discarded – undo
203 203
 
204 204
         //Calculate NET winner
205 205
         $lowNet = array();
206
-        $scores =array();
207
-        foreach ($matchRound as $key => $match){
208
-            $netScore = ($match['score'] - round($match['player']->handicap,0)); //calculate net score
206
+        $scores = array();
207
+        foreach ($matchRound as $key => $match) {
208
+            $netScore = ($match['score'] - round($match['player']->handicap, 0)); //calculate net score
209 209
             $lowNet[$match['player']->id] = $netScore;
210 210
         }
211 211
         $arrayLowNet = array_keys($lowNet, min($lowNet));
212 212
 
213
-        foreach($arrayLowNet as $key => $lownetPlayer) {
213
+        foreach ($arrayLowNet as $key => $lownetPlayer) {
214 214
             $netWinner = new Netwinner;
215 215
             $netWinner->player_id = $lownetPlayer;
216 216
             $netWinner->match_id = $matchdata['match'];
217 217
             $netWinner->score = $lowNet[$lownetPlayer];
218
-            $netWinner->money = $this->prizeMoney->getlowScore() /  count($arrayLowNet);
218
+            $netWinner->money = $this->prizeMoney->getlowScore() / count($arrayLowNet);
219 219
             $netWinner->save();
220 220
         }
221 221
 
@@ -226,25 +226,25 @@  discard block
 block discarded – undo
226 226
         $match = $this->match->find($matchdata['match']);
227 227
         $aPlayers = array();
228 228
         $bPlayers = array();
229
-        foreach($match->players as $player)
229
+        foreach ($match->players as $player)
230 230
         {
231
-            if($player->pivot->level_id == 1){
231
+            if ($player->pivot->level_id == 1) {
232 232
                 $aPlayers[] = $player->pivot->player_id;
233 233
 
234 234
             }
235
-            if($player->pivot->level_id == 2){
235
+            if ($player->pivot->level_id == 2) {
236 236
                 $bPlayers[] = $player->pivot->player_id;
237 237
             }
238 238
         }
239 239
 
240 240
         //Create Skins arrays
241 241
         //player_id, 'holescores'
242
-        foreach($matchRound as $key => $round) {
243
-            if (in_array($round->player_id,$aPlayers)){
242
+        foreach ($matchRound as $key => $round) {
243
+            if (in_array($round->player_id, $aPlayers)) {
244 244
                 $aPlayersSkins[$key]['player_id'] = $round->player_id;
245 245
                 $aPlayersSkins[$key]['holescores'] = $round->holescores;
246 246
             }
247
-            if (in_array($round->player_id,$bPlayers)){
247
+            if (in_array($round->player_id, $bPlayers)) {
248 248
                 $bPlayersSkins[$key]['player_id'] = $round->player_id;
249 249
                 $bPlayersSkins[$key]['holescores'] = $round->holescores;
250 250
             }
@@ -252,19 +252,19 @@  discard block
 block discarded – undo
252 252
 
253 253
         //Run A Skins analysis
254 254
         $scores = array();
255
-        foreach($aPlayersSkins as $key => $playerSkin){
256
-            foreach($playerSkin['holescores'] as $hole => $holescore){
255
+        foreach ($aPlayersSkins as $key => $playerSkin) {
256
+            foreach ($playerSkin['holescores'] as $hole => $holescore) {
257 257
                 $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score'];
258 258
             }
259 259
         }
260 260
 
261
-        foreach($scores as $hole_id => $hole) {
261
+        foreach ($scores as $hole_id => $hole) {
262 262
             $minScore = min($hole);
263 263
             $winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score
264 264
         }
265 265
         $aSkinsWon = 0;
266
-        foreach($winners as $key => $winner) {
267
-            if(count($winner)  ===  1) {
266
+        foreach ($winners as $key => $winner) {
267
+            if (count($winner) === 1) {
268 268
                 //post to DB
269 269
                 $skinWinner = new Skin;
270 270
                 $skinWinner->player_id = $winner[0];
@@ -278,19 +278,19 @@  discard block
 block discarded – undo
278 278
 
279 279
         //Run B Skins analysis
280 280
         $scores = array();
281
-        foreach($bPlayersSkins as $key => $playerSkin){
282
-            foreach($playerSkin['holescores'] as $hole => $holescore){
281
+        foreach ($bPlayersSkins as $key => $playerSkin) {
282
+            foreach ($playerSkin['holescores'] as $hole => $holescore) {
283 283
                 $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score'];
284 284
             }
285 285
         }
286 286
 
287
-        foreach($scores as $hole_id => $hole) {
287
+        foreach ($scores as $hole_id => $hole) {
288 288
             $minScore = min($hole);
289 289
             $winners[$hole_id] = array_keys($hole, min($hole)); //gets player id of lowest score
290 290
         }
291 291
         $bSkinsWon = 0;
292
-        foreach($winners as $key => $winner) {
293
-            if(count($winner)  ===  1) {
292
+        foreach ($winners as $key => $winner) {
293
+            if (count($winner) === 1) {
294 294
                 //post to DB
295 295
                 $skinWinner = new Skin;
296 296
                 $skinWinner->player_id = $winner[0];
@@ -302,34 +302,34 @@  discard block
 block discarded – undo
302 302
             }
303 303
         }
304 304
 
305
-        $match =  Match::find($matchdata['match']);
305
+        $match = Match::find($matchdata['match']);
306 306
 
307 307
         //Need to add Carry over money if there no skins are won
308 308
         //check for carry over money
309 309
         $skinsamoney = $match->skinsamoney; // + carryover A money if any
310 310
         $skinsbmoney = $match->skinsbmoney; // + carryover B money if any
311 311
 
312
-        if($aSkinsWon > 0) {
312
+        if ($aSkinsWon > 0) {
313 313
             $moneyperskinA = $skinsamoney / $aSkinsWon;
314 314
 
315 315
             $aSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 1)->get();
316
-            foreach ($aSkins as $askin){
316
+            foreach ($aSkins as $askin) {
317 317
                 $askin->money = $moneyperskinA;
318 318
                 $askin->save();
319 319
             }
320 320
         }
321 321
 
322
-        if($bSkinsWon > 0) {
322
+        if ($bSkinsWon > 0) {
323 323
             $moneyperskinB = $skinsbmoney / $bSkinsWon;
324 324
 
325 325
             $bSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 2)->get();
326
-            foreach ($bSkins as $bskin){
326
+            foreach ($bSkins as $bskin) {
327 327
                 $bskin->money = $moneyperskinB;
328 328
                 $bskin->save();
329 329
             }
330 330
         }
331 331
         //foreach player in pivot table create player and run handicap analysis
332
-        foreach($match->players as $matchplayer)
332
+        foreach ($match->players as $matchplayer)
333 333
         {
334 334
             $player = Player::find($matchplayer->pivot->player_id);
335 335
             $handicap = new Handicap($player);
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
      */
351 351
     public function get($matchid)
352 352
     {
353
-        $matchdata =  $this->matchRepo->get($matchid);
353
+        $matchdata = $this->matchRepo->get($matchid);
354 354
         return $matchdata;
355 355
     }
356 356
 
Please login to merge, or discard this patch.
Braces   +22 added lines, -26 removed lines patch added patch discarded remove patch
@@ -17,8 +17,7 @@  discard block
 block discarded – undo
17 17
 /**
18 18
  * Our MatchService, containing all useful methods for business logic around Matches
19 19
  */
20
-class MatchService
21
-{
20
+class MatchService {
22 21
     // Containing our matchRepository to make all our database calls to
23 22
     protected $matchRepo;
24 23
 
@@ -67,11 +66,10 @@  discard block
 block discarded – undo
67 66
         $aPlayerCount = 0;
68 67
         
69 68
         $bPlayerCount = 0;
70
-        foreach($matchdata['player'] as $player){
71
-            if ($player['level_id'] == '1'){
69
+        foreach($matchdata['player'] as $player) {
70
+            if ($player['level_id'] == '1') {
72 71
                 $aPlayerCount++;
73
-            }
74
-            else {
72
+            } else {
75 73
                 $bPlayerCount++;
76 74
             }
77 75
             $totalPlayers++;
@@ -100,9 +98,9 @@  discard block
 block discarded – undo
100 98
         $this->events->fire('match.create', array($matchdata));  // MatchHandler and teamMatchHandler are listening...
101 99
 
102 100
         // Run for team Matches
103
-        if($matchdata['matchType'] === 'team' || $matchdata['matchType'] === 'both'){
101
+        if($matchdata['matchType'] === 'team' || $matchdata['matchType'] === 'both') {
104 102
 
105
-            foreach ($matchdata['teamMatchUp1'] as $teamKey => $team){
103
+            foreach ($matchdata['teamMatchUp1'] as $teamKey => $team) {
106 104
                 $matchUp1[] = $this->search($matchdata['player'], 'team', $team);
107 105
             }
108 106
 
@@ -122,7 +120,7 @@  discard block
 block discarded – undo
122 120
             $this->teammatch->create($match1); //save to match table
123 121
 
124 122
 
125
-            foreach ($matchdata['teamMatchUp2'] as $teamKey => $team){
123
+            foreach ($matchdata['teamMatchUp2'] as $teamKey => $team) {
126 124
                 $matchUp2[] = $this->search($matchdata['player'], 'team', $team);
127 125
             }
128 126
 
@@ -142,7 +140,7 @@  discard block
 block discarded – undo
142 140
             $this->teammatch->create($match2); //save to match table
143 141
 
144 142
 
145
-            foreach ($matchdata['teamMatchUp3'] as $teamKey => $team){
143
+            foreach ($matchdata['teamMatchUp3'] as $teamKey => $team) {
146 144
                 $matchUp3[] = $this->search($matchdata['player'], 'team', $team);
147 145
             }
148 146
 
@@ -188,7 +186,7 @@  discard block
 block discarded – undo
188 186
 
189 187
 
190 188
         $lowGross = array();
191
-        foreach ($matchRound as $key => $match){
189
+        foreach ($matchRound as $key => $match) {
192 190
             $lowGross[$match['player']->id] = $match['score'];
193 191
         }
194 192
         $arrayLowGross = array_keys($lowGross, min($lowGross));
@@ -204,7 +202,7 @@  discard block
 block discarded – undo
204 202
         //Calculate NET winner
205 203
         $lowNet = array();
206 204
         $scores =array();
207
-        foreach ($matchRound as $key => $match){
205
+        foreach ($matchRound as $key => $match) {
208 206
             $netScore = ($match['score'] - round($match['player']->handicap,0)); //calculate net score
209 207
             $lowNet[$match['player']->id] = $netScore;
210 208
         }
@@ -226,13 +224,12 @@  discard block
 block discarded – undo
226 224
         $match = $this->match->find($matchdata['match']);
227 225
         $aPlayers = array();
228 226
         $bPlayers = array();
229
-        foreach($match->players as $player)
230
-        {
231
-            if($player->pivot->level_id == 1){
227
+        foreach($match->players as $player) {
228
+            if($player->pivot->level_id == 1) {
232 229
                 $aPlayers[] = $player->pivot->player_id;
233 230
 
234 231
             }
235
-            if($player->pivot->level_id == 2){
232
+            if($player->pivot->level_id == 2) {
236 233
                 $bPlayers[] = $player->pivot->player_id;
237 234
             }
238 235
         }
@@ -240,11 +237,11 @@  discard block
 block discarded – undo
240 237
         //Create Skins arrays
241 238
         //player_id, 'holescores'
242 239
         foreach($matchRound as $key => $round) {
243
-            if (in_array($round->player_id,$aPlayers)){
240
+            if (in_array($round->player_id,$aPlayers)) {
244 241
                 $aPlayersSkins[$key]['player_id'] = $round->player_id;
245 242
                 $aPlayersSkins[$key]['holescores'] = $round->holescores;
246 243
             }
247
-            if (in_array($round->player_id,$bPlayers)){
244
+            if (in_array($round->player_id,$bPlayers)) {
248 245
                 $bPlayersSkins[$key]['player_id'] = $round->player_id;
249 246
                 $bPlayersSkins[$key]['holescores'] = $round->holescores;
250 247
             }
@@ -252,8 +249,8 @@  discard block
 block discarded – undo
252 249
 
253 250
         //Run A Skins analysis
254 251
         $scores = array();
255
-        foreach($aPlayersSkins as $key => $playerSkin){
256
-            foreach($playerSkin['holescores'] as $hole => $holescore){
252
+        foreach($aPlayersSkins as $key => $playerSkin) {
253
+            foreach($playerSkin['holescores'] as $hole => $holescore) {
257 254
                 $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score'];
258 255
             }
259 256
         }
@@ -278,8 +275,8 @@  discard block
 block discarded – undo
278 275
 
279 276
         //Run B Skins analysis
280 277
         $scores = array();
281
-        foreach($bPlayersSkins as $key => $playerSkin){
282
-            foreach($playerSkin['holescores'] as $hole => $holescore){
278
+        foreach($bPlayersSkins as $key => $playerSkin) {
279
+            foreach($playerSkin['holescores'] as $hole => $holescore) {
283 280
                 $scores[$holescore['hole_id']][$playerSkin['player_id']] = $holescore['score'];
284 281
             }
285 282
         }
@@ -313,7 +310,7 @@  discard block
 block discarded – undo
313 310
             $moneyperskinA = $skinsamoney / $aSkinsWon;
314 311
 
315 312
             $aSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 1)->get();
316
-            foreach ($aSkins as $askin){
313
+            foreach ($aSkins as $askin) {
317 314
                 $askin->money = $moneyperskinA;
318 315
                 $askin->save();
319 316
             }
@@ -323,14 +320,13 @@  discard block
 block discarded – undo
323 320
             $moneyperskinB = $skinsbmoney / $bSkinsWon;
324 321
 
325 322
             $bSkins = Skin::where('match_id', '=', $matchdata['match'])->where('level_id', '=', 2)->get();
326
-            foreach ($bSkins as $bskin){
323
+            foreach ($bSkins as $bskin) {
327 324
                 $bskin->money = $moneyperskinB;
328 325
                 $bskin->save();
329 326
             }
330 327
         }
331 328
         //foreach player in pivot table create player and run handicap analysis
332
-        foreach($match->players as $matchplayer)
333
-        {
329
+        foreach($match->players as $matchplayer) {
334 330
             $player = Player::find($matchplayer->pivot->player_id);
335 331
             $handicap = new Handicap($player);
336 332
             $player->handicap = $handicap->calculate();
Please login to merge, or discard this patch.
app/models/Teammatch.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -2,22 +2,22 @@
 block discarded – undo
2 2
 
3 3
 class Teammatch extends Eloquent {
4 4
 
5
-    protected $table = 'teammatches';
6
-    protected $fillable = ['match_id', 'team_id', 'player1', 'player2', 'opponent'];
5
+	protected $table = 'teammatches';
6
+	protected $fillable = ['match_id', 'team_id', 'player1', 'player2', 'opponent'];
7 7
 
8
-    public function match()
9
-    {
10
-        return $this->belongsTo('Match');
11
-    }
8
+	public function match()
9
+	{
10
+		return $this->belongsTo('Match');
11
+	}
12 12
 
13
-    public function team()
14
-    {
15
-        return $this->belongsTo('Team');
16
-    }
13
+	public function team()
14
+	{
15
+		return $this->belongsTo('Team');
16
+	}
17 17
 
18
-    public function player()
19
-    {
20
-        return $this->belongsTo('Player');
21
-    }
18
+	public function player()
19
+	{
20
+		return $this->belongsTo('Player');
21
+	}
22 22
 
23 23
 }
24 24
\ No newline at end of file
Please login to merge, or discard this patch.
app/routes.php 3 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -12,20 +12,20 @@
 block discarded – undo
12 12
 */
13 13
 Route::get('/', function()
14 14
 {
15
-    return Redirect::to('schedule');
15
+	return Redirect::to('schedule');
16 16
 });
17 17
 
18 18
 Route::get('/test', function()
19 19
 {
20 20
 
21
-    $players = new \Player();
22
-    $players = $players->all();
23
-    //echo $players;
21
+	$players = new \Player();
22
+	$players = $players->all();
23
+	//echo $players;
24 24
    foreach ($players as $player){
25
-       $handicap = new \GolfLeague\Handicap($player);
26
-       $player->handicap = $handicap->calculate();
27
-       echo $player->name . " " . $player->handicap . "<br>";
28
-       $player->save();
25
+	   $handicap = new \GolfLeague\Handicap($player);
26
+	   $player->handicap = $handicap->calculate();
27
+	   echo $player->name . " " . $player->handicap . "<br>";
28
+	   $player->save();
29 29
    }
30 30
 });
31 31
 
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -21,10 +21,10 @@  discard block
 block discarded – undo
21 21
     $players = new \Player();
22 22
     $players = $players->all();
23 23
     //echo $players;
24
-   foreach ($players as $player){
24
+   foreach ($players as $player) {
25 25
        $handicap = new \GolfLeague\Handicap($player);
26 26
        $player->handicap = $handicap->calculate();
27
-       echo $player->name . " " . $player->handicap . "<br>";
27
+       echo $player->name." ".$player->handicap."<br>";
28 28
        $player->save();
29 29
    }
30 30
 });
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 Route::resource('leaderboard', 'LeaderboardController');
62 62
 Route::resource('tournament', 'TournamentController');
63 63
 Route::resource('tournamentLeaderboard', 'TournamentLeaderboardController');
64
-Route::resource('teammatches','TeamMatchesController');
65
-Route::get('teammatches/points/{year}','TeamMatchesController@getPointsByYear');
64
+Route::resource('teammatches', 'TeamMatchesController');
65
+Route::get('teammatches/points/{year}', 'TeamMatchesController@getPointsByYear');
66 66
 Route::resource('team', 'TeamController');
67 67
 Route::get('team/year/{year}', 'TeamController@findByYear');
68 68
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
     $players = new \Player();
22 22
     $players = $players->all();
23 23
     //echo $players;
24
-   foreach ($players as $player){
24
+   foreach ($players as $player) {
25 25
        $handicap = new \GolfLeague\Handicap($player);
26 26
        $player->handicap = $handicap->calculate();
27 27
        echo $player->name . " " . $player->handicap . "<br>";
Please login to merge, or discard this patch.
app/controllers/TeamController.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -4,13 +4,13 @@  discard block
 block discarded – undo
4 4
 
5 5
 class TeamController extends \BaseController {
6 6
 
7
-    private $team;
7
+	private $team;
8 8
 
9
-    public function __construct(TeamRepo $team)
10
-    {
11
-        $this->team = $team;
12
-    }
13
-    /**
9
+	public function __construct(TeamRepo $team)
10
+	{
11
+		$this->team = $team;
12
+	}
13
+	/**
14 14
 	 * Display a listing of the resource.
15 15
 	 *
16 16
 	 * @return Response
@@ -42,15 +42,15 @@  discard block
 block discarded – undo
42 42
 		//
43 43
 	}
44 44
 
45
-    /**
46
-     * Display a listing of the teams by year .
47
-     *
48
-     * @return Response
49
-     */
45
+	/**
46
+	 * Display a listing of the teams by year .
47
+	 *
48
+	 * @return Response
49
+	 */
50 50
 	public function findByYear($year)
51
-    {
52
-        return $this->team->findByYear($year);
53
-    }
51
+	{
52
+		return $this->team->findByYear($year);
53
+	}
54 54
 
55 55
 	/**
56 56
 	 * Display the specified resource.
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@
 block discarded – undo
48 48
      * @return Response
49 49
      */
50 50
 	public function findByYear($year)
51
-    {
51
+	{
52 52
         return $this->team->findByYear($year);
53 53
     }
54 54
 
Please login to merge, or discard this patch.
app/controllers/MatchesController.php 3 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -76,11 +76,11 @@
 block discarded – undo
76 76
         $teamMatchDate = new Carbon('first day of January 2017');
77 77
 		$matchDate = new Carbon($data['date']);
78 78
 
79
-		if($matchDate >= $teamMatchDate){
79
+		if ($matchDate >= $teamMatchDate) {
80 80
 		    $enterView = 'EnterTeamMatch';
81 81
         }
82 82
 
83
-		if($today <= $matchDate){
83
+		if ($today <= $matchDate) {
84 84
 			//Show Editable View
85 85
 			$view = View::make($enterView, $data);
86 86
 			return $view;
Please login to merge, or discard this patch.
Braces   +3 added lines, -4 removed lines patch added patch discarded remove patch
@@ -76,16 +76,15 @@
 block discarded – undo
76 76
         $teamMatchDate = new Carbon('first day of January 2017');
77 77
 		$matchDate = new Carbon($data['date']);
78 78
 
79
-		if($matchDate >= $teamMatchDate){
79
+		if($matchDate >= $teamMatchDate) {
80 80
 		    $enterView = 'EnterTeamMatch';
81 81
         }
82 82
 
83
-		if($today <= $matchDate){
83
+		if($today <= $matchDate) {
84 84
 			//Show Editable View
85 85
 			$view = View::make($enterView, $data);
86 86
 			return $view;
87
-		}
88
-		else {
87
+		} else {
89 88
 			//Show Readonly View
90 89
 			$view = View::make('ViewMatch', $data);
91 90
 			return $view;
Please login to merge, or discard this patch.
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -7,11 +7,11 @@  discard block
 block discarded – undo
7 7
 class MatchesController extends \BaseController {
8 8
 
9 9
 
10
-    public function __construct(MatchService $match, MatchRepository $matchRepo)
11
-    {
12
-        $this->match = $match;
10
+	public function __construct(MatchService $match, MatchRepository $matchRepo)
11
+	{
12
+		$this->match = $match;
13 13
 		$this->matchRepo = $matchRepo;
14
-    }
14
+	}
15 15
 
16 16
 	/**
17 17
 	 * Display a listing of the resource.
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	public function create()
33 33
 	{
34 34
 		$view = View::make('creatematch');
35
-        return $view;
35
+		return $view;
36 36
 	}
37 37
 
38 38
 	/**
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 */
43 43
 	public function store()
44 44
 	{
45
-	    $input = Input::all();
45
+		$input = Input::all();
46 46
 		return $this->match->create($input);
47 47
 	}
48 48
 
@@ -68,20 +68,20 @@  discard block
 block discarded – undo
68 68
 	public function edit($id)
69 69
 	{
70 70
 
71
-        $enterView = 'EnterTeamMatch';
72
-	    $data = $this->match->get($id);
73
-        $view = View::make($enterView, $data);
74
-        return $view;
71
+		$enterView = 'EnterTeamMatch';
72
+		$data = $this->match->get($id);
73
+		$view = View::make($enterView, $data);
74
+		return $view;
75 75
 
76
-	    // Logic to allow editable for day of match only
76
+		// Logic to allow editable for day of match only
77 77
 		$today = Carbon::today();
78 78
 
79
-        $teamMatchDate = new Carbon('first day of January 2017');
79
+		$teamMatchDate = new Carbon('first day of January 2017');
80 80
 		$matchDate = new Carbon($data['date']);
81 81
 
82 82
 		if($matchDate >= $teamMatchDate){
83
-		    $enterView = 'EnterTeamMatch';
84
-        }
83
+			$enterView = 'EnterTeamMatch';
84
+		}
85 85
 
86 86
 		if($today <= $matchDate){
87 87
 			//Show Editable View
Please login to merge, or discard this patch.
app/library/Storage/EloquentRepositories/EloquentTeamRepository.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -4,37 +4,37 @@
 block discarded – undo
4 4
 
5 5
 class EloquentTeamRepository implements TeamRepository
6 6
 {
7
-    private $team;
8
-
9
-    public function __construct(Team $team)
10
-    {
11
-        $this->team = $team;
12
-    }
13
-
14
-    public function all()
15
-    {
16
-        return $this->team->all();
17
-    }
18
-    public function findById($id)
19
-    {
20
-        return $this->team->where('id', '=', $id)->get();
21
-    }
22
-
23
-    public function findByYear($year)
24
-    {
25
-        return $this->team->whereYear('created_at', '=', $year)->get();
26
-    }
27
-
28
-    public function create($input)
29
-    {
30
-        $this->team->create($input);
31
-    }
32
-
33
-    public function update($team)
34
-    {
35
-        $updateTeam = $this->team->where('id', '=', $id)->get();
36
-        $updateTeam = $team;
37
-        $updateTeam->save();
38
-    }
7
+	private $team;
8
+
9
+	public function __construct(Team $team)
10
+	{
11
+		$this->team = $team;
12
+	}
13
+
14
+	public function all()
15
+	{
16
+		return $this->team->all();
17
+	}
18
+	public function findById($id)
19
+	{
20
+		return $this->team->where('id', '=', $id)->get();
21
+	}
22
+
23
+	public function findByYear($year)
24
+	{
25
+		return $this->team->whereYear('created_at', '=', $year)->get();
26
+	}
27
+
28
+	public function create($input)
29
+	{
30
+		$this->team->create($input);
31
+	}
32
+
33
+	public function update($team)
34
+	{
35
+		$updateTeam = $this->team->where('id', '=', $id)->get();
36
+		$updateTeam = $team;
37
+		$updateTeam->save();
38
+	}
39 39
 
40 40
 }
41 41
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,8 +2,7 @@
 block discarded – undo
2 2
 
3 3
 use \Team as Team;
4 4
 
5
-class EloquentTeamRepository implements TeamRepository
6
-{
5
+class EloquentTeamRepository implements TeamRepository {
7 6
     private $team;
8 7
 
9 8
     public function __construct(Team $team)
Please login to merge, or discard this patch.
app/library/Storage/EloquentRepositories/EloquentTeamMatchesRepository.php 2 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -14,35 +14,35 @@
 block discarded – undo
14 14
 
15 15
 class EloquentTeamMatchesRepository implements TeamMatchesRepository
16 16
 {
17
-    private $teamMatch;
18
-
19
-    public function __construct(Teammatch $teamMatch)
20
-    {
21
-        $this->teamMatch = $teamMatch;
22
-    }
23
-
24
-    public function all()
25
-    {
26
-        // TODO: Implement all() method.
27
-    }
28
-
29
-    public function findById($id)
30
-    {
31
-        // TODO: Implement findById() method.
32
-    }
33
-
34
-    public function create($input)
35
-    {
36
-        // TODO: Implement create() method.
37
-    }
38
-
39
-    public function update($team)
40
-    {
41
-        // TODO: Implement update() method.
42
-    }
43
-
44
-    public function getByMatch($matchId)
45
-    {
46
-        return $this->teamMatch->where('match_id', '=', $matchId)->get();
47
-    }
17
+	private $teamMatch;
18
+
19
+	public function __construct(Teammatch $teamMatch)
20
+	{
21
+		$this->teamMatch = $teamMatch;
22
+	}
23
+
24
+	public function all()
25
+	{
26
+		// TODO: Implement all() method.
27
+	}
28
+
29
+	public function findById($id)
30
+	{
31
+		// TODO: Implement findById() method.
32
+	}
33
+
34
+	public function create($input)
35
+	{
36
+		// TODO: Implement create() method.
37
+	}
38
+
39
+	public function update($team)
40
+	{
41
+		// TODO: Implement update() method.
42
+	}
43
+
44
+	public function getByMatch($matchId)
45
+	{
46
+		return $this->teamMatch->where('match_id', '=', $matchId)->get();
47
+	}
48 48
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,8 +12,7 @@
 block discarded – undo
12 12
 
13 13
 use GolfLeague\Storage\Team\TeamMatchesRepository;
14 14
 
15
-class EloquentTeamMatchesRepository implements TeamMatchesRepository
16
-{
15
+class EloquentTeamMatchesRepository implements TeamMatchesRepository {
17 16
     private $teamMatch;
18 17
 
19 18
     public function __construct(Teammatch $teamMatch)
Please login to merge, or discard this patch.