Sync SOP ke e-doc Plant & Add Subject dan penyempurnaan bagian matrix training karyawan

This commit is contained in:
Iwit
2026-06-04 19:01:17 +07:00
parent 91c0a8147f
commit 1089f60a3d
26 changed files with 1241 additions and 155 deletions
@@ -6,54 +6,60 @@ use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Department;
use App\Models\Position;
use App\Models\Subject; // PASTIKAN SUBJECT DI-IMPORT
use App\Models\Subject;
use App\Models\User;
use App\Models\QuestionBank;
class ExamManagementController extends Controller
{
public function questionBank(Request $request)
public function questionBank(Request $request)
{
$departments = Department::orderBy('name', 'asc')->get();
$positions = Position::orderBy('name', 'asc')->get();
$subjects = Subject::orderBy('name', 'asc')->get(); // Mengambil data Subject
$creators = User::whereHas('roles', function($q){
$q->whereIn('name', ['admin', 'trainer']);
})->orderBy('first_name', 'asc')->get();
// 1. Ambil ID unik siapa saja yang PERNAH membuat soal di tabel question_banks
$creatorIds = \App\Models\QuestionBank::whereNotNull('created_by')
->distinct()
->pluck('created_by');
// Load relasi subject, department, position, dan creator
$query = QuestionBank::with(['subject', 'department', 'position', 'creator']);
// 2. Tarik data User HANYA berdasarkan ID pembuat soal tersebut
$creators = \App\Models\User::whereIn('id', $creatorIds)
->orderBy('first_name', 'asc')
->get();
// Logika Filter
if ($request->filled('search')) {
$query->where('question_text', 'like', '%' . $request->search . '%');
// 3. Tarik data pendukung lainnya untuk filter & dropdown
$subjects = \App\Models\Subject::orderBy('name', 'asc')->get();
$departments = \App\Models\Department::orderBy('name', 'asc')->get();
$positions = \App\Models\Position::orderBy('name', 'asc')->get();
// 4. Hitung Total Soal Keseluruhan (TANPA FILTER) untuk Badge di View
$totalQuestions = \App\Models\QuestionBank::count(); // <--- TAMBAHKAN BARIS INI
// 5. Query utama Bank Soal (dengan fitur pencarian/filter)
$query = \App\Models\QuestionBank::with(['subject', 'department', 'creator', 'position']);
// Filter berdasarkan pembuat soal
if ($request->filled('creator_id')) {
$query->where('created_by', $request->creator_id);
}
// Filter berdasarkan subject/materi
if ($request->filled('subject_id')) {
$query->where('subject_id', $request->subject_id);
}
// Filter berdasarkan departemen
if ($request->filled('department_id')) {
$query->where('department_id', $request->department_id);
}
// Filter berdasarkan posisi/jabatan
if ($request->filled('position_id')) {
$query->where('position_id', $request->position_id);
}
if ($request->filled('subject_id')) { // Filter berdasarkan Subject
$query->where('subject_id', $request->subject_id);
}
if ($request->filled('question_type')) {
$query->where('question_type', $request->question_type);
}
if ($request->filled('question_level')) {
$query->where('question_level', $request->question_level);
}
if ($request->filled('created_by')) {
$query->where('created_by', $request->created_by);
}
$questions = $query->latest()->paginate(15)->withQueryString();
$totalQuestions = $questions->total();
// Pagination
$questions = $query->latest()->paginate(20);
return view('pages.admin.exams.question-bank', compact(
'questions', 'totalQuestions', 'departments', 'positions', 'subjects', 'creators'
));
// Pastikan $totalQuestions ikut dikirim ke compact
return view('pages.admin.question-banks.question-bank', compact('questions', 'creators', 'subjects', 'departments', 'positions', 'totalQuestions'));
}
// Fungsi untuk menampilkan halaman Tambah Soal
@@ -63,7 +69,7 @@ class ExamManagementController extends Controller
$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'));
return view('pages.admin.question-banks.create', compact('departments', 'positions', 'subjects'));
}
// Fungsi untuk menampilkan halaman Edit Soal
@@ -74,14 +80,14 @@ class ExamManagementController extends Controller
$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'));
return view('pages.admin.question-banks.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'));
return view('pages.admin.question-banks.show', compact('question'));
}
/**