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

3
class Accesscontroller_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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    protected $_table='access_controller';

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

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

    public function update($id, $dataUpdate){
        $this->db->where('id', $id);
        $this->db->update($this->_table, $dataUpdate);
    }

    public function delete($id){
        $this->db->where('id', $id);
        $this->db->delete($this->_table);
    }

    public function getById($id){
        $this->db->select('*');
        $this->db->from($this->_table);
        $this->db->where('id', $id);
        $query = $this->db->get();
        return $query->result_array();
    }

    public function getListFoxSelectBox($firstItem=''){
        $this->db->select('id, name');
        $this->db->from($this->_table);
        $this->db->where('is_active', 1);
        $this->db->order_by($this->_table.'.name', 'asc');
        $query = $this->db->get();
        $result = $query->result_array();
        $list = array();
        if($firstItem != ''){
            $list[''] = $firstItem;
        }
        foreach($result as $value){
            $list[$value['id']] = $value['name'];
        }
        return $list;
    }

    public function getListPermissionForMenu($firstItem=''){
        $this->db->select('id, name');
        $this->db->from($this->_table);
        $this->db->where('is_active', 1);
        $this->db->order_by($this->_table.'.name', 'asc');
        $query = $this->db->get();
        $result = $query->result_array();
        $list = array();
        if($firstItem != ''){
            $list[''] = $firstItem;
        }
        foreach($result as $value){
            $list[$value['id']] = $value['name'];
        }
        return $list;
    }

    public function getList($is_active=true){
        $this->db->select('*');
        $this->db->from($this->_table);
        if($is_active == true){
            $this->db->where('is_active', 1);
        }
        $this->db->order_by($this->_table.'.name', 'asc');
        $query = $this->db->get();
        return $query->result_array();
    }

    public function getListForPermission($is_active=true){
        $this->db->select('id, name');
        $this->db->from($this->_table);
        if($is_active == true){
            $this->db->where('is_active', 1);
        }
        $this->db->order_by($this->_table.'.name', 'asc');
        $query = $this->db->get();
        return $query->result_array();
    }

    public function getListByGroupId($group_id, $is_active=true){
        $this->db->select('ac.*');
        $this->db->from($this->_table.' ac');
        $this->db->join('group_access_controller gac', 'gac.access_controller_id = ac.id');
        $this->db->where('gac.group_id', $group_id);
        if($is_active == true){
            $this->db->where('ac.is_active', 1);
        }
        $this->db->order_by('ac.name', 'asc');
        $query = $this->db->get();
        return $query->result_array();
    }

    public function countAll($name=null){
        $this->db->select('COUNT(*) AS totalResults');
        $this->db->from($this->_table);
        if($name != null){
            $this->db->like('name', $name, 'both');
        }
        $query = $this->db->get();
        $result = $query->result_array();
        if($result){
            return $result[0]['totalResults'];
        }else{
            return 0;
        }
        //return $this->db->count_all($this->_table);
    }

    public function getPagination($record, $start, $name=null){
        $this->db->select('*');
        $this->db->from($this->_table);
        if($name != null){
            $this->db->like('name', $name, 'both');
        }
        $this->db->order_by($this->_table.'.name', 'asc');
        $this->db->limit($record, $start);
        $query = $this->db->get();
        return $query->result_array();
    }

}

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