Adminaccessaction_model.php 4.07 KB
Newer Older
Phạm Văn Đoan committed
1 2
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

3
class Adminaccessaction_model extends CI_Model {
Phạm Văn Đoan committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    protected $_table='admin_access_action';

    public function __construct(){
        parent::__construct();
        date_default_timezone_set("Asia/Ho_Chi_Minh");
    }

    public function add($dataInsert){
        $this->db->insert($this->_table, $dataInsert);
    }

    // Thêm nhiều quyền truy cập
    public function addBatch($dataInsertBatch){
        $this->db->insert_batch($this->_table, $dataInsertBatch);
    }

    // Xóa quyền truy cập
    public function delete($admin_id, $access_action_id){
        $this->db->where('admin_id', $admin_id);
        $this->db->where('access_action_id', $access_action_id);
        $this->db->delete($this->_table);
    }

    // Lấy danh sách ID quyền truy cập action của user
    public function getByAdminId($admin_id, $group_id){
        // Lấy mảng controller_id từ group_id
        $this->load->model('mgroupaccesscontroller');
        $listControllerByGroupId = $this->mgroupaccesscontroller->getByGroupId($group_id);
        //
        $this->db->select('aa.*');
        $this->db->from($this->_table.' adaa');
        $this->db->join('access_action aa', 'aa.id = adaa.access_action_id');
        $this->db->where('adaa.admin_id', $admin_id);
        if(count($listControllerByGroupId) > 0){
            $this->db->where_in('aa.controller_id', $listControllerByGroupId);
        }
        $query = $this->db->get();
        $result = $query->result_array();
        $list = array();
        foreach($result as $value){
            $list[] = $value['id'];
        }
        return $list;
    }

    // Lấy danh sách ID quyền truy cập action của user
    public function getActionAssignedByAdminId($admin_id, $is_active=true){
        $this->db->select('aa.*');
        $this->db->from($this->_table.' adaa');
        $this->db->join('access_action aa', 'aa.id = adaa.access_action_id');
        $this->db->where('adaa.admin_id', $admin_id);
        if($is_active == true){
            $this->db->where('aa.is_active', 1);
        }
        $query = $this->db->get();
        return $query->result_array();
    }

    public function getListPermissionForMenu(){
63
        $this->load->model('AdminModel');
Phạm Văn Đoan committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
        $admin_id = $this->session->userdata('id');

        $this->db->select('aa.name');
        $this->db->from($this->_table.' adaa');
        $this->db->join('access_action aa', 'aa.id = adaa.access_action_id');
        $this->db->where('adaa.admin_id', $admin_id);
        $this->db->where('aa.is_active', 1);
        $query = $this->db->get();
        $result = $query->result_array();
        $list = array();
        foreach($result as $value){
            $list[] = $value['name'];
        }
        return $list;
    }

    public function getCountActionInControllerAssigned(){
81
        $this->load->model('AdminModel');
Phạm Văn Đoan committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115

        $admin_id = $this->session->userdata('id');
        $adminInfo = $this->madmin->getById($admin_id);
        $group_id = $adminInfo[0]['group_id'];

        $this->db->select('ac.name AS controller_name, COUNT(*) AS count_action');
        $this->db->from($this->_table.' adaa');
        $this->db->join('access_action aa', 'aa.id = adaa.access_action_id');
        $this->db->join('access_controller ac', 'ac.id = aa.controller_id');
        $this->db->join('group_access_controller gac', 'gac.access_controller_id = ac.id');
        $this->db->join('group g', 'g.id = gac.group_id');

        $this->db->where('g.is_active', 1);
        $this->db->where('ac.is_active', 1);
        $this->db->where('aa.is_active', 1);
        $this->db->where('adaa.admin_id', $admin_id);
        $this->db->where('gac.group_id', $group_id);

        $this->db->group_by(array('gac.access_controller_id'));

        $query = $this->db->get();
        $result = $query->result_array();
        $list = array();
        foreach($result as $value){
            $list[] = $value['controller_name'];
        }
        return $list;
    }


}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */