1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Association; |
6
|
|
|
use App\Result; |
7
|
|
|
use App\TeamResult; |
8
|
|
|
use App\ResultSubmission; |
9
|
|
|
use Illuminate\Http\Request; |
10
|
|
|
|
11
|
|
|
class ResultSubmissionsController extends Controller |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Display a listing of the resource. |
15
|
|
|
* |
16
|
|
|
* @return \Illuminate\Http\Response |
17
|
|
|
*/ |
18
|
|
|
public function index(Association $association) |
19
|
|
|
{ |
20
|
|
|
return view('result_submissions.approve', ['association' => $association]); |
|
|
|
|
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Show the form for creating a new resource. |
25
|
|
|
* |
26
|
|
|
* @return \Illuminate\Http\Response |
27
|
|
|
*/ |
28
|
|
|
public function create() |
29
|
|
|
{ |
30
|
|
|
// |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Store a newly created resource in storage. |
35
|
|
|
* |
36
|
|
|
* @param \Illuminate\Http\Request $request |
37
|
|
|
* @return \Illuminate\Http\Response |
38
|
|
|
*/ |
39
|
|
|
public function store(Request $request) |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
// |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Display the specified resource. |
46
|
|
|
* |
47
|
|
|
* @param int $id |
48
|
|
|
* @return \Illuminate\Http\Response |
49
|
|
|
*/ |
50
|
|
|
public function show($id) |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
// |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Show the form for editing the specified resource. |
57
|
|
|
* |
58
|
|
|
* @param int $id |
59
|
|
|
* @return \Illuminate\Http\Response |
60
|
|
|
*/ |
61
|
|
|
public function edit($id) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
// |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Update the specified resource in storage. |
68
|
|
|
* |
69
|
|
|
* @param \Illuminate\Http\Request $request |
70
|
|
|
* @param int $id |
71
|
|
|
* @return \Illuminate\Http\Response |
72
|
|
|
*/ |
73
|
|
|
public function update(Request $request, $id) |
74
|
|
|
{ |
75
|
|
|
$submission = ResultSubmission::find($id); |
76
|
|
|
|
77
|
|
|
if ($request->delete == 'delete') { |
78
|
|
|
$submission->delete(); |
79
|
|
|
} |
80
|
|
|
else { |
81
|
|
|
$result = Result::where('match_id', $submission->match_id)->first(); |
82
|
|
|
|
83
|
|
|
if (empty($result)) { |
84
|
|
|
$result = new Result(); |
85
|
|
|
$result->match_id = $submission->match_id; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$result->home_team_id = $submission->match->home_team_id; |
89
|
|
|
$result->away_team_id = $submission->match->away_team_id; |
90
|
|
|
$result->home_team_score = $submission->home_team_score; |
91
|
|
|
$result->away_team_score = $submission->away_team_score; |
92
|
|
|
|
93
|
|
|
$result->save(); |
94
|
|
|
|
95
|
|
|
// FIXME: need to look up / overwrite existing team results as applicable: |
96
|
|
|
// home team result: |
97
|
|
|
$team_result = new TeamResult(); |
98
|
|
|
$team_result->schedule_id = $submission->match->schedule_id; |
99
|
|
|
$team_result->match_id = $submission->match->id; |
100
|
|
|
$team_result->team_id = $result->home_team_id; |
101
|
|
|
$team_result->points = $result->home_team_score; |
102
|
|
|
$team_result->win = $result->home_team_id == $submission->win_team_id ? 1 : 0; |
103
|
|
|
$team_result->loss = $result->home_team_id != $submission->win_team_id ? 1 : 0; |
104
|
|
|
$team_result->tie = 0; |
105
|
|
|
$team_result->save(); |
106
|
|
|
|
107
|
|
|
// away team result; |
108
|
|
|
$team_result = new TeamResult(); |
109
|
|
|
$team_result->schedule_id = $submission->match->schedule_id; |
110
|
|
|
$team_result->match_id = $submission->match->id; |
111
|
|
|
$team_result->team_id = $result->away_team_id; |
112
|
|
|
$team_result->points = $result->away_team_score; |
113
|
|
|
$team_result->win = $result->away_team_id == $submission->win_team_id ? 1 : 0; |
114
|
|
|
$team_result->loss = $result->away_team_id != $submission->win_team_id ? 1 : 0; |
115
|
|
|
$team_result->tie = 0; |
116
|
|
|
$team_result->save(); |
117
|
|
|
|
118
|
|
|
$submission->approved = TRUE; |
119
|
|
|
$submission->save(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$url = $request->url; |
123
|
|
|
|
124
|
|
|
if (!empty($url)) { |
125
|
|
|
return redirect($url)->with('success', 'Data saved successfully!'); |
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return redirect()->route('user', ['id' => \Auth::user()->id]); |
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Remove the specified resource from storage. |
133
|
|
|
* |
134
|
|
|
* @param int $id |
135
|
|
|
* @return \Illuminate\Http\Response |
136
|
|
|
*/ |
137
|
|
|
public function destroy($id) |
|
|
|
|
138
|
|
|
{ |
139
|
|
|
// |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|