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

class wali_santri_model extends CI_Model
{
    public function get_data($table)
    {
        return $this->db->get($table);
    }

    public function insert_data($data, $table)
    {
        $this->db->insert($table, $data);
    }

    public function get_santri_by_id($id_santri)
    {
        return $this->db->get_where('santri', array('id_santri' => $id_santri))->row();
    }

    // Di dalam wali_santri_model.php
    public function get_data_by_id($id_wali_santri)
    {
        $this->db->where('id_wali_santri', $id_wali_santri);
        return $this->db->get('tb_wali_santri')->row();
    }


    public function get_all_santri()
    {
        // Mengambil data dari tabel tb_wali_santri dan menggabungkannya dengan tb_santri
        $this->db->select('tb_wali_santri.nama_wali_santri, tb_santri.nama_santri, tb_wali_santri.alamat, tb_wali_santri.no_telepon, tb_santri.id_santri');
        $this->db->from('tb_wali_santri');
        $this->db->join('tb_santri', 'tb_santri.id_santri = tb_wali_santri.id_santri');
        return $this->db->get()->result(); // Mengembalikan hasil query
    }

    public function update_data($data, $table)
    {
        $this->db->where('id_wali_santri', $data['id_wali_santri']);
        $this->db->update($table, $data);
    }

    public function check_wali_exists($id_santri)
    {
        $this->db->where('id_santri', $id_santri);
        $query = $this->db->get('tb_wali_santri');

        return $query->num_rows() > 0;
    }
}
