1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bantenprov\Pendaftaran\Http\Controllers; |
4
|
|
|
|
5
|
|
|
/* Require */ |
6
|
|
|
use App\Http\Controllers\Controller; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
use Carbon\Carbon; |
9
|
|
|
/* Models */ |
10
|
|
|
use Bantenprov\Pendaftaran\Models\Bantenprov\Pendaftaran\Pendaftaran; |
11
|
|
|
use Bantenprov\Kegiatan\Models\Bantenprov\Kegiatan\Kegiatan; |
12
|
|
|
use Bantenprov\Sekolah\Models\Bantenprov\Sekolah\Sekolah; |
13
|
|
|
use Bantenprov\Sekolah\Models\Bantenprov\Sekolah\AdminSekolah; |
14
|
|
|
use App\User; |
15
|
|
|
use Bantenprov\Siswa\Models\Bantenprov\Siswa\Siswa; |
16
|
|
|
use Bantenprov\Sktm\Models\Bantenprov\Sktm\MasterSktm; |
17
|
|
|
use Bantenprov\Sktm\Models\Bantenprov\Sktm\Sktm; |
18
|
|
|
use Bantenprov\Prestasi\Models\Bantenprov\Prestasi\JenisPrestasi; |
19
|
|
|
use Bantenprov\Prestasi\Models\Bantenprov\Prestasi\MasterPrestasi; |
20
|
|
|
use Bantenprov\Prestasi\Models\Bantenprov\Prestasi\Prestasi; |
21
|
|
|
use Bantenprov\Prestasi\Http\Controllers\MasterPrestasiController; |
22
|
|
|
|
23
|
|
|
/* Etc */ |
24
|
|
|
use Validator; |
25
|
|
|
use Auth; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The PendaftaranController class. |
29
|
|
|
* |
30
|
|
|
* @package Bantenprov\Pendaftaran |
31
|
|
|
* @author bantenprov <[email protected]> |
32
|
|
|
*/ |
33
|
|
|
class PendaftaranController extends Controller |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* Create a new controller instance. |
37
|
|
|
* |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
protected $kegiatanModel; |
41
|
|
|
protected $pendaftaran; |
42
|
|
|
protected $user; |
43
|
|
|
protected $sekolah; |
44
|
|
|
protected $admin_sekolah; |
45
|
|
|
protected $siswa; |
46
|
|
|
protected $mastersktm; |
47
|
|
|
protected $sktm; |
48
|
|
|
protected $jenisprestasi; |
49
|
|
|
protected $masterprestasi; |
50
|
|
|
protected $masterprestasicont; |
51
|
|
|
protected $prestasi; |
52
|
|
|
|
53
|
|
|
public function __construct() |
54
|
|
|
{ |
55
|
|
|
$this->pendaftaran = new Pendaftaran; |
56
|
|
|
$this->kegiatanModel = new Kegiatan; |
57
|
|
|
$this->user = new User; |
58
|
|
|
$this->sekolah = new Sekolah; |
59
|
|
|
$this->admin_sekolah = new AdminSekolah; |
60
|
|
|
$this->siswa = new Siswa; |
61
|
|
|
$this->sktm = new Sktm; |
62
|
|
|
$this->mastersktm = new MasterSktm; |
63
|
|
|
$this->jenisprestasi = new JenisPrestasi; |
64
|
|
|
$this->masterprestasi = new MasterPrestasi; |
65
|
|
|
$this->masterprestasicont = new MasterPrestasiController; |
66
|
|
|
$this->prestasi = new Prestasi; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Display a listing of the resource. |
71
|
|
|
* |
72
|
|
|
* @return \Illuminate\Http\Response |
73
|
|
|
*/ |
74
|
|
|
public function index(Request $request) |
75
|
|
|
{ |
76
|
|
|
$admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first(); |
77
|
|
|
|
78
|
|
|
if(is_null($admin_sekolah) && $this->checkRole(['superadministrator']) === false){ |
79
|
|
|
$response = []; |
80
|
|
|
return response()->json($response) |
81
|
|
|
->header('Access-Control-Allow-Origin', '*') |
82
|
|
|
->header('Access-Control-Allow-Methods', 'GET'); |
83
|
|
|
}else{ |
84
|
|
|
$page = 10; |
85
|
|
|
$data = $this->pendaftaran |
86
|
|
|
->select( |
87
|
|
|
'pendaftarans.id', |
88
|
|
|
'users.name', |
89
|
|
|
'pendaftarans.tanggal_pendaftaran', |
90
|
|
|
'sekolahs.nama', |
91
|
|
|
'kegiatans.label', |
92
|
|
|
'siswas.nama_siswa' |
93
|
|
|
) |
94
|
|
|
->leftjoin( |
95
|
|
|
'sekolahs', |
96
|
|
|
'pendaftarans.sekolah_id','=','sekolahs.id' |
97
|
|
|
) |
98
|
|
|
->leftjoin( |
99
|
|
|
'kegiatans', |
100
|
|
|
'pendaftarans.kegiatan_id','=','kegiatans.id' |
101
|
|
|
) |
102
|
|
|
->leftjoin( |
103
|
|
|
'users', |
104
|
|
|
'pendaftarans.user_id','=','users.id' |
105
|
|
|
) |
106
|
|
|
->leftjoin( |
107
|
|
|
'siswas', |
108
|
|
|
'users.name','=','siswas.nomor_un' |
109
|
|
|
) |
110
|
|
|
->where('pendaftarans.sekolah_id','=',$admin_sekolah->sekolah_id) |
111
|
|
|
->paginate($page); |
112
|
|
|
return response()->json($data) |
113
|
|
|
->header('Access-Control-Allow-Origin', '*') |
114
|
|
|
->header('Access-Control-Allow-Methods', 'GET'); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Display the specified resource. |
120
|
|
|
* |
121
|
|
|
* @param \App\Pendaftaran $pendaftaran |
|
|
|
|
122
|
|
|
* @return \Illuminate\Http\Response |
123
|
|
|
*/ |
124
|
|
|
public function store(Request $request) |
125
|
|
|
{ |
126
|
|
|
$admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first(); |
127
|
|
|
|
128
|
|
|
$pendaftaran = $this->pendaftaran; |
129
|
|
|
$current_user_id = $request->user_id; |
130
|
|
|
|
131
|
|
|
$validator = Validator::make($request->all(), [ |
132
|
|
|
'kegiatan_id' => 'required', |
133
|
|
|
'user_id' => "required|exists:{$this->user->getTable()},id", |
134
|
|
|
'tanggal_pendaftaran' => 'required', |
135
|
|
|
'sekolah_id' => 'required', |
136
|
|
|
]); |
137
|
|
|
|
138
|
|
|
if($admin_sekolah->sekolah_id != $request->sekolah_id && $this->checkRole(['superadministrator']) === false){ |
139
|
|
|
$response['error'] = true; |
|
|
|
|
140
|
|
|
$response['message'] = 'Terjadi kesalahan, mohon ulangi lagi pengisian data yang benar.'; |
141
|
|
|
$response['status'] = true; |
142
|
|
|
|
143
|
|
|
return response()->json($response); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
View Code Duplication |
if ($validator->fails()) { |
|
|
|
|
147
|
|
|
$error = true; |
148
|
|
|
$message = $validator->errors()->first(); |
149
|
|
|
|
150
|
|
|
} else { |
151
|
|
|
$pendaftaran->kegiatan_id = $request->input('kegiatan_id'); |
152
|
|
|
$pendaftaran->user_id = $current_user_id; |
153
|
|
|
$pendaftaran->tanggal_pendaftaran = $request->input('tanggal_pendaftaran'); |
154
|
|
|
$pendaftaran->sekolah_id = $request->input('sekolah_id'); |
155
|
|
|
$pendaftaran->save(); |
156
|
|
|
$error = false; |
157
|
|
|
$message = 'Success'; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
$response['error'] = $error; |
|
|
|
|
161
|
|
|
$response['message'] = $message; |
162
|
|
|
$response['status'] = true; |
163
|
|
|
|
164
|
|
|
return response()->json($response); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Store a newly created resource in storage. |
169
|
|
|
* |
170
|
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
171
|
|
|
* @return \Illuminate\Http\Response |
172
|
|
|
*/ |
173
|
|
|
public function show($id) |
174
|
|
|
{ |
175
|
|
|
|
176
|
|
|
// $admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first(); |
|
|
|
|
177
|
|
|
// if($this->checkRole(['superadministrator'])){ |
|
|
|
|
178
|
|
|
// $pendaftaran = $this->pendaftaran->findOrFail($id); |
|
|
|
|
179
|
|
|
// }else{ |
180
|
|
|
// $pendaftaran = $this->pendaftaran->where('sekolah_id', $admin_sekolah->sekolah_id)->findOrFail($id); |
|
|
|
|
181
|
|
|
// } |
182
|
|
|
|
183
|
|
|
|
184
|
|
|
|
185
|
|
|
$admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first(); |
|
|
|
|
186
|
|
|
|
187
|
|
|
if($this->checkRole(['superadministrator'])){ |
|
|
|
|
188
|
|
|
// $pendaftaran = $this->pendaftaran->findOrFail($id); |
|
|
|
|
189
|
|
|
}else{ |
190
|
|
|
$data = $this->pendaftaran |
191
|
|
|
->select( |
192
|
|
|
'siswas.nama_siswa', |
193
|
|
|
'kegiatans.label as jenis_pendaftaran', |
194
|
|
|
'pendaftarans.id', |
195
|
|
|
'users.name', |
196
|
|
|
'pendaftarans.tanggal_pendaftaran', |
197
|
|
|
'sekolahs.nama as sekolah_tujuan', |
198
|
|
|
'master_sktms.nama as jenis_sktm', |
199
|
|
|
'sktms.no_sktm', |
200
|
|
|
'prestasis.nama_lomba', |
201
|
|
|
'jenis_prestasis.nama as jenis_prestasi', |
202
|
|
|
'master_prestasis.juara', |
203
|
|
|
'master_prestasis.tingkat' |
204
|
|
|
) |
205
|
|
|
->leftjoin( |
206
|
|
|
'sekolahs', |
207
|
|
|
'pendaftarans.sekolah_id','=','sekolahs.id' |
208
|
|
|
) |
209
|
|
|
->leftjoin( |
210
|
|
|
'kegiatans', |
211
|
|
|
'pendaftarans.kegiatan_id','=','kegiatans.id' |
212
|
|
|
) |
213
|
|
|
->leftjoin( |
214
|
|
|
'users', |
215
|
|
|
'pendaftarans.user_id','=','users.id' |
216
|
|
|
) |
217
|
|
|
->leftjoin( |
218
|
|
|
'siswas', |
219
|
|
|
'users.name','=','siswas.nomor_un' |
220
|
|
|
) |
221
|
|
|
->leftjoin( |
222
|
|
|
'sktms', |
223
|
|
|
'pendaftarans.nomor_un','=','sktms.nomor_un' |
224
|
|
|
) |
225
|
|
|
->leftjoin( |
226
|
|
|
'master_sktms', |
227
|
|
|
'sktms.master_sktm_id','=','master_sktms.id' |
228
|
|
|
) |
229
|
|
|
->leftjoin( |
230
|
|
|
'prestasis', |
231
|
|
|
'pendaftarans.nomor_un','=','prestasis.nomor_un' |
232
|
|
|
) |
233
|
|
|
->leftjoin( |
234
|
|
|
'master_prestasis', |
235
|
|
|
'prestasis.master_prestasi_id','=','master_prestasis.id' |
236
|
|
|
) |
237
|
|
|
->leftjoin( |
238
|
|
|
'jenis_prestasis', |
239
|
|
|
'master_prestasis.jenis_prestasi_id','=','jenis_prestasis.id' |
240
|
|
|
) |
241
|
|
|
->where('pendaftarans.id','=',$id) |
242
|
|
|
->first(); |
243
|
|
|
// $result = array(); |
|
|
|
|
244
|
|
|
// foreach((array)$data as $key => $val){ |
|
|
|
|
245
|
|
|
// if($key == '*attributes'){ |
|
|
|
|
246
|
|
|
// dd($val); |
|
|
|
|
247
|
|
|
// foreach($val as $key1 => $val1){ |
|
|
|
|
248
|
|
|
// if($key1 == 'juara'){ |
|
|
|
|
249
|
|
|
// $result['juara'] = $this->masterprestasi->prestasi_label($val1); |
|
|
|
|
250
|
|
|
// }elseif($key1 == 'tingkat'){ |
|
|
|
|
251
|
|
|
// $result['tingkat'] = $this->masterprestasi->tingkat_label($val1); |
|
|
|
|
252
|
|
|
// }else{ |
253
|
|
|
// $result[$key1] = $val1; |
|
|
|
|
254
|
|
|
// } |
255
|
|
|
// } |
256
|
|
|
// } |
257
|
|
|
// } |
258
|
|
|
return response()->json($data) |
259
|
|
|
->header('Access-Control-Allow-Origin', '*') |
260
|
|
|
->header('Access-Control-Allow-Methods', 'GET'); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
// $response['pendaftaran'] = $pendaftaran; |
|
|
|
|
264
|
|
|
// $response['kegiatan'] = $pendaftaran->kegiatan; |
|
|
|
|
265
|
|
|
// $response['sekolah'] = $pendaftaran->sekolah; |
|
|
|
|
266
|
|
|
// $response['user'] = $pendaftaran->user; |
|
|
|
|
267
|
|
|
// $response['siswa'] = $pendaftaran->siswa; |
|
|
|
|
268
|
|
|
// /* |
269
|
|
|
// // $response['prestasi'] = $pendaftaran->sekolah; |
270
|
|
|
// // $response['sktm'] = $pendaftaran->sekolah; |
271
|
|
|
// */ |
272
|
|
|
|
273
|
|
|
// $response['nama_siswa'] = $data->nama_siswa; |
|
|
|
|
274
|
|
|
// $response['jenis_pendaftaran'] = $data->label; |
|
|
|
|
275
|
|
|
// $response['sekolah_tujuan'] = $data->nama; |
|
|
|
|
276
|
|
|
// $response['tanggal_pendaftaran'] = $data->tanggal_pendaftaran; |
|
|
|
|
277
|
|
|
// $response['jenis_sktm'] = $data->nama; |
|
|
|
|
278
|
|
|
// $response['no_sktm'] = $data->no_sktm; |
|
|
|
|
279
|
|
|
// $response['prestasi'] = $data->nama_lomba; |
|
|
|
|
280
|
|
|
// $response['jenis_prestasi'] = $data->nama; |
|
|
|
|
281
|
|
|
// $response['juara'] = $data->juara; |
|
|
|
|
282
|
|
|
// $response['tingkat'] = $data->tingkat; |
|
|
|
|
283
|
|
|
// $response['status'] = true; |
|
|
|
|
284
|
|
|
// return response()->json($response); |
|
|
|
|
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Show the form for editing the specified resource. |
289
|
|
|
* |
290
|
|
|
* @param \App\Pendaftaran $pendaftaran |
|
|
|
|
291
|
|
|
* @return \Illuminate\Http\Response |
292
|
|
|
*/ |
293
|
|
|
public function edit($id) |
294
|
|
|
{ |
295
|
|
|
$admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first(); |
296
|
|
|
|
297
|
|
|
if($this->checkRole(['superadministrator'])){ |
298
|
|
|
$pendaftaran = $this->pendaftaran->with(['kegiatan', 'sekolah', 'user' ])->findOrFail($id); |
299
|
|
|
}else{ |
300
|
|
|
$pendaftaran = $this->pendaftaran->where('sekolah_id', $admin_sekolah->sekolah_id)->with(['kegiatan', 'sekolah', 'user' ])->findOrFail($id); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
|
304
|
|
|
$response['pendaftaran']['user'] = array_add($pendaftaran->user, 'label', $pendaftaran->user->name); |
|
|
|
|
305
|
|
|
|
306
|
|
|
|
307
|
|
|
|
308
|
|
|
$response['pendaftaran'] = $pendaftaran; |
309
|
|
|
//$response['kegiatan'] = $pendaftaran->kegiatan; |
|
|
|
|
310
|
|
|
//$response['sekolah'] = $pendaftaran->sekolah->nama; |
|
|
|
|
311
|
|
|
//$response['user'] = $pendaftaran->user; |
|
|
|
|
312
|
|
|
$response['error'] = false; |
313
|
|
|
$response['message'] = 'Success'; |
314
|
|
|
$response['status'] = true; |
315
|
|
|
|
316
|
|
|
return response()->json($response); |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* Update the specified resource in storage. |
321
|
|
|
* |
322
|
|
|
* @param \Illuminate\Http\Request $request |
323
|
|
|
* @param \App\Pendaftaran $pendaftaran |
|
|
|
|
324
|
|
|
* @return \Illuminate\Http\Response |
325
|
|
|
*/ |
326
|
|
|
public function update(Request $request, $id) |
327
|
|
|
{ |
328
|
|
|
$admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first(); |
329
|
|
|
|
330
|
|
|
if($this->checkRole(['superadministrator'])){ |
331
|
|
|
$pendaftaran = $this->pendaftaran->with(['kegiatan', 'sekolah', 'user' ])->findOrFail($id); |
332
|
|
|
}else{ |
333
|
|
|
$pendaftaran = $this->pendaftaran->where('sekolah_id', $admin_sekolah->sekolah_id)->with(['kegiatan', 'sekolah', 'user' ])->findOrFail($id); |
334
|
|
|
|
335
|
|
|
if(is_null($pendaftaran)){ |
336
|
|
|
$response['error'] = true; |
|
|
|
|
337
|
|
|
$response['message'] = 'Terjadi kesalahan saat update data.'; |
338
|
|
|
$response['status'] = true; |
339
|
|
|
|
340
|
|
|
return response()->json($response); |
341
|
|
|
} |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
|
345
|
|
|
$validator = Validator::make($request->all(), [ |
346
|
|
|
'kegiatan_id' => 'required', |
347
|
|
|
'tanggal_pendaftaran' => 'required', |
348
|
|
|
'sekolah_id' => 'required', |
349
|
|
|
]); |
350
|
|
|
|
351
|
|
View Code Duplication |
if ($validator->fails()) { |
|
|
|
|
352
|
|
|
$error = true; |
353
|
|
|
$message = $validator->errors()->first(); |
354
|
|
|
|
355
|
|
|
} else { |
356
|
|
|
$pendaftaran->kegiatan_id = $request->input('kegiatan_id'); |
357
|
|
|
$pendaftaran->tanggal_pendaftaran = $request->input('tanggal_pendaftaran'); |
358
|
|
|
$pendaftaran->sekolah_id = $request->input('sekolah_id'); |
359
|
|
|
$pendaftaran->save(); |
360
|
|
|
|
361
|
|
|
$error = false; |
362
|
|
|
$message = 'Success'; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
$response['error'] = $error; |
|
|
|
|
366
|
|
|
$response['message'] = $message; |
367
|
|
|
$response['status'] = true; |
368
|
|
|
|
369
|
|
|
return response()->json($response); |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* Remove the specified resource from storage. |
374
|
|
|
* |
375
|
|
|
* @param \App\Pendaftaran $pendaftaran |
|
|
|
|
376
|
|
|
* @return \Illuminate\Http\Response |
377
|
|
|
*/ |
378
|
|
|
public function destroy($id) |
379
|
|
|
{ |
380
|
|
|
if(!$this->checkRole(['superadministrator'])){ |
381
|
|
|
$response['status'] = false; |
|
|
|
|
382
|
|
|
return json_encode($response); |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
$pendaftaran = $this->pendaftaran->findOrFail($id); |
386
|
|
|
|
387
|
|
|
if ($pendaftaran->delete()) { |
388
|
|
|
$response['status'] = true; |
|
|
|
|
389
|
|
|
} else { |
390
|
|
|
$response['status'] = false; |
|
|
|
|
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
return json_encode($response); |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
protected function checkRole($role = array()) |
397
|
|
|
{ |
398
|
|
|
return Auth::user()->hasRole($role); |
399
|
|
|
} |
400
|
|
|
} |
401
|
|
|
|
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.