|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use GolfLeague\Services\MatchService as MatchService; |
|
4
|
|
|
use GolfLeague\Storage\Match\MatchRepository as MatchRepository; |
|
5
|
|
|
use Carbon\Carbon; |
|
6
|
|
|
|
|
7
|
|
|
class MatchesController extends \BaseController { |
|
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
public function __construct(MatchService $match, MatchRepository $matchRepo) |
|
11
|
|
|
{ |
|
12
|
|
|
$this->match = $match; |
|
13
|
|
|
$this->matchRepo = $matchRepo; |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Display a listing of the resource. |
|
18
|
|
|
* |
|
19
|
|
|
* @return Response |
|
20
|
|
|
*/ |
|
21
|
|
|
public function index() |
|
22
|
|
|
{ |
|
23
|
|
|
return $this->matchRepo->all(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Show the form for creating a new resource. |
|
29
|
|
|
* |
|
30
|
|
|
* @return Response |
|
31
|
|
|
*/ |
|
32
|
|
|
public function create() |
|
33
|
|
|
{ |
|
34
|
|
|
$view = View::make('creatematch'); |
|
35
|
|
|
return $view; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Store a newly created resource in storage. |
|
40
|
|
|
* |
|
41
|
|
|
* @return Response |
|
42
|
|
|
*/ |
|
43
|
|
|
public function store() |
|
44
|
|
|
{ |
|
45
|
|
|
$input = Input::all(); |
|
46
|
|
|
return $this->match->create($input); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Display the specified resource. |
|
52
|
|
|
* |
|
53
|
|
|
* @param int $id |
|
54
|
|
|
* @return Response |
|
55
|
|
|
*/ |
|
56
|
|
|
public function show($id) |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->matchRepo->get($id); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Show the form for editing the specified resource. |
|
64
|
|
|
* |
|
65
|
|
|
* @param int $id |
|
66
|
|
|
* @return Response |
|
67
|
|
|
*/ |
|
68
|
|
|
public function edit($id) |
|
69
|
|
|
{ |
|
70
|
|
|
|
|
71
|
|
|
$enterView = 'EnterTeamMatch'; |
|
72
|
|
|
$data = $this->match->get($id); |
|
73
|
|
|
$view = View::make($enterView, $data); |
|
74
|
|
|
return $view; |
|
75
|
|
|
|
|
76
|
|
|
// Logic to allow editable for day of match only |
|
77
|
|
|
$today = Carbon::today(); |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
$teamMatchDate = new Carbon('first day of January 2017'); |
|
80
|
|
|
$matchDate = new Carbon($data['date']); |
|
81
|
|
|
|
|
82
|
|
|
if($matchDate >= $teamMatchDate){ |
|
83
|
|
|
$enterView = 'EnterTeamMatch'; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
if($today <= $matchDate){ |
|
87
|
|
|
//Show Editable View |
|
88
|
|
|
$view = View::make($enterView, $data); |
|
89
|
|
|
return $view; |
|
90
|
|
|
} |
|
91
|
|
|
else { |
|
92
|
|
|
//Show Readonly View |
|
93
|
|
|
$view = View::make('ViewMatch', $data); |
|
94
|
|
|
return $view; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Update the specified resource in storage. |
|
101
|
|
|
* |
|
102
|
|
|
* @param int $id |
|
103
|
|
|
* @return Response |
|
104
|
|
|
*/ |
|
105
|
|
|
public function update($id) |
|
106
|
|
|
{ |
|
107
|
|
|
// |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Remove the specified resource from storage. |
|
113
|
|
|
* |
|
114
|
|
|
* @param int $id |
|
115
|
|
|
* @return Response |
|
116
|
|
|
*/ |
|
117
|
|
|
public function destroy($id) |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->matchRepo->delete($id); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.