<?php
class Xppo_model extends CI_Model{
	public function __construct(){
		parent::__construct();
	}

	public function ver($personal,$permiso){
		$this->db->select('*')->from('personal_permiso');
		$this->db->where('pers_id',$personal);
		$this->db->where('perm_id',$permiso);
		$query = $this->db->get();
		return $query->row();
	}

	public function listar($xpl, $texto = ''){
		$qwhere = ($texto!='')?" WHERE permiso.perm_descripcion LIKE '%{$texto}%'":"";
		$query 	= "	SELECT
						permiso.perm_id,
						permiso.perm_descripcion,
						(
						SELECT personal_permiso.pers_id
						FROM personal_permiso
						WHERE personal_permiso.perm_id = permiso.perm_id AND personal_permiso.pers_id = $xpl) AS pers_id
					FROM
						permiso
					{$qwhere}";
		return $this->db->query($query);
	}

	public function validar($xpl, $xpo){
		$this->db->select('*')->from('personal_permiso');
		$this->db->where('xpl',$personal);
		$this->db->where('xpo',$permiso);
		$query = $this->db->get();
		return $query->row();
	}

	public function insertar($data){
		$this->db->insert('personal_permiso',$data);
	}

	public function eliminar($xpl, $xpo){
		$this->db->where('pers_id',$xpl);
		$this->db->where('perm_id',$xpo);
		$this->db->delete('personal_permiso');
	}
}