<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class SiswaModel extends CI_Model {

    // Get all siswa
    public function getAll()
    {
        return $this->db
            ->order_by('nama_kelas', 'ASC')
            ->order_by('nama', 'ASC')
            ->get('v_siswa')
            ->result();
    }

    // Insert siswa
    public function insert($data)
    {
        return $this->db->insert('siswa', $data);
    }

    // Cari ID kelas berdasarkan nama kelas
    public function getKelasIdByName($nama)
    {
        $row = $this->db->get_where('kelas', ['nama' => $nama])->row();
        return $row ? $row->id : null;
    }

    // Cari ID kamar berdasarkan nama kamar & nama gedung
    public function getKamarIdByName($kamar, $gedung)
    {
        $row = $this->db->get_where('kamar', [
            'nama'   => $kamar,
            'gedung' => $gedung
        ])->row();

        return $row ? $row->id : null;
    }
}
