1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\User; |
6
|
|
|
use Chrisbjr\ApiGuard\Models\ApiKey; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
|
9
|
|
|
use App\Http\Requests; |
10
|
|
|
use Bouncer; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class StaffController |
14
|
|
|
* @package App\Http\Controllers |
15
|
|
|
*/ |
16
|
|
|
class StaffController extends Controller |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* StaffController constructor. |
21
|
|
|
*/ |
22
|
|
|
public function __construct() |
23
|
|
|
{ |
24
|
|
|
$this->middleware('auth'); |
25
|
|
|
$this->middleware('lang'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Create new staff member. |
30
|
|
|
* |
31
|
|
|
* @TODO Build up the view |
32
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
33
|
|
|
*/ |
34
|
|
|
public function create() |
35
|
|
|
{ |
36
|
|
|
return view('staff.create'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Store the new member in the database |
41
|
|
|
* |
42
|
|
|
* @TODO: Needs phpunit test. |
43
|
|
|
* @TODO: Build up the controller logic. |
44
|
|
|
* @TODO: Build up the request validator. |
45
|
|
|
* @return \Illuminate\Http\RedirectResponse |
46
|
|
|
*/ |
47
|
|
|
public function store() |
48
|
|
|
{ |
49
|
|
|
return redirect()->back(302); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Update the staff member. |
54
|
|
|
* |
55
|
|
|
* @TODO: Needs phpunit test |
56
|
|
|
* @TODO: Build up the controller. |
57
|
|
|
* @TODO: BUild up the request validator. |
58
|
|
|
* @param int $id The staff member id in the database. |
59
|
|
|
* @return \Illuminate\Http\RedirectResponse |
60
|
|
|
*/ |
61
|
|
|
public function update($id) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
return redirect()->back(302); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Edit view for a staff member. |
68
|
|
|
* |
69
|
|
|
* @TODO Build up the view. |
70
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
71
|
|
|
*/ |
72
|
|
|
public function edit($id) |
73
|
|
|
{ |
74
|
|
|
$data['query'] = User::find($id); |
|
|
|
|
75
|
|
|
return view('staff.edit', $data); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Display all the staff. |
80
|
|
|
* |
81
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
82
|
|
|
*/ |
83
|
|
|
public function index() |
84
|
|
|
{ |
85
|
|
|
$data['users'] = User::paginate(15); |
|
|
|
|
86
|
|
|
return view('users/index', $data); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Set the user available. |
91
|
|
|
* |
92
|
|
|
* @return \Illuminate\Http\RedirectResponse |
93
|
|
|
*/ |
94
|
|
View Code Duplication |
public function setAvailable() |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
$user = User::find(auth()->user()->id); |
|
|
|
|
97
|
|
|
Bouncer::retract('unavailable')->from($user); |
98
|
|
|
Bouncer::assign('available')->to($user); |
99
|
|
|
|
100
|
|
|
return redirect()->back(302); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Set the user unavailable. |
105
|
|
|
* |
106
|
|
|
* @return \Illuminate\Http\RedirectResponse |
107
|
|
|
*/ |
108
|
|
View Code Duplication |
public function setUnavailable() |
|
|
|
|
109
|
|
|
{ |
110
|
|
|
$user = User::find(auth()->user()->id); |
|
|
|
|
111
|
|
|
Bouncer::retract('available')->from($user); |
112
|
|
|
Bouncer::assign('unavailable')->to($user); |
113
|
|
|
|
114
|
|
|
return redirect()->back(302); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Display the profile. |
119
|
|
|
* |
120
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
121
|
|
|
*/ |
122
|
|
|
public function profile() |
123
|
|
|
{ |
124
|
|
|
$id = auth()->user()->id; |
|
|
|
|
125
|
|
|
$data['tokens'] = ApiKey::where('user_id', $id)->get(); |
|
|
|
|
126
|
|
|
return view('users/profile', $data); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Destroy or multiple staff members. |
131
|
|
|
* |
132
|
|
|
* @param int $id THe id off the staff member in the database. |
133
|
|
|
* @return \Illuminate\Http\RedirectResponse |
134
|
|
|
*/ |
135
|
|
|
public function destroy($id) |
136
|
|
|
{ |
137
|
|
|
$user = User::find($id); |
138
|
|
|
$user->roles()->sync([]); |
139
|
|
|
|
140
|
|
|
User::destroy($id); |
141
|
|
|
session()->flash('message', 'User deleted'); |
142
|
|
|
|
143
|
|
|
return redirect()->to('/staff'); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
View Code Duplication |
public function get_roles() |
|
|
|
|
147
|
|
|
{ |
148
|
|
|
$items = Roles::all(); |
149
|
|
|
$data2 = []; |
150
|
|
|
foreach($items as $role) |
151
|
|
|
{ |
152
|
|
|
$data2[] = [ |
153
|
|
|
'value' => $role["id"], |
154
|
|
|
'text' => $role["name"] |
155
|
|
|
]; |
156
|
|
|
|
157
|
|
|
} |
158
|
|
|
return json_encode($data2); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
} |
162
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.