1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bantenprov\Seleksi\Http\Controllers; |
4
|
|
|
|
5
|
|
|
/* Require */ |
6
|
|
|
use App\Http\Controllers\Controller; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
|
9
|
|
|
/* Models */ |
10
|
|
|
use Bantenprov\Seleksi\Models\Bantenprov\Seleksi\Seleksi; |
11
|
|
|
use Bantenprov\Pendaftaran\Models\Bantenprov\Pendaftaran\Pendaftaran; |
12
|
|
|
use Bantenprov\Siswa\Models\Bantenprov\Siswa\Siswa; |
13
|
|
|
use Bantenprov\Nilai\Models\Bantenprov\Nilai\Nilai; |
14
|
|
|
use App\User; |
15
|
|
|
|
16
|
|
|
/* Etc */ |
17
|
|
|
use Validator; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The SeleksiController class. |
21
|
|
|
* |
22
|
|
|
* @package Bantenprov\Seleksi |
23
|
|
|
* @author bantenprov <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class SeleksiController extends Controller |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Create a new controller instance. |
29
|
|
|
* |
30
|
|
|
* @return void |
31
|
|
|
*/ |
32
|
|
|
protected $pendaftaran; |
33
|
|
|
protected $seleksi; |
34
|
|
|
protected $siswa; |
35
|
|
|
protected $nilai; |
36
|
|
|
protected $user; |
37
|
|
|
|
38
|
|
|
public function __construct(Seleksi $seleksi, Pendaftaran $pendaftaran, User $user, Siswa $siswa, Nilai $nilai) |
39
|
|
|
{ |
40
|
|
|
$this->seleksi = $seleksi; |
41
|
|
|
$this->pendaftaran = $pendaftaran; |
42
|
|
|
$this->user = $user; |
43
|
|
|
$this->siswa = $siswa; |
44
|
|
|
$this->nilai = $nilai; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Display a listing of the resource. |
49
|
|
|
* |
50
|
|
|
* @return \Illuminate\Http\Response |
51
|
|
|
*/ |
52
|
|
|
public function index(Request $request) |
53
|
|
|
{ |
54
|
|
|
if (request()->has('sort')) { |
55
|
|
|
list($sortCol, $sortDir) = explode('|', request()->sort); |
56
|
|
|
|
57
|
|
|
$query = $this->seleksi->with('pendaftaran')->with('user')->with('siswa')->with('nilai')->orderBy($sortCol, $sortDir); |
58
|
|
|
} else { |
59
|
|
|
$query = $this->seleksi->with('pendaftaran')->with('user')->with('siswa')->with('nilai')->orderBy('id', 'asc'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if ($request->exists('filter')) { |
63
|
|
|
$query->where(function($q) use($request) { |
64
|
|
|
$value = "%{$request->filter}%"; |
65
|
|
|
$q->where('nilai_id', 'like', $value) |
66
|
|
|
->orWhere('pendaftaran_id', 'like', $value); |
67
|
|
|
}); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$perPage = request()->has('per_page') ? (int) request()->per_page : null; |
71
|
|
|
$response = $query->paginate($perPage); |
72
|
|
|
|
73
|
|
|
return response()->json($response) |
74
|
|
|
->header('Access-Control-Allow-Origin', '*') |
75
|
|
|
->header('Access-Control-Allow-Methods', 'GET'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Show the form for creating a new resource. |
80
|
|
|
* |
81
|
|
|
* @return \Illuminate\Http\Response |
82
|
|
|
*/ |
83
|
|
|
public function create() |
84
|
|
|
{ |
85
|
|
|
$response = []; |
86
|
|
|
|
87
|
|
|
$pendaftarans = $this->pendaftaran->all(); |
88
|
|
|
$siswas = $this->siswa->all(); |
89
|
|
|
$nilais = $this->nilai->all(); |
90
|
|
|
$users_special = $this->user->all(); |
91
|
|
|
$users_standar = $this->user->find(\Auth::User()->id); |
92
|
|
|
$current_user = \Auth::User(); |
93
|
|
|
|
94
|
|
|
$role_check = \Auth::User()->hasRole(['superadministrator','administrator']); |
95
|
|
|
|
96
|
|
|
if($role_check){ |
97
|
|
|
$response['user_special'] = true; |
98
|
|
|
foreach($users_special as $user){ |
99
|
|
|
array_set($user, 'label', $user->name); |
100
|
|
|
} |
101
|
|
|
$response['user'] = $users_special; |
102
|
|
|
}else{ |
103
|
|
|
$response['user_special'] = false; |
104
|
|
|
array_set($users_standar, 'label', $users_standar->name); |
105
|
|
|
$response['user'] = $users_standar; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
array_set($current_user, 'label', $current_user->name); |
109
|
|
|
|
110
|
|
|
foreach($pendaftarans as $pendaftaran){ |
111
|
|
|
array_set($pendaftaran, 'label', $pendaftaran->kegiatan->description); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
foreach($siswas as $siswa){ |
115
|
|
|
array_set($siswa, 'label', $siswa->nama_siswa); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
foreach($nilais as $nilai){ |
119
|
|
|
array_set($nilai, 'label', $nilai->siswa->nama_siswa); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$response['current_user'] = $current_user; |
123
|
|
|
$response['pendaftaran'] = $pendaftarans; |
124
|
|
|
$response['siswa'] = $siswas; |
125
|
|
|
$response['nilai'] = $nilais; |
126
|
|
|
$response['status'] = true; |
127
|
|
|
|
128
|
|
|
return response()->json($response); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Display the specified resource. |
133
|
|
|
* |
134
|
|
|
* @param \App\Seleksi $seleksi |
|
|
|
|
135
|
|
|
* @return \Illuminate\Http\Response |
136
|
|
|
*/ |
137
|
|
|
public function store(Request $request) |
138
|
|
|
{ |
139
|
|
|
$seleksi = $this->seleksi; |
140
|
|
|
$current_user_id = $request->user_id; |
141
|
|
|
|
142
|
|
|
$validator = Validator::make($request->all(), [ |
143
|
|
|
'pendaftaran_id' => 'required|unique:seleksis,pendaftaran_id', |
144
|
|
|
'user_id' => 'required', |
145
|
|
|
'nilai_id' => 'required|unique:seleksis,nilai_id', |
146
|
|
|
'nomor_un' => 'required|unique:seleksis,nomor_un' |
147
|
|
|
]); |
148
|
|
|
|
149
|
|
|
if($validator->fails()){ |
150
|
|
|
|
151
|
|
|
$check = $seleksi->where('pendaftaran_id', $request->pendaftaran_id)->orWhere('nilai_id', $request->nilai_id)->orWhere('nomor_un', $request->nomor_un)->whereNull('deleted_at')->count(); |
|
|
|
|
152
|
|
|
|
153
|
|
|
if ($check > 0) { |
154
|
|
|
$response['message'] = 'Failed, Pendaftaran, Nama Siswa, Nilai already exists'; |
|
|
|
|
155
|
|
|
} else { |
156
|
|
|
$seleksi->pendaftaran_id = $request->input('pendaftaran_id'); |
|
|
|
|
157
|
|
|
$seleksi->user_id = $current_user_id; |
|
|
|
|
158
|
|
|
$seleksi->nomor_un = $request->input('nomor_un'); |
|
|
|
|
159
|
|
|
$seleksi->nilai_id = $request->input('nilai_id'); |
|
|
|
|
160
|
|
|
$seleksi->save(); |
161
|
|
|
|
162
|
|
|
$response['message'] = 'success'; |
|
|
|
|
163
|
|
|
} |
164
|
|
|
} else { |
165
|
|
|
$seleksi->pendaftaran_id = $request->input('pendaftaran_id'); |
|
|
|
|
166
|
|
|
$seleksi->user_id = $current_user_id; |
|
|
|
|
167
|
|
|
$seleksi->nomor_un = $request->input('nomor_un'); |
|
|
|
|
168
|
|
|
$seleksi->nilai_id = $request->input('nilai_id'); |
|
|
|
|
169
|
|
|
$seleksi->save(); |
170
|
|
|
$response['message'] = 'success'; |
|
|
|
|
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
$response['status'] = true; |
174
|
|
|
|
175
|
|
|
return response()->json($response); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Store a newly created resource in storage. |
180
|
|
|
* |
181
|
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
182
|
|
|
* @return \Illuminate\Http\Response |
183
|
|
|
*/ |
184
|
|
|
public function show($id) |
185
|
|
|
{ |
186
|
|
|
$seleksi = $this->seleksi->findOrFail($id); |
|
|
|
|
187
|
|
|
|
188
|
|
|
$response['seleksi'] = $seleksi; |
|
|
|
|
189
|
|
|
$response['pendaftaran'] = $seleksi->pendaftaran; |
190
|
|
|
$response['user'] = $seleksi->user; |
191
|
|
|
$response['siswa'] = $seleksi->siswa; |
192
|
|
|
$response['nilai'] = $seleksi->nilai; |
193
|
|
|
$response['status'] = true; |
194
|
|
|
|
195
|
|
|
return response()->json($response); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Show the form for editing the specified resource. |
200
|
|
|
* |
201
|
|
|
* @param \App\Seleksi $seleksi |
|
|
|
|
202
|
|
|
* @return \Illuminate\Http\Response |
203
|
|
|
*/ |
204
|
|
|
public function edit($id) |
205
|
|
|
{ |
206
|
|
|
$seleksi = $this->seleksi->findOrFail($id); |
|
|
|
|
207
|
|
|
|
208
|
|
|
array_set($seleksi->user, 'label', $seleksi->user->name); |
209
|
|
|
array_set($seleksi->pendaftaran, 'label', $seleksi->pendaftaran->kegiatan->description); |
210
|
|
|
array_set($seleksi->siswa, 'label', $seleksi->siswa->nama_siswa); |
211
|
|
|
array_set($seleksi->nilai, 'label', $seleksi->nilai->siswa->nama_siswa); |
212
|
|
|
|
213
|
|
|
|
214
|
|
|
$response['seleksi'] = $seleksi; |
|
|
|
|
215
|
|
|
$response['pendaftaran'] = $seleksi->pendaftaran; |
216
|
|
|
$response['user'] = $seleksi->user; |
217
|
|
|
$response['siswa'] = $seleksi->siswa; |
218
|
|
|
$response['nilai'] = $seleksi->nilai; |
219
|
|
|
$response['status'] = true; |
220
|
|
|
|
221
|
|
|
return response()->json($response); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Update the specified resource in storage. |
226
|
|
|
* |
227
|
|
|
* @param \Illuminate\Http\Request $request |
228
|
|
|
* @param \App\Seleksi $seleksi |
|
|
|
|
229
|
|
|
* @return \Illuminate\Http\Response |
230
|
|
|
*/ |
231
|
|
|
public function update(Request $request, $id) |
232
|
|
|
{ |
233
|
|
|
|
234
|
|
|
$response = array(); |
235
|
|
|
$message = array(); |
236
|
|
|
$seleksi = $this->seleksi->findOrFail($id); |
|
|
|
|
237
|
|
|
|
238
|
|
|
$validator = Validator::make($request->all(), [ |
239
|
|
|
'user_id' => 'required', |
240
|
|
|
'pendaftaran_id' => 'required|unique:seleksis,pendaftaran_id,'.$id, |
241
|
|
|
'nomor_un' => 'required|unique:seleksis,nomor_un,'.$id, |
242
|
|
|
'nilai_id' => 'required|unique:seleksis,nilai_id,'.$id, |
243
|
|
|
]); |
244
|
|
|
|
245
|
|
|
if ($validator->fails()) { |
246
|
|
|
|
247
|
|
|
foreach($validator->messages()->getMessages() as $key => $error){ |
248
|
|
|
foreach($error AS $error_get) { |
249
|
|
|
array_push($message, $error_get); |
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
$check_pendaftaran = $this->seleksi->where('id','!=', $id)->where('pendaftaran_id', $request->pendaftaran_id); |
|
|
|
|
254
|
|
|
$check_siswa = $this->seleksi->where('id','!=', $id)->where('nomor_un', $request->nomor_un); |
|
|
|
|
255
|
|
|
$check_nilai = $this->seleksi->where('id','!=', $id)->where('nilai_id', $request->nilai_id); |
|
|
|
|
256
|
|
|
|
257
|
|
|
if($check_pendaftaran->count() > 0 || $check_siswa->count() > 0 || $check_nilai->count() > 0){ |
258
|
|
|
$response['message'] = implode("\n",$message); |
259
|
|
View Code Duplication |
} else { |
|
|
|
|
260
|
|
|
$seleksi->user_id = $request->input('user_id'); |
261
|
|
|
$seleksi->pendaftaran_id = $request->input('pendaftaran_id'); |
262
|
|
|
$seleksi->nomor_un = $request->input('nomor_un'); |
263
|
|
|
$seleksi->nilai_id = $request->input('nilai_id'); |
264
|
|
|
$seleksi->save(); |
265
|
|
|
|
266
|
|
|
$response['message'] = 'success'; |
267
|
|
|
} |
268
|
|
View Code Duplication |
} else { |
|
|
|
|
269
|
|
|
$seleksi->user_id = $request->input('user_id'); |
270
|
|
|
$seleksi->pendaftaran_id = $request->input('pendaftaran_id'); |
271
|
|
|
$seleksi->nomor_un = $request->input('nomor_un'); |
272
|
|
|
$seleksi->nilai_id = $request->input('nilai_id'); |
273
|
|
|
$seleksi->save(); |
274
|
|
|
|
275
|
|
|
$response['message'] = 'success'; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
$response['status'] = true; |
279
|
|
|
|
280
|
|
|
return response()->json($response); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* Remove the specified resource from storage. |
285
|
|
|
* |
286
|
|
|
* @param \App\Seleksi $seleksi |
|
|
|
|
287
|
|
|
* @return \Illuminate\Http\Response |
288
|
|
|
*/ |
289
|
|
|
public function destroy($id) |
290
|
|
|
{ |
291
|
|
|
$seleksi = $this->seleksi->findOrFail($id); |
|
|
|
|
292
|
|
|
|
293
|
|
|
if ($seleksi->delete()) { |
294
|
|
|
$response['status'] = true; |
|
|
|
|
295
|
|
|
} else { |
296
|
|
|
$response['status'] = false; |
|
|
|
|
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
return json_encode($response); |
300
|
|
|
} |
301
|
|
|
} |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.