1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace plunner\Http\Controllers\Employees\Planners; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Illuminate\Support\Facades\Response; |
7
|
|
|
use plunner\Group; |
8
|
|
|
use plunner\Http\Controllers\Controller; |
9
|
|
|
use plunner\Http\Requests; |
10
|
|
|
use plunner\Http\Requests\Employees\Meeting\MeetingRequest; |
11
|
|
|
use plunner\Meeting; |
12
|
|
|
|
13
|
|
|
class MeetingsController extends Controller |
14
|
|
|
{ |
15
|
45 |
|
public function __construct() |
16
|
|
|
{ |
17
|
45 |
|
config(['auth.model' => \plunner\Planner::class]); |
18
|
45 |
|
config(['jwt.user' => \plunner\Planner::class]); |
19
|
45 |
|
$this->middleware('jwt.authandrefresh:mode-en'); |
20
|
45 |
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Display a listing of the resource. |
24
|
|
|
* ?current=1 -> to exclude old planed meetings |
25
|
|
|
* |
26
|
|
|
* @param int $groupId |
27
|
|
|
* @param Request $request needed for get query to get only current planed meetings (to be planned are all retrieved) |
28
|
|
|
* @return mixed |
29
|
|
|
*/ |
30
|
6 |
|
public function index($groupId, Request $request) |
31
|
|
|
{ |
32
|
6 |
|
$group = Group::findOrFail($groupId); |
33
|
6 |
|
$this->authorize($group); |
34
|
6 |
|
$meetings = $group->meetings(); |
35
|
6 |
|
if ($request->query('current')) |
36
|
3 |
|
$meetings->where(function ($query) { //parenthesis for conditions ...(C1 OR C2)... |
37
|
3 |
|
$query->where('start_time', '=', NULL);//to be planned |
38
|
|
|
//datetime to consider timezone, don't use mysql NOW() |
39
|
3 |
|
$query->orWhere('start_time', '>=', new \DateTime());//planned |
40
|
3 |
|
}); |
41
|
|
|
|
42
|
6 |
|
return $meetings->get(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Display the specified resource. |
47
|
|
|
* |
48
|
|
|
* @param int $groupId |
49
|
|
|
* @param int $meetingId |
50
|
|
|
* @return mixed |
51
|
|
|
*/ |
52
|
9 |
|
public function show($groupId, $meetingId) |
53
|
|
|
{ |
54
|
9 |
|
$group = Group::findOrFail($groupId); |
55
|
9 |
|
$this->authorize($group); |
56
|
|
|
//Meeting::where('group_id', $groupId)->findOrFail($meetingId); |
57
|
|
|
//it is good but expensive and useless for the user experience |
58
|
6 |
|
$meeting = Meeting::findOrFail($meetingId); |
59
|
3 |
|
$this->authorize($meeting); |
60
|
3 |
|
return $meeting; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Store a newly created resource in storage. |
65
|
|
|
* |
66
|
|
|
* @param MeetingRequest $request |
67
|
|
|
* @param int $groupId |
68
|
|
|
* @return static |
69
|
|
|
*/ |
70
|
12 |
|
public function store(MeetingRequest $request, $groupId) |
71
|
|
|
{ |
72
|
12 |
|
$group = Group::findOrFail($groupId); |
73
|
12 |
|
$this->authorize($group); |
74
|
12 |
|
$input = $request->all(); |
75
|
12 |
|
$meeting = $group->meetings()->create($input); |
76
|
12 |
|
return $meeting; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Store a newly created resource in storage. |
81
|
|
|
* |
82
|
|
|
* @param Requests\Request $request |
83
|
|
|
* @param int $groupId |
84
|
|
|
* @param int $meetingId |
85
|
|
|
* @return static |
86
|
|
|
*/ |
87
|
|
|
public function storeImage(Requests\Request $request, $groupId, $meetingId) |
88
|
|
|
{ |
89
|
|
|
$this->validate($request, ['data' => 'required|image']); |
90
|
|
|
$group = Group::findOrFail($groupId); |
91
|
|
|
$this->authorize($group); |
92
|
|
|
$meeting = Group::findOrFail($meetingId); |
93
|
|
|
$this->authorize($meeting); |
94
|
|
|
$file = $request->file('data'); |
95
|
|
|
self::putImg($file, $meeting); |
96
|
|
|
return $meeting; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
private static function putImg($file, Meeting $meeting) |
100
|
|
|
{ |
101
|
|
|
\Storage::put('meetings/' . $meeting->id, \File::get($file)); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Store a newly created resource in storage. |
106
|
|
|
* |
107
|
|
|
* @param int $groupId |
108
|
|
|
* @param int $meetingId |
109
|
|
|
* @return static |
110
|
|
|
*/ |
111
|
|
|
public function showImage($groupId, $meetingId) |
112
|
|
|
{ |
113
|
|
|
$group = Group::findOrFail($groupId); |
114
|
|
|
$this->authorize($group); |
115
|
|
|
$meeting = Group::findOrFail($meetingId); |
116
|
|
|
$this->authorize($meeting); |
117
|
|
|
$ret = self::getImg($meeting); |
118
|
|
|
if ($ret === false) |
119
|
|
|
return \Response::json(['error' => 'The file is not uploaded'], 404); |
|
|
|
|
120
|
|
|
return (new Response($ret, 200)) |
|
|
|
|
121
|
|
|
->header('Content-Type', 'image/jpeg'); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
private static function getImg(Meeting $meeting) |
125
|
|
|
{ |
126
|
|
|
$name = 'meetings/' . $meeting->id; |
127
|
|
|
if (!\Storage::exists($name)) |
|
|
|
|
128
|
|
|
return false; |
129
|
|
|
return \Storage::get($name); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Update the specified resource in storage. |
134
|
|
|
* |
135
|
|
|
* @param MeetingRequest $request |
136
|
|
|
* @param int $meetingId |
137
|
|
|
* @param int $groupId |
138
|
|
|
* @return mixed |
139
|
|
|
*/ |
140
|
9 |
|
public function update(MeetingRequest $request, $groupId, $meetingId) |
141
|
|
|
{ |
142
|
9 |
|
$group = Group::findOrFail($groupId); |
143
|
9 |
|
$this->authorize($group); |
144
|
6 |
|
$meeting = Meeting::findOrFail($meetingId); |
145
|
3 |
|
$this->authorize($meeting); |
146
|
3 |
|
$input = $request->all(); |
147
|
|
|
//the planner cannot modify the duration of a planed meeting |
148
|
3 |
|
if ($meeting->start_time != NULL && $meeting->duration != $input['duration']) |
149
|
2 |
|
return Response::json(['error' => 'the meeting is already planned, you cannot change the duration'], 422); |
150
|
3 |
|
$meeting->update($input); |
151
|
3 |
|
return $meeting; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Remove the specified resource from storage. |
156
|
|
|
* |
157
|
|
|
* @param int $groupId |
158
|
|
|
* @param int $meetingId |
159
|
|
|
* @return mixed |
160
|
|
|
*/ |
161
|
9 |
|
public function destroy($groupId, $meetingId) |
162
|
|
|
{ |
163
|
9 |
|
$group = Group::findOrFail($groupId); |
164
|
9 |
|
$this->authorize($group); |
165
|
6 |
|
$meeting = Meeting::findOrFail($meetingId); |
166
|
3 |
|
$this->authorize($meeting); |
167
|
3 |
|
$meeting->delete(); |
168
|
3 |
|
return $meeting; |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.