<?php
namespace App\Controllers;

use Core\Database;
use PDO;

class DosenCorectSoalController
{
    private $db;

    public function __construct()
    {
        $this->db = Database::getConnection();
    }

    public function index()
    {
        $niy = $_SESSION['user']['niy'] ?? null;
        if (!$niy) {
            header("Location: /login");
            exit();
        }

        // Ambil daftar mata kuliah yang diampu dosen
        $stmt = $this->db->prepare("
            SELECT DISTINCT dm.kode_mk, mk.nama_mk, dm.kode_kelas 
            FROM tb_dosen_mk dm
            INNER JOIN tb_mk mk ON dm.kode_mk = mk.kode_mk
            INNER JOIN tb_akademik ak ON dm.tahun_akademik = ak.tahun_akademik
            WHERE dm.niy = :niy AND ak.status = 'Aktif'
        ");
        $stmt->execute(['niy' => $niy]);
        $mata_kuliah = $stmt->fetchAll(PDO::FETCH_ASSOC);

        // Tampilkan view yang memuat daftar mata kuliah
        require __DIR__ . '/../Views/dosen/koreksi_soal.php';
    }
}

