|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bantenprov\PassingGrade\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
/* Require */ |
|
6
|
|
|
use App\Http\Controllers\Controller; |
|
7
|
|
|
use Illuminate\Http\Request; |
|
8
|
|
|
use Illuminate\Support\Facades\DB; |
|
9
|
|
|
use Bantenprov\PassingGrade\Facades\PassingGradeFacade; |
|
10
|
|
|
|
|
11
|
|
|
/* Models */ |
|
12
|
|
|
use Bantenprov\Sekolah\Models\Bantenprov\Sekolah\Sekolah; |
|
13
|
|
|
use Bantenprov\Siswa\Models\Bantenprov\Siswa\Siswa; |
|
14
|
|
|
use App\User; |
|
15
|
|
|
use Bantenprov\Sekolah\Models\Bantenprov\Sekolah\AdminSekolah; |
|
16
|
|
|
|
|
17
|
|
|
/* Etc */ |
|
18
|
|
|
use Validator; |
|
19
|
|
|
use Auth; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The PassingGradeController class. |
|
23
|
|
|
* |
|
24
|
|
|
* @package Bantenprov\PassingGrade |
|
25
|
|
|
* @author bantenprov <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
class PassingGradeController extends Controller |
|
28
|
|
|
{ |
|
29
|
|
|
protected $sekolah; |
|
30
|
|
|
protected $user; |
|
31
|
|
|
protected $admin_sekolah; |
|
32
|
|
|
protected $user_id; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Create a new controller instance. |
|
36
|
|
|
* |
|
37
|
|
|
* @return void |
|
|
|
|
|
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->sekolah = new Sekolah; |
|
42
|
|
|
$this->siswa = new Siswa; |
|
43
|
|
|
$this->user = new User; |
|
44
|
|
|
$this->user_id = isset(Auth::User()->id) ?? null; |
|
45
|
|
|
$this->admin_sekolah = AdminSekolah::where('admin_sekolah_id', $this->user_id)->first(); |
|
46
|
|
|
$this->admin_sekolah_id = isset($this->admin_sekolah->sekolah_id) ?? null; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Display a listing of the resource. |
|
51
|
|
|
* |
|
52
|
|
|
* @return \Illuminate\Http\Response |
|
53
|
|
|
*/ |
|
54
|
|
|
public function index(Request $request) |
|
55
|
|
|
{ |
|
56
|
|
View Code Duplication |
if (request()->has('sort')) { |
|
|
|
|
|
|
57
|
|
|
list($sortCol, $sortDir) = explode('|', request()->sort); |
|
58
|
|
|
|
|
59
|
|
|
$query = $this->sekolah |
|
60
|
|
|
->orderBy($sortCol, $sortDir); |
|
61
|
|
|
} else { |
|
62
|
|
|
$query = $this->sekolah |
|
63
|
|
|
->orderBy('npsn', 'asc'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
if ($request->exists('filter')) { |
|
67
|
|
|
$query->where(function($q) use($request) { |
|
68
|
|
|
$value = "%{$request->filter}%"; |
|
69
|
|
|
|
|
70
|
|
|
if (Auth::User()->hasRole(['superadministrator'])) { |
|
71
|
|
|
$q->where('nama', 'like', $value) |
|
72
|
|
|
->orWhere('npsn', 'like', $value); |
|
73
|
|
|
} else { |
|
74
|
|
|
$q->where('nama', 'like', $value) |
|
75
|
|
|
->orWhere('npsn', 'like', $value); |
|
76
|
|
|
} |
|
77
|
|
|
}); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
if (Auth::User()->hasRole(['superadministrator'])) { |
|
|
|
|
|
|
81
|
|
|
// |
|
82
|
|
|
} else { |
|
83
|
|
|
$query->where('id', $this->admin_sekolah_id); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$perPage = request()->has('per_page') ? (int) request()->per_page : null; |
|
87
|
|
|
$response = $query->with(['jenis_sekolah', 'province', 'city', 'district', 'village', 'master_zona', 'user'])->paginate($perPage); |
|
88
|
|
|
|
|
89
|
|
|
if (is_null($this->admin_sekolah) && !Auth::User()->hasRole(['superadministrator'])) { |
|
|
|
|
|
|
90
|
|
|
// $response = (object) []; |
|
|
|
|
|
|
91
|
|
|
} else { |
|
|
|
|
|
|
92
|
|
|
// |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
return response()->json($response) |
|
96
|
|
|
->header('Access-Control-Allow-Origin', '*') |
|
97
|
|
|
->header('Access-Control-Allow-Methods', 'GET'); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Display the specified resource. |
|
102
|
|
|
* |
|
103
|
|
|
* @param \App\Sekolah $sekolah |
|
|
|
|
|
|
104
|
|
|
* @return \Illuminate\Http\Response |
|
105
|
|
|
*/ |
|
106
|
|
|
public function show($id, $track = null, Request $request) |
|
107
|
|
|
{ |
|
108
|
|
View Code Duplication |
if (request()->has('sort')) { |
|
|
|
|
|
|
109
|
|
|
list($sortCol, $sortDir) = explode('|', request()->sort); |
|
110
|
|
|
|
|
111
|
|
|
$query = $this->siswa->orderBy($sortCol, $sortDir); |
|
112
|
|
|
} else { |
|
113
|
|
|
$query = $this->siswa |
|
114
|
|
|
->orderBy('nomor_un', 'asc'); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
if ($request->exists('filter')) { |
|
118
|
|
|
$query->where(function($q) use($request) { |
|
119
|
|
|
$value = "%{$request->filter}%"; |
|
120
|
|
|
|
|
121
|
|
|
if (Auth::User()->hasRole(['superadministrator'])) { |
|
122
|
|
|
$q->where('nomor_un', 'like', $value) |
|
123
|
|
|
->orWhere('nik', 'like', $value) |
|
124
|
|
|
->orWhere('nama_siswa', 'like', $value) |
|
125
|
|
|
->orWhere('no_kk', 'like', $value) |
|
126
|
|
|
->orWhere('nisn', 'like', $value); |
|
127
|
|
|
} else { |
|
128
|
|
|
$q->where('nomor_un', 'like', $value) |
|
129
|
|
|
->orWhere('nik', 'like', $value) |
|
130
|
|
|
->orWhere('nama_siswa', 'like', $value) |
|
131
|
|
|
->orWhere('no_kk', 'like', $value) |
|
132
|
|
|
->orWhere('nisn', 'like', $value); |
|
133
|
|
|
} |
|
134
|
|
|
}); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
if (Auth::User()->hasRole(['superadministrator'])) { |
|
|
|
|
|
|
138
|
|
|
// |
|
139
|
|
|
} else { |
|
140
|
|
|
$query->where('sekolah_id', $this->admin_sekolah_id); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
if ($track == 'umum') { |
|
144
|
|
|
$query->whereIn('kegiatan_id', ['12', '22']); |
|
145
|
|
|
} else if ($track == 'prestasi') { |
|
146
|
|
|
$query->whereIn('kegiatan_id', ['11', '21']); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
$perPage = request()->has('per_page') ? (int) request()->per_page : null; |
|
150
|
|
|
$response = $query->with(['province', 'city', 'district', 'village', 'sekolah', 'prodi_sekolah', 'user', 'akademik', 'nilai'])->paginate($perPage); |
|
151
|
|
|
|
|
152
|
|
|
if (is_null($this->admin_sekolah) && !Auth::User()->hasRole(['superadministrator'])) { |
|
|
|
|
|
|
153
|
|
|
// $response = (object) []; |
|
|
|
|
|
|
154
|
|
|
} else { |
|
|
|
|
|
|
155
|
|
|
// |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
foreach ($response as $siswa) { |
|
159
|
|
|
if (isset($siswa->prodi_sekolah->program_keahlian)) { |
|
160
|
|
|
$siswa->prodi_sekolah->program_keahlian; |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
return response()->json($response) |
|
165
|
|
|
->header('Access-Control-Allow-Origin', '*') |
|
166
|
|
|
->header('Access-Control-Allow-Methods', 'GET'); |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.