<?php

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

class Hotel_static_pages_model extends CI_Model
{

    public $table = 'hotel_static_pages';
    public $id = 'ID';
    public $order = 'ASC';

    function __construct()
    {
        parent::__construct();
        $this->userDetails = $this->session->userdata('isUserLoggedIn');
    }

    // get all
    function get_all()
    {
        $this->db->order_by($this->id, $this->order);
        return $this->db->get($this->table)->result();
    }

    // get data by id
    function get_by_id($id)
    {
        $this->db->where($this->id, $id);
        return $this->db->get($this->table)->row();
    }
    
    // get total rows
    function total_rows($q = NULL) {
        $this->db->like('ID', $q);
	    $this->db->where("(`hotel_static_pages.ID` LIKE '%".$q."%' ESCAPE '!' OR `hotel_static_pages`.`fsTitle` LIKE '%".$q."%' ESCAPE '!' OR `hotel_static_pages`.`fsDescription` LIKE '%".$q."%' ESCAPE '!' OR `hotel_static_pages`.`fdCreateDate` LIKE '%".$q."%' ESCAPE '!' OR `hotel_static_pages`.`fdUpdateDate` LIKE '%".$q."%' ESCAPE '!')");
        $this->db->where('hotel_static_pages.fiHotelId', $this->userDetails['Id']);
	$this->db->from($this->table);
        return $this->db->count_all_results();
    }

    // get data with limit and search
    function get_limit_data($limit, $start = 0, $q = NULL) {
        $this->db->select('hotel_static_pages.*');
        $this->db->order_by('fsTitle', $this->order);
        $this->db->where("(`hotel_static_pages.ID` LIKE '%".$q."%' ESCAPE '!' OR `hotel_static_pages`.`fsTitle` LIKE '%".$q."%' ESCAPE '!' OR `hotel_static_pages`.`fsDescription` LIKE '%".$q."%' ESCAPE '!' OR `hotel_static_pages`.`fdCreateDate` LIKE '%".$q."%' ESCAPE '!' OR `hotel_static_pages`.`fdUpdateDate` LIKE '%".$q."%' ESCAPE '!')");
        $this->db->where('hotel_static_pages.fiHotelId', $this->userDetails['Id']);
	$this->db->limit($limit, $start);
        return $this->db->get($this->table)->result();
    }

    // insert data
    function insert($data)
    {
        $this->db->insert($this->table, $data);
    }

    // update data
    function update($id, $data)
    {
        $this->db->where($this->id, $id);
        $this->db->update($this->table, $data);
    }

    // delete data
    function delete($id)
    {
        $this->db->where($this->id, $id);
        $this->db->delete($this->table);
    }

}
