<?php class specialities_model extends CI_Model{

	private $table_name	= 'especialidades';			// users profiles

	public function get_specialities($active=null)
	{
		$this->db->from($this->table_name);
		$this->db->order_by('nombre');
		$query=$this->db->get();
		return $query->result_array();
		
	}

	
	public function get_speciality($id)
	{
		$this->db->from($this->table_name);
		$this->db->where('id_especialidades', $id);		
		$query=$this->db->get();
		return $query->row_array();
		
	}



	public function set_speciality($id,$data,$mode=null)
	{
		if ($mode == 'insert') {
			$this->db->insert($this->table_name, $data);
			return $this->db->insert_id();
		} else {
			$this->db->where('id_especialidades', $id);
			return $this->db->update($this->table_name, $data);
		}
		
	}

	public function delete_speciality($id)
	{
		$this->db->where('id_especialidades', $id);
		return $this->db->delete($this->table_name);
	
	}	
	
	public function get_speciality_log($id)
	{
		$txtSelect = '*';
		$this->db->select($txtSelect);
		$this->db->from('especialidades_log');
		$this->db->where('id_especialidades', $id);
		$this->db->order_by('fecha','desc');
		$query=$this->db->get();
		return $query->result_array();
	}	
	
	
	public function set_speciality_log($data)
	{
		return $this->db->insert('especialidades_log', $data);
	}	


	public function is_unique($nombre, $id)
	{
		$this->db->from($this->table_name);
		$this->db->where('id_especialidades !=', $id);
		$this->db->where('nombre', $nombre);				
		$query=$this->db->get();
		if ($query->num_rows()>0) {return false;}else { return true;}
	}

	
}

