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->admin_sekolah = AdminSekolah::where('admin_sekolah_id', $this->user_id)->first(); |
45
|
|
|
$this->user_id = isset(Auth::User()->id) ? Auth::User()->id : null; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Display a listing of the resource. |
50
|
|
|
* |
51
|
|
|
* @return \Illuminate\Http\Response |
52
|
|
|
*/ |
53
|
|
|
public function index(Request $request) |
54
|
|
|
{ |
55
|
|
View Code Duplication |
if (request()->has('sort')) { |
|
|
|
|
56
|
|
|
list($sortCol, $sortDir) = explode('|', request()->sort); |
57
|
|
|
|
58
|
|
|
$query = $this->sekolah |
59
|
|
|
->orderBy($sortCol, $sortDir); |
60
|
|
|
} else { |
61
|
|
|
$query = $this->sekolah |
62
|
|
|
->orderBy('npsn', 'asc'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if ($request->exists('filter')) { |
66
|
|
|
$query->where(function($q) use($request) { |
67
|
|
|
$value = "%{$request->filter}%"; |
68
|
|
|
|
69
|
|
|
if (Auth::User()->hasRole(['superadministrator'])) { |
70
|
|
|
$q->where('nama', 'like', $value) |
71
|
|
|
->orWhere('npsn', 'like', $value); |
72
|
|
|
} else { |
73
|
|
|
$q->where('nama', 'like', $value) |
74
|
|
|
->orWhere('npsn', 'like', $value); |
75
|
|
|
} |
76
|
|
|
}); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if (Auth::User()->hasRole(['superadministrator'])) { |
|
|
|
|
80
|
|
|
// |
81
|
|
|
} else if (!is_null($this->admin_sekolah)) { |
82
|
|
|
$query->where('id', $this->admin_sekolah->sekolah_id); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$perPage = request()->has('per_page') ? (int) request()->per_page : null; |
86
|
|
|
$response = $query->with(['jenis_sekolah', 'province', 'city', 'district', 'village', 'master_zona', 'user'])->paginate($perPage); |
|
|
|
|
87
|
|
|
|
88
|
|
|
if (is_null($this->admin_sekolah) && !Auth::User()->hasRole(['superadministrator'])) { |
89
|
|
|
$response = $query->with(['user'])->paginate($perPage); |
90
|
|
|
} else { |
91
|
|
|
$response = $query->with(['user'])->paginate($perPage); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return response()->json($response) |
95
|
|
|
->header('Access-Control-Allow-Origin', '*') |
96
|
|
|
->header('Access-Control-Allow-Methods', 'GET'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Display the specified resource. |
101
|
|
|
* |
102
|
|
|
* @param \App\Sekolah $sekolah |
|
|
|
|
103
|
|
|
* @return \Illuminate\Http\Response |
104
|
|
|
*/ |
105
|
|
|
public function show($id, $track = null, Request $request) |
106
|
|
|
{ |
107
|
|
View Code Duplication |
if (request()->has('sort')) { |
|
|
|
|
108
|
|
|
list($sortCol, $sortDir) = explode('|', request()->sort); |
109
|
|
|
|
110
|
|
|
$query = $this->siswa->orderBy($sortCol, $sortDir); |
111
|
|
|
} else { |
112
|
|
|
$query = $this->siswa |
113
|
|
|
->orderBy('nomor_un', 'asc'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
if ($request->exists('filter')) { |
117
|
|
|
$query->where(function($q) use($request) { |
118
|
|
|
$value = "%{$request->filter}%"; |
119
|
|
|
|
120
|
|
|
if (Auth::User()->hasRole(['superadministrator'])) { |
121
|
|
|
$q->where('nomor_un', 'like', $value) |
122
|
|
|
->orWhere('nik', 'like', $value) |
123
|
|
|
->orWhere('nama_siswa', 'like', $value) |
124
|
|
|
->orWhere('no_kk', 'like', $value) |
125
|
|
|
->orWhere('nisn', 'like', $value); |
126
|
|
|
} else { |
127
|
|
|
$q->where('nomor_un', 'like', $value) |
128
|
|
|
->orWhere('nik', 'like', $value) |
129
|
|
|
->orWhere('nama_siswa', 'like', $value) |
130
|
|
|
->orWhere('no_kk', 'like', $value) |
131
|
|
|
->orWhere('nisn', 'like', $value); |
132
|
|
|
} |
133
|
|
|
}); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
if (Auth::User()->hasRole(['superadministrator'])) { |
137
|
|
|
$query->where('sekolah_id', '=', $id); |
138
|
|
|
} else if (!is_null($this->admin_sekolah)) { |
139
|
|
|
$query->where('sekolah_id', '=', $this->admin_sekolah->sekolah_id); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
if ($track == 'umum') { |
143
|
|
|
$query->whereIn('kegiatan_id', ['12', '22']); |
144
|
|
|
} else if ($track == 'prestasi') { |
145
|
|
|
$query->whereIn('kegiatan_id', ['11', '21']); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
$perPage = request()->has('per_page') ? (int) request()->per_page : null; |
149
|
|
|
|
150
|
|
|
if (is_null($this->admin_sekolah) && !Auth::User()->hasRole(['superadministrator'])) { |
151
|
|
|
$response = $query->with(['province', 'city', 'district', 'village', 'sekolah', 'prodi_sekolah', 'user', 'akademik', 'nilai'])->paginate($perPage); |
152
|
|
|
} else { |
153
|
|
|
$response = $query->with(['province', 'city', 'district', 'village', 'sekolah', 'prodi_sekolah', 'user', 'akademik', 'nilai'])->paginate($perPage); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
foreach ($response as $siswa) { |
157
|
|
|
if (isset($siswa->prodi_sekolah->program_keahlian)) { |
158
|
|
|
$siswa->prodi_sekolah->program_keahlian; |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
return response()->json($response) |
163
|
|
|
->header('Access-Control-Allow-Origin', '*') |
164
|
|
|
->header('Access-Control-Allow-Methods', 'GET'); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
Adding a
@return
annotation 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.