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

class hotel_model extends CI_Model 
{

	function __construct()
    {
        parent::__construct();
        
    }
    function allhotel_details(){ 
        $this->db->select('name,id');
        $this->db->from('hotel');
        $this->db->where('status','1');
        $this->db->where('is_delete','0');
        $this->db->order_by("name", "asc");
        $query=$this->db->get();
        return $query->result_array();
    }
    function get_all_hotel_id(){ 
        $this->db->select('id');
        $this->db->from('hotel');
        $this->db->where('status','1');
        $this->db->where('is_delete','0');
        $this->db->order_by("name", "asc");
        $query=$this->db->get();
        return $query->result_array();
    }
   
    function addhotel($data){
        if($data['name']!=''){
            $name = $this->hotel_model->check_already_hotel($data['name']);
            if($name>0){
                $return = array();
                $return['msg']='alreadyexist';
                $return['error']='none';
            }else{
               $this->db->insert('hotel', $data);
               $return = array();
               $return['msg']=$this->db->insert_id();
               $return['error']='none';
            }
        }   
        return $return;
    }
    function check_already_hotel($name){
        $this->db->select('name');
        $this->db->from('hotel');
        $this->db->where('name', $name);
        $query = $this->db->get();
        $numr =$query->num_rows();
        return $numr;
    }
    function edithotel($data){
        $this->db->update("hotel", $data, array('id' => $data['id']));
        return $this->db->affected_rows();
    }
    function single_hotel_details($hotelid){ 
        $this->db->select('*');
        $this->db->from('hotel');
        $this->db->where('status','1');
        $this->db->where('is_delete','0');
        $this->db->where("id", $hotelid);
        $query=$this->db->get();
        return $query->row_array();
    }
    
    
       
}
?>
