<?php
class M_materi extends CI_Model {
    function __call($func, $arg) {
        if ($func == 'get_all_materi') {
            switch (count($arg)) {
                case 1:
                    return $this->db->query("SELECT * FROM tbl_materi WHERE materi_guru_id='$arg[0]'");

                case 2:
                    return $this->db->query("SELECT * FROM tbl_materi 
                                            JOIN tbl_guru 
                                            ON tbl_guru.guru_id=tbl_materi.materi_guru_id
                                            AND tbl_materi.materi_mapel='$arg[0]'
                                            AND tbl_materi.materi_kelas_id='$arg[1]'");

            }
        }
    }

    function get_all_mapel() {
        return $this->db->query("SELECT materi_mapel FROM tbl_materi");
    }

    function get_guru_nama($id) {
        return $this->db->query("SELECT guru_nama FROM tbl_guru WHERE guru_id=$id");
    }

    function save_materi($guru_id, $kelas_guru, $materi_mapel, $materi_judul, $konten, $materi_catatan) {
        foreach($kelas_guru as $k) {
            $this->db->query("INSERT INTO 
                            tbl_materi (
                                materi_guru_id, 
                                materi_kelas_id, 
                                materi_mapel, 
                                materi_judul,
                                materi_konten,
                                materi_catatan
                            )
                            VALUES (
                                '$guru_id',
                                '$k',
                                '$materi_mapel',
                                '$materi_judul',
                                '$konten',
                                '$materi_catatan'
                            )
                            ");
        }
    }
}
?>