<?php
class Report_Settings_Model extends CI_Model {
    public function __construct(){
        parent::__construct();
        $this->report_settings = TBL_SETTINGS_REPORT;
    }
    
    public function list_all() {
        $resource = $this->db->get($this->report_settings);
        return $resource->result();
    }
    
    public function list_active() {
        $this->db->select('id, report_name, controller_name');
        $this->db->where('status', 1);
        $this->db->order_by('seq_number');
        return $this->db->get($this->report_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->report_settings)->row()->controller_name;
    }
    
    public function permissions_by_controller($controller_name_arr) {
        $this->db->select('id, report_name, controller_name, menu_name, menu_icon');
        if(!empty($controller_name_arr))
            $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->report_settings)->result_array();
    }
    
    public function get_data($ids) {
        $this->db->select('id');
        if (!empty($ids)) {
            $this->db->where_not_in('id', $ids);
        }
        
        $resource = $this->db->get($this->report_settings);
        return $resource->result();
    }
    
    public function update($data,$id){
        $this->db->where('id', $id);
        $this->db->update($this->report_settings, $data);
        return $this->db->affected_rows();
    }
}
?>
