Perbaikan modul data karyawan dan staff + modul SOP import
This commit is contained in:
@@ -6,32 +6,26 @@ use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Department;
|
||||
use App\Models\Position;
|
||||
use App\Models\TrainingMatrix;
|
||||
use App\Models\Subject; // PASTIKAN SUBJECT DI-IMPORT
|
||||
use App\Models\User;
|
||||
use App\Models\QuestionBank;
|
||||
|
||||
class ExamManagementController extends Controller
|
||||
{
|
||||
/**
|
||||
* Menampilkan halaman Bank Soal dengan Filter Komprehensif
|
||||
*/
|
||||
public function questionBank(Request $request)
|
||||
{
|
||||
// 1. Siapkan Data untuk Dropdown Filter
|
||||
$departments = Department::orderBy('name', 'asc')->get();
|
||||
$positions = Position::orderBy('name', 'asc')->get();
|
||||
// $matrices = TrainingMatrix::orderBy('title', 'asc')->get();
|
||||
$subjects = Subject::orderBy('name', 'asc')->get(); // Mengambil data Subject
|
||||
|
||||
// Ambil daftar user yang pernah membuat soal (untuk filter 'Pembuat')
|
||||
// Sesuaikan nama relasi/kolom jika berbeda
|
||||
$creators = User::whereHas('roles', function($q){
|
||||
$q->whereIn('name', ['admin', 'trainer']);
|
||||
})->orderBy('first_name', 'asc')->get();
|
||||
|
||||
// 2. Query Utama dengan Relasi
|
||||
$query = QuestionBank::with(['department', 'position', 'creator']);
|
||||
// Load relasi subject, department, position, dan creator
|
||||
$query = QuestionBank::with(['subject', 'department', 'position', 'creator']);
|
||||
|
||||
// 3. Logika Filter Dinamis
|
||||
// Logika Filter
|
||||
if ($request->filled('search')) {
|
||||
$query->where('question_text', 'like', '%' . $request->search . '%');
|
||||
}
|
||||
@@ -41,28 +35,55 @@ class ExamManagementController extends Controller
|
||||
if ($request->filled('position_id')) {
|
||||
$query->where('position_id', $request->position_id);
|
||||
}
|
||||
// if ($request->filled('matrix_id')) {
|
||||
// $query->where('training_matrix_id', $request->matrix_id);
|
||||
// }
|
||||
if ($request->filled('subject_id')) { // Filter berdasarkan Subject
|
||||
$query->where('subject_id', $request->subject_id);
|
||||
}
|
||||
if ($request->filled('question_type')) {
|
||||
$query->where('type', $request->question_type);
|
||||
$query->where('question_type', $request->question_type);
|
||||
}
|
||||
if ($request->filled('question_level')) {
|
||||
$query->where('level', $request->question_level);
|
||||
$query->where('question_level', $request->question_level);
|
||||
}
|
||||
if ($request->filled('created_by')) {
|
||||
$query->where('created_by', $request->created_by);
|
||||
}
|
||||
|
||||
// 4. Eksekusi Query dengan Pagination
|
||||
$questions = $query->latest()->paginate(15)->withQueryString();
|
||||
$totalQuestions = $questions->total();
|
||||
|
||||
return view('pages.admin.exams.question-bank', compact(
|
||||
'questions', 'totalQuestions', 'departments', 'positions', 'creators'
|
||||
'questions', 'totalQuestions', 'departments', 'positions', 'subjects', 'creators'
|
||||
));
|
||||
}
|
||||
|
||||
// Fungsi untuk menampilkan halaman Tambah Soal
|
||||
public function create()
|
||||
{
|
||||
$departments = Department::orderBy('name', 'asc')->get();
|
||||
$positions = Position::orderBy('name', 'asc')->get();
|
||||
$subjects = Subject::orderBy('name', 'asc')->get(); // Kirim Subject ke form
|
||||
|
||||
return view('pages.admin.exams.create', compact('departments', 'positions', 'subjects'));
|
||||
}
|
||||
|
||||
// Fungsi untuk menampilkan halaman Edit Soal
|
||||
public function edit($id)
|
||||
{
|
||||
$question = QuestionBank::findOrFail($id);
|
||||
$departments = Department::orderBy('name', 'asc')->get();
|
||||
$positions = Position::orderBy('name', 'asc')->get();
|
||||
$subjects = Subject::orderBy('name', 'asc')->get(); // Kirim Subject ke form
|
||||
|
||||
return view('pages.admin.exams.edit', compact('question', 'departments', 'positions', 'subjects'));
|
||||
}
|
||||
|
||||
// Fungsi Show untuk Detail Soal
|
||||
public function show($id)
|
||||
{
|
||||
$question = QuestionBank::with(['subject', 'department', 'position', 'creator'])->findOrFail($id);
|
||||
return view('pages.admin.exams.show', compact('question'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Menghapus banyak soal sekaligus (Bulk Delete)
|
||||
*/
|
||||
@@ -86,6 +107,6 @@ class ExamManagementController extends Controller
|
||||
*/
|
||||
public function importView()
|
||||
{
|
||||
return view('pages.admin.exams.import-questions');
|
||||
return view('pages.admin.exams.questions.import');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user