1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace plunner\Http\Controllers\Employees\Calendars; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use plunner\Calendar; |
7
|
|
|
use plunner\Http\Controllers\Controller; |
8
|
|
|
use plunner\Http\Requests\Employees\Calendar\TimeslotRequest; |
9
|
|
|
use plunner\Timeslot; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class TimeslotsController extends Controller |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var \plunner\Company |
16
|
|
|
*/ |
17
|
|
|
private $user; |
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* ExampleController constructor. |
21
|
|
|
*/ |
22
|
14 |
|
public function __construct() |
23
|
|
|
{ |
24
|
14 |
|
config(['auth.model' => \plunner\Employee::class]); |
25
|
14 |
|
config(['jwt.user' => \plunner\Employee::class]); |
26
|
14 |
|
$this->middleware('jwt.authandrefresh:mode-en'); |
27
|
14 |
|
} |
28
|
|
|
|
29
|
|
|
//TODO check that the calendar is not a caldav calendar |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Display a listing of the resource. |
33
|
|
|
* |
34
|
|
|
* @param int $calendarId |
35
|
|
|
* @return \Illuminate\Http\Response |
36
|
|
|
*/ |
37
|
2 |
|
public function index($calendarId) |
38
|
|
|
{ |
39
|
|
|
//TODO improvement return small period |
40
|
|
|
/** |
41
|
|
|
* @var $employee Employee |
42
|
|
|
*/ |
43
|
2 |
|
$calendar = Calendar::findOrFail($calendarId); |
44
|
2 |
|
$this->authorize($calendar); |
45
|
2 |
|
return $calendar->timeslots; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Store a newly created resource in storage. |
50
|
|
|
* |
51
|
|
|
* @param TimeslotRequest $request |
52
|
|
|
* @param int $calendarId |
53
|
|
|
* @return \Illuminate\Http\Response |
54
|
|
|
*/ |
55
|
2 |
|
public function store(TimeslotRequest $request, $calendarId) |
56
|
|
|
{ |
57
|
|
|
//TODO check that end is after start and start is after now |
58
|
|
|
//TODO CHECK |
59
|
2 |
|
$calendar = Calendar::findOrFail($calendarId); |
60
|
2 |
|
$this->authorize($calendar); |
61
|
2 |
|
$input = $request->all(); |
62
|
2 |
|
$timeslot = $calendar->timeslots()->create($input); |
63
|
|
|
// if( $timeslot->time_start > $timeslot->time_end) //IMPROVE THIS,t hsi must be inserted before creation |
64
|
2 |
|
return $timeslot; |
65
|
|
|
//TODO else |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Display the specified resource. |
70
|
|
|
* |
71
|
|
|
* @param int $calendarId |
72
|
|
|
* @param int $timeslotId |
73
|
|
|
* @return \Illuminate\Http\Response |
74
|
|
|
*/ |
75
|
6 |
|
public function show($calendarId, $timeslotId) |
76
|
|
|
{ |
77
|
|
|
// |
78
|
6 |
|
$calendar = Calendar::findOrFail($calendarId); |
79
|
6 |
|
$this->authorize($calendar); |
80
|
6 |
|
$timeslot = Timeslot::findOrFail($timeslotId); |
81
|
6 |
|
$this->authorize($timeslot); |
82
|
4 |
|
return $timeslot; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Update the specified resource in storage. |
87
|
|
|
* |
88
|
|
|
* @param TimeslotRequest $request |
89
|
|
|
* @param int $calendarId |
90
|
|
|
* @param int $timeslotId |
91
|
|
|
* @return \Illuminate\Http\Response |
92
|
|
|
*/ |
93
|
2 |
|
public function update(TimeslotRequest $request, $calendarId, $timeslotId) |
94
|
|
|
{ |
95
|
|
|
// |
96
|
2 |
|
$calendar = Calendar::findOrFail($calendarId); |
97
|
2 |
|
$this->authorize($calendar); |
98
|
2 |
|
$timeslot = Timeslot::findOrFail($timeslotId); |
99
|
2 |
|
$this->authorize($timeslot); |
100
|
2 |
|
$input = $request->all(); |
101
|
2 |
|
$timeslot->update($input); |
102
|
2 |
|
return $timeslot; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Remove the specified resource from storage. |
107
|
|
|
* |
108
|
|
|
* @param int $calendarId |
109
|
|
|
* @param int $timeslotId |
110
|
|
|
* @return \Illuminate\Http\Response |
111
|
|
|
*/ |
112
|
2 |
|
public function destroy($calendarId, $timeslotId) |
113
|
|
|
{ |
114
|
|
|
// |
115
|
2 |
|
$calendar = Calendar::findOrFail($calendarId); |
116
|
2 |
|
$this->authorize($calendar); |
117
|
2 |
|
$timeslot = Timeslot::findOrFail($timeslotId); |
118
|
2 |
|
$this->authorize($timeslot); |
119
|
2 |
|
$timeslot->delete(); |
120
|
2 |
|
return $timeslot; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.