<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP 5.1.6 or newer
 *
 * @package		CodeIgniter
 * @author		Ahmad Sanusi
 * @copyright	Copyright (c) 2014 Ahmad Sanusi
 * @license		http://codeigniter.com/user_guide/license.html
 * @link		http://codeigniter.com
 * @since		Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * CodeIgniter Model Class
 *
 * @package		CodeIgniter
 * @subpackage	Libraries
 * @category	Libraries
 * @author		Ahmad Sanusi
 * @link		http://codeigniter.com/user_guide/libraries/config.html
 */
class Pesertadidik_m extends MY_Model {

	/**
	 * Constructor
	 *
	 * @access public
	 */
	protected $_table_name = 'peserta_didik';
    protected $_order_by   = 'peserta_didik.peserta_didik_id DESC';
    protected $_primary_key = 'peserta_didik.peserta_didik_id';
    
    public $_rules         = array(
        'nama'=> array(
			'field'=>'nama',
			'label'=>'Nama Siswa',
			'rules'=>'trim|required|max_length[150]'),
        'kewarganegaraan'=> array(
			'field'=>'kewarganegaraan',
			'label'=>'Kewarganegaraan',
			'rules'=>'trim|required'),
        'desa_kelurahan'=> array(
			'field'=>'desa_kelurahan',
			'label'=>'Desa/Kelurahan',
			'rules'=>'trim|required'),
    );

	public function __construct()
	{
		parent::__construct();
    }
    
	public function get_data($id = NULL)
	{
		$method = 'result';

		$this->db->select('pd.*, ag.nama AS agama, 
            bk.kebutuhan_khusus AS kebutuhan_khusus, 
            jtt.nama AS tempat_tinggal,
            at.nama AS alat_transportasi,
            ayah.nama AS nama_ayah, 
            ayah.orang_tua_id AS id_ayah, 
            ibu.nama AS nama_ibu, 
            ibu.orang_tua_id AS id_ibu, 
            sk_ayah.nama AS status_kekerabatan_ayah,
            sk_ibu.nama AS status_kekerabatan_ibu
            ');
        
		if($id !== NULL)
		{
			$method = 'row';
            $this->db->join('agama ag','ag.agama_id=pd.agama_id','left');
            // Berkebutuhan Khusus
            $this->db->join('kebutuhan_khusus bk','bk.kebutuhan_khusus_id=pd.kebutuhan_khusus_id','left');
            // Tempat Tinggal
            $this->db->join('jenis_tinggal jtt','jtt.jenis_tinggal_id=pd.jenis_tinggal_id','left');
            // Tempat Tinggal
            $this->db->join('alat_transportasi at','at.alat_transportasi_id=pd.alat_transportasi_id','left');

            // Orangtua / Wali
            $this->db->join('orang_tua ayah','ayah.orang_tua_id=pd.ayah_id','left');
            $this->db->join('orang_tua ibu','ibu.orang_tua_id=pd.ibu_id','left');

             // Hubungan Kekerabatan
             $this->db->join('status_kekerabatan sk_ayah','sk_ayah.status_kekerabatan_id=ayah.status_kekerabatan_id','left');
             $this->db->join('status_kekerabatan sk_ibu','sk_ibu.status_kekerabatan_id=ibu.status_kekerabatan_id','left');

			$this->db->where('pd.peserta_didik_id', $id);
		}
		else
		{
			$this->db->limit('100');
		}
        return $this->db->get('peserta_didik pd')->$method();
	}

    public function get_datatables()
    {
   
        $this->_dtselect        = 'pd.peserta_didik_id, pd.nama, pd.registered, pd.nisn, pd.jenis_kelamin, pd.tempat_lahir, pd.tanggal_lahir, pd.nomor_telepon_seluler, pd.email';
        $this->_dtfrom          = 'peserta_didik pd';
        $this->_dtjoin          = array(
                                    array('peserta_didik_longitudinal pdl','pdl.peserta_didik_id = pd.peserta_didik_id','left')
                                );

        $this->_dtcolumn_order  = array(null, 'pd.nama','pd.jenis_kelamin','pd.nisn','pd.tempat_lahir','pd.tanggal_lahir',null);
        $this->_dtcolumn_search = array('pd.nama','pd.nisn');
        $this->_dtwhere         = array('pdl.semester_id' => $this->_data['lainnya']->tahun_semester->semester_id);
        $this->_dtfilter        = array('jenis_kelamin','alat_transportasi_id','pdl.asrama_id');

        return parent::get_datatables();
    }
}
// END pesertadidik_m Class

/* End of file pesertadidik_m.php */
/* Location: ./Application/modules/student/models/pesertadidik_m.php */