shopifine /magehelp/application/models/acl/role.php

Language PHP Lines 252
MD5 Hash 4105b635811ff9355f6e3b4954cad611 Estimated Cost $4,359 (why?)
Repository https://bitbucket.org/jit_bec/shopifine.git View Raw File View Project SPDX
  1
  2
  3
  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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of role
 *
 * @author abhijit
 */

class Role extends CI_Model {	
	
        function insert($role_data,$parents = array())
	{
            //$this->db->insert('invoice',$invoice_data);
            //return $this->db->insert('roles',$role_data);
            $this->db->trans_start();
            $this->db->insert('acl_roles',$role_data);
            $id = $this->db->insert_id();
            if (!empty($parents)){
                foreach ($parents as $parent){
                    $parent_name = $this->getName($parent);
                    if (!empty($parent_name)){
                        $role_inherit_data = array('role_id'=>$id,'role_name'=>$role_data['role_name'],
                            'parent_role_id'=>$parent,'parent_role_name'=>$parent_name);
                        $this->db->insert('acl_role_inheritance_mapping',$role_inherit_data);
                    }
                }
            }
            $this->db->trans_complete();
            if ($this->db->trans_status() === FALSE)
            {
                //echo $this->db->_error_message();
                die( 'Shipping  Failed.Please check log ');
            }
            else {
                $success = true;
            }
	}
        
        
        function totalNoOfRoles () {
            
            $this->db->from('acl_roles');
            return $this->db->count_all_results() ;
            
            
        }
        
        function getAllParentsMapping($csv = false,$whereClause=null,$order_limit_clause=array(),$like_fields_array=null,$or_where_clause_array=null){
            $orderBy = 'id';
            $orderDir= 'desc';
            $startLimit = 0;
            $limit = 1000;
            
            if (!empty($order_limit_clause['orderBy'])){
                $orderBy = $order_limit_clause['orderBy'];
            }
            if (!empty($order_limit_clause['orderDir'])){
                $orderDir = $order_limit_clause['orderDir'];
            }
            if (!empty($order_limit_clause['startLimit'])){
                $startLimit = $order_limit_clause['startLimit'];
            }
            if (!empty($order_limit_clause['limit'])){
                $limit = $order_limit_clause['limit'];
            }
        
            $this->load->dbutil();  
            $this->db->select('*');
            if (!empty($whereClause)){
                $this->db->where($whereClause);
            }
            
            if (!empty($or_where_clause_array)){
                $this->db->or_where($or_where_clause_array);
            }
            
            if (!empty($like_fields_array)){
                $this->db->like($like_fields_array);
            }
            $this->db->order_by($orderBy,$orderDir);
            $this->db->limit($limit,$startLimit);
            $query = $this->db->get('acl_role_inheritance_mapping');
            
            if ($csv){
                return $this->dbutil->csv_from_result($query);
            }
            return $query->result_array();
        }
        
        function totalNoOfRowsInParentMapping ($where_clause_array=null,$like_fields_array=null,$or_where_clause_array=null) {
            if (!empty($where_clause_array)){
                $this->db->where($where_clause_array);
            }
            
            if (!empty($or_where_clause_array)){
                $this->db->or_where($or_where_clause_array);
            }
            
            if (!empty($like_fields_array)){
                $this->db->like($like_fields_array);
            }
            
            $this->db->from('acl_role_inheritance_mapping');
            return $this->db->count_all_results() ;
            
            
        }
        function getAll(){
            $this->db->select('*');
            $query = $this->db->get('acl_roles');
            return $query->result_array();
        }
        
	
        function getAllParents($id){
            $this->db->select('parent_role_name');
            $this->db->where('role_id',$id);
            $this->db->order_by('relative_order_parent','asc');
            $query = $this->db->get('acl_role_inheritance_mapping');
            //log_message('debug','parent roles '.$this->db->last_query());
            return $query->result_array();
        }
        
        function getId($role_name){
            $this->db->select('id');
            $this->db->where('role_name',$role_name);
            $query = $this->db->get('acl_roles');
            if ($query->num_rows() > 0)
            {
                $row = $query->row_array(); 

                return  $row['id'];
            
            } 
            return null;
        }
        
        function getName($id){
            $this->db->select('role_name');
            $this->db->where('id',$id);
            $query = $this->db->get('acl_roles');
            if ($query->num_rows() > 0)
            {
                $row = $query->row_array(); 

                return  $row['role_name'];
            
            } 
            return null;
        }
        
        function parentExists($roleid,$parentroleid) {
            
            $this->db->from('acl_role_inheritance_mapping');
            $this->db->where('role_id',$roleid);
            $this->db->where('parent_role_id',$parentroleid);
            
            
            $query = $this->db->get();
            return ($query->num_rows()==1);
            
        }
        
        function parentExistsById($id) {
            
            $this->db->from('acl_role_inheritance_mapping');
            $this->db->where('id',$id);
            
            
            $query = $this->db->get();
            return ($query->num_rows()==1);
            
        }
        
        function roleExists($id) {
            
            $this->db->from('acl_roles');
            $this->db->where('id',$id);
            
            
            $query = $this->db->get();
            return ($query->num_rows()==1);
            
        }
        
        function saveParent($parent_data,$id=false){
            $success=false;
            //Run these queries as a transaction, we want to make sure we do all or nothing
            if (!empty($parent_data)){
                try {
                    if (!$id or !$this->parentExistsById($id)){
                        $success = $this->db->insert('acl_role_inheritance_mapping',$parent_data);
                    }
                    else{

                        $this->db->where('id', $id);
                        $success = $this->db->update('acl_role_inheritance_mapping',$parent_data);

                    }
                    if ($success){
                        log_message('debug','Parent Role Suceesfully Modified');
                    }
                }
                catch (Exception $e){
                    log_message('Parent Role Creation Failed '.$this->db->_error_message() );
                    throw new Exception('Parent Role Creation Failed' );
                }
                
            }
            
            
            return $success;
        }
        
        function save($role_data,$id=false){
            $success=false;
            //Run these queries as a transaction, we want to make sure we do all or nothing
            if (!empty($role_data)){
                try {
                    if (!$id or !$this->roleExists($id)){
                        $success = $this->db->insert('acl_roles',$role_data);
                    }
                    else{

                        $this->db->where('id', $id);
                        $success = $this->db->update('acl_roles',$role_data);

                    }
                    if ($success){
                        log_message('debug','Role Suceesfully Modified');
                    }
                }
                catch (Exception $e){
                    log_message('Parent Role Creation Failed '.$this->db->_error_message() );
                    throw new Exception('Parent Role Creation Failed' );
                }
                
            }
            
            
            return $success;
        }
	
}

?>
Back to Top