<?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 Pdb_m extends MY_Model {

	/**
	 * Constructor
	 *
	 * @access public
     */
     protected $_table_name  = 'peserta_didik_baru';
     protected $_order_by    = 'peserta_didik_baru.pdb_id DESC';
     protected $_primary_key = 'peserta_didik_baru.pdb_id';

	public function __construct()
	{
		parent::__construct();
    }

    public function get_datatables()
    {

        $this->_dtselect        = 'pdb.pdb_id, pdb.nama_lengkap, pdb.nisn, pdb.jenis_kelamin, pdb.tempat_lahir, pdb.tanggal_lahir, pdb.nomor_telepon_seluler, pdb.email, bp.nama AS bentuk_pendidikan, pdb.create_date AS tanggal_daftar';
        $this->_dtfrom          = 'peserta_didik_baru pdb';
        $this->_dtjoin          = array(
                                    array('tahun_ajaran ta','ta.tahun_ajaran_id = pdb.tahun_ajaran_id','left'),
                                    array('bentuk_pendidikan bp','bp.bentuk_pendidikan_id = pdb.bentuk_pendidikan_id','left'),
                                );

        $this->_dtcolumn_order  = array(null, 'pdb.nama_lengkap','pdb.jenis_kelamin','pdb.nisn','pdb.tempat_lahir','bp.nama','pdb.tanggal_lahir','pdb.create_date',null);
        $this->_dtcolumn_search = array('pdb.nama','pdb.nisn');
        $this->_dtwhere         = array('pdb.tahun_ajaran_id' => date('Y'));
        $this->_dtfilter        = array('pdb.jenis_kelamin','pdb.bentuk_pendidikan_id','pdb.tahun_ajaran_id');

        return parent::get_datatables();
    }


    public function get_data($id = NULL)
    {
        $this->db->select('pdb.*, ag.nama AS agama,
            bp.nama AS bentuk_pendidikan,
            tj.nama AS tahun_ajaran,
            pkj_ayah.nama AS pekerjaan_ayah,
            pkj_ibu.nama AS pekerjaan_ibu,
            pkj_wali.nama AS pekerjaan_wali,
            lv3.nama AS kecamatan,
            lv2.nama AS kabupaten');

            $this->db->join('agama ag','ag.agama_id=pdb.agama_id','left');
            $this->db->join('tahun_ajaran tj','tj.tahun_ajaran_id=pdb.tahun_ajaran_id','left');
            $this->db->join('bentuk_pendidikan bp','bp.bentuk_pendidikan_id=pdb.bentuk_pendidikan_id','left');

            // Wilayah
            $this->db->join('mst_wilayah lv3','pdb.kode_wilayah=lv3.kode_wilayah','left');
            $this->db->join('mst_wilayah lv2','lv3.mst_kode_wilayah=lv2.kode_wilayah','left');

            // pekerjaan
            $this->db->join('pekerjaan pkj_ayah','pkj_ayah.pekerjaan_id=pdb.pekerjaan_id_ayah','left');
            $this->db->join('pekerjaan pkj_ibu','pkj_ibu.pekerjaan_id=pdb.pekerjaan_id_ibu','left');
            $this->db->join('pekerjaan pkj_wali','pkj_wali.pekerjaan_id=pdb.pekerjaan_id_wali','left');

            if ($id !== NULL) {
                $this->db->where('pdb.pdb_id', $id);
                return $this->db->get('peserta_didik_baru pdb')->row();
            }
            else
            {
                return $this->db->get('peserta_didik_baru pdb')->result();
            }

    }

}
// END pdb_m Class

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