<?php
class Service_Settings_Model extends CI_Model {
    public function __construct(){
        parent::__construct();
        $this->service_settings = TBL_SERVICE_MENU;
    }
    
    public function list_all() {
        $resource = $this->db->get($this->service_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->service_settings);
        return $resource->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->service_settings)->row()->controller_name;
    }
    
    public function permissions_by_controller($controller_name_arr) {
        $this->db->select('id, service_name, controller_name, menu_name, menu_icon, seq_number, table_name');
        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->service_settings)->result_array();
    }
    
    public function list_active() {
        $this->db->select('id, service_name, controller_name');
        $this->db->where('status', 1);
        $this->db->order_by('seq_number');
        return $this->db->get($this->service_settings)->result();
    }
    
    public function get_by_id($id) {
        $this->db->where('id',$id);
        return $this->db->get($this->service_settings)->row();
    }
    
    public function update($data,$id){
        $this->db->where('id', $id);
        $this->db->update($this->service_settings, $data);
        return $this->db->affected_rows();
    }
}
?>
