<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class inv_temple_model extends CI_Model {
    public function __construct() {
        parent::__construct();
        $this->temple = TBL_INV_TEMPLE;
    }
    
    public function list_all() {
        $this->db->select('*, CASE status WHEN 1 THEN "Active" ELSE "Inactive" END as status_str',FALSE);
        $this->db->where('status !=', 2);
        $this->db->order_by('id', 'desc');
        return $this->db->get($this->temple)->result();
    }
    
    public  function insert($data){  
        $this->db->insert($this->temple, $data);  
        return $this->db->insert_id();
    } 

    public function get_by_id($id) {
        $this->db->select('*, CASE status WHEN 1 THEN "Active" ELSE "Inactive" END as status_str',FALSE);
        $this->db->where('id',$id);
        return $this->db->get($this->temple)->row();
    } 

    public function update($data, $id){
        $this->db->where('id', $id);
        $this->db->update($this->temple, $data);
        return $this->db->affected_rows();
    }    
    
    public function type_exists($id = '',$type = '') {        
        if($id != '')
            $this->db->where('id !=', $id);
        
        $this->db->where('type', $type);
        $this->db->where('status !=', 2);
        if($this->db->get($this->temple)->num_rows())
            return 1;
        else 
            return 0;
    }

}
?>