<?php
class Inventory_Settings_Model extends CI_Model {
    public function __construct(){
        parent::__construct();
        $this->inventory_settings = TBL_SETTINGS_INVENTORY;
        $this->statue_settings = TBL_SETTINGS_STATUE;
    }
    
    public function list_all() {
        $resource = $this->db->get($this->inventory_settings);
        return $resource->result();
    }
    
    public function statue_list() {
        $resource = $this->db->get($this->statue_settings);
        return $resource->result();
    }
    
    public function get_data($ids = '') {
        $this->db->select('id');
        if (!empty($ids)) {
            $this->db->where_not_in('id', $ids);
        }
        $resource = $this->db->get($this->inventory_settings);
        return $resource->result();
    }
    
    public function list_active() {
        $this->db->select('id, inventory_name, controller_name');
        $this->db->where('status', 1);
        $this->db->order_by('seq_number');
        return $this->db->get($this->inventory_settings)->result();
    }
    
    public function controller_name_str() {
        $this->db->select('GROUP_CONCAT(controller_name SEPARATOR ",") as controller_name', FALSE);
        $this->db->where('status', 1);
        return $this->db->get($this->inventory_settings)->row()->controller_name;
    }
    
    public function statue_list_active() {
        $this->db->select('id, menu_name, controller_name');
        $this->db->where('status', 1);
        $this->db->order_by('seq_number');
        return $this->db->get($this->statue_settings)->result();
    }
    
    public function statue_controller_name_str() {
        $this->db->select('GROUP_CONCAT(controller_name SEPARATOR ",") as controller_name', FALSE);
        $this->db->where('status', 1);
        return $this->db->get($this->statue_settings)->row()->controller_name;
    }
    
    public function permissions_by_controller($controller_name_arr) {
        
        if(!empty($controller_name_arr)) :
            $this->db->select('id, inventory_name, controller_name, menu_name, menu_icon');
            $this->db->where_in('controller_name', $controller_name_arr);
        
            $this->db->where('status', 1);
            $this->db->order_by('seq_number');
            return $this->db->get($this->inventory_settings)->result_array();
        endif;
        
        return array();
    }
    
    public function statue_permissions_by_controller($controller_name_arr) {
        
        if(!empty($controller_name_arr)) :
            $this->db->select('id, menu_name, controller_name, menu_icon');
            $this->db->where_in('controller_name', $controller_name_arr);
        
            $this->db->where('status', 1);
            $this->db->order_by('seq_number');
            return $this->db->get($this->statue_settings)->result_array();
        endif;
        
        return array();
    }
    
    public function update($data,$id){
        $this->db->where('id', $id);
        $this->db->update($this->inventory_settings, $data);
        return $this->db->affected_rows();
    }
}
?>
