|
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->label); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
foreach($nilais as $nilai){ |
|
116
|
|
|
array_set($nilai, 'label', $nilai->siswa->nomor_un.' - '.$nilai->siswa->nama_siswa); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$response['current_user'] = $current_user; |
|
120
|
|
|
$response['pendaftaran'] = $pendaftarans; |
|
121
|
|
|
$response['siswa'] = $siswas; |
|
122
|
|
|
$response['nilai'] = $nilais; |
|
123
|
|
|
$response['status'] = true; |
|
124
|
|
|
|
|
125
|
|
|
return response()->json($response); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Display the specified resource. |
|
130
|
|
|
* |
|
131
|
|
|
* @param \App\Seleksi $seleksi |
|
|
|
|
|
|
132
|
|
|
* @return \Illuminate\Http\Response |
|
133
|
|
|
*/ |
|
134
|
|
|
public function store(Request $request) |
|
135
|
|
|
{ |
|
136
|
|
|
$seleksi = $this->seleksi; |
|
137
|
|
|
$current_user_id = $request->user_id; |
|
138
|
|
|
|
|
139
|
|
|
$validator = Validator::make($request->all(), [ |
|
140
|
|
|
'pendaftaran_id' => 'required', |
|
141
|
|
|
'user_id' => 'required', |
|
142
|
|
|
'nilai_id' => 'required|unique:seleksis,nilai_id', |
|
143
|
|
|
'nomor_un' => 'required|unique:seleksis,nomor_un' |
|
144
|
|
|
]); |
|
145
|
|
|
|
|
146
|
|
|
if($validator->fails()){ |
|
147
|
|
|
|
|
148
|
|
|
$check = $seleksi->Where('nilai_id', $request->nilai_id)->orWhere('nomor_un', $request->nomor_un)->whereNull('deleted_at')->count(); |
|
|
|
|
|
|
149
|
|
|
|
|
150
|
|
|
if ($check > 0) { |
|
151
|
|
|
$response['message'] = 'Failed, Nama Siswa already exists'; |
|
|
|
|
|
|
152
|
|
|
} else { |
|
153
|
|
|
$seleksi->pendaftaran_id = $request->input('pendaftaran_id'); |
|
|
|
|
|
|
154
|
|
|
$seleksi->user_id = $current_user_id; |
|
|
|
|
|
|
155
|
|
|
$seleksi->nomor_un = $request->input('nomor_un'); |
|
|
|
|
|
|
156
|
|
|
$seleksi->nilai_id = $request->input('nilai_id'); |
|
|
|
|
|
|
157
|
|
|
$seleksi->save(); |
|
158
|
|
|
|
|
159
|
|
|
$response['message'] = 'success'; |
|
|
|
|
|
|
160
|
|
|
} |
|
161
|
|
|
} else { |
|
162
|
|
|
$seleksi->pendaftaran_id = $request->input('pendaftaran_id'); |
|
|
|
|
|
|
163
|
|
|
$seleksi->user_id = $current_user_id; |
|
|
|
|
|
|
164
|
|
|
$seleksi->nomor_un = $request->input('nomor_un'); |
|
|
|
|
|
|
165
|
|
|
$seleksi->nilai_id = $request->input('nilai_id'); |
|
|
|
|
|
|
166
|
|
|
$seleksi->save(); |
|
167
|
|
|
$response['message'] = 'success'; |
|
|
|
|
|
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
$response['status'] = true; |
|
171
|
|
|
|
|
172
|
|
|
return response()->json($response); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* Store a newly created resource in storage. |
|
177
|
|
|
* |
|
178
|
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
|
|
179
|
|
|
* @return \Illuminate\Http\Response |
|
180
|
|
|
*/ |
|
181
|
|
|
public function show($id) |
|
182
|
|
|
{ |
|
183
|
|
|
$seleksi = $this->seleksi->findOrFail($id); |
|
|
|
|
|
|
184
|
|
|
|
|
185
|
|
|
$response['seleksi'] = $seleksi; |
|
|
|
|
|
|
186
|
|
|
$response['pendaftaran'] = $seleksi->pendaftaran; |
|
187
|
|
|
$response['user'] = $seleksi->user; |
|
188
|
|
|
$response['siswa'] = $seleksi->siswa; |
|
189
|
|
|
$response['nilai'] = $seleksi->nilai; |
|
190
|
|
|
$response['status'] = true; |
|
191
|
|
|
|
|
192
|
|
|
return response()->json($response); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Show the form for editing the specified resource. |
|
197
|
|
|
* |
|
198
|
|
|
* @param \App\Seleksi $seleksi |
|
|
|
|
|
|
199
|
|
|
* @return \Illuminate\Http\Response |
|
200
|
|
|
*/ |
|
201
|
|
|
public function edit($id) |
|
202
|
|
|
{ |
|
203
|
|
|
$seleksi = $this->seleksi->with(['pendaftaran', 'nilai', 'siswa', 'user'])->findOrFail($id); |
|
|
|
|
|
|
204
|
|
|
|
|
205
|
|
|
|
|
206
|
|
|
array_set($seleksi->user, 'label', $seleksi->user->name); |
|
207
|
|
|
array_set($seleksi->pendaftaran, 'label', $seleksi->pendaftaran->kegiatan->label); |
|
208
|
|
|
|
|
209
|
|
|
|
|
210
|
|
|
/*array_set($seleksi->nilai, 'label', $seleksi->nilai->nomor_un.' - '.$seleksi->nilai->siswa->nama_siswa);*/ |
|
|
|
|
|
|
211
|
|
|
|
|
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', |
|
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_siswa = $this->seleksi->where('id','!=', $id)->where('nomor_un', $request->nomor_un); |
|
|
|
|
|
|
254
|
|
|
$check_nilai = $this->seleksi->where('id','!=', $id)->where('nilai_id', $request->nilai_id); |
|
|
|
|
|
|
255
|
|
|
|
|
256
|
|
|
if($check_siswa->count() > 0 || $check_nilai->count() > 0){ |
|
257
|
|
|
$response['message'] = implode("\n",$message); |
|
258
|
|
View Code Duplication |
} else { |
|
|
|
|
|
|
259
|
|
|
$seleksi->user_id = $request->input('user_id'); |
|
260
|
|
|
$seleksi->pendaftaran_id = $request->input('pendaftaran_id'); |
|
261
|
|
|
$seleksi->nomor_un = $request->input('nomor_un'); |
|
262
|
|
|
$seleksi->nilai_id = $request->input('nilai_id'); |
|
263
|
|
|
$seleksi->save(); |
|
264
|
|
|
|
|
265
|
|
|
$response['message'] = 'success'; |
|
266
|
|
|
} |
|
267
|
|
View Code Duplication |
} else { |
|
|
|
|
|
|
268
|
|
|
$seleksi->user_id = $request->input('user_id'); |
|
269
|
|
|
$seleksi->pendaftaran_id = $request->input('pendaftaran_id'); |
|
270
|
|
|
$seleksi->nomor_un = $request->input('nomor_un'); |
|
271
|
|
|
$seleksi->nilai_id = $request->input('nilai_id'); |
|
272
|
|
|
$seleksi->save(); |
|
273
|
|
|
|
|
274
|
|
|
$response['message'] = 'success'; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
$response['status'] = true; |
|
278
|
|
|
|
|
279
|
|
|
return response()->json($response); |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* Remove the specified resource from storage. |
|
284
|
|
|
* |
|
285
|
|
|
* @param \App\Seleksi $seleksi |
|
|
|
|
|
|
286
|
|
|
* @return \Illuminate\Http\Response |
|
287
|
|
|
*/ |
|
288
|
|
|
public function destroy($id) |
|
289
|
|
|
{ |
|
290
|
|
|
$seleksi = $this->seleksi->findOrFail($id); |
|
|
|
|
|
|
291
|
|
|
|
|
292
|
|
|
if ($seleksi->delete()) { |
|
293
|
|
|
$response['status'] = true; |
|
|
|
|
|
|
294
|
|
|
} else { |
|
295
|
|
|
$response['status'] = false; |
|
|
|
|
|
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
return json_encode($response); |
|
299
|
|
|
} |
|
300
|
|
|
} |
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.