wecuro_blog/application/modules/groups/models/Groups_permission_model.php

73 lines
2.4 KiB
PHP
Executable File

<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Groups_permission_model extends CI_model {
function __construct() {
parent::__construct();
$this->load->database();
}
function insertGroupPermission($data) {
$this->db->insert('groups_permission', $data);
}
function getGroupsPermission() {
$query = $this->db->get('groups_permission');
return $query->result();
}
function getGroupPermissionById($id) {
$this->db->select('permissions.*');
$this->db->from('permissions');
$this->db->where('permissions.parent_id', 0);
$query = $this->db->get();
$permissions=$query->result();
foreach ($permissions as $p) {
$this->db->select('groups_permission.*');
$this->db->from('groups_permission');
$this->db->where('groups_permission.group_id', $id);
$this->db->where('groups_permission.permission_id', $p->id);
$query1 = $this->db->get();
$permissions1=$query1->row();
if($permissions1)
$p->checked=1;
else
$p->checked=0;
$child_permission=$this->db->get_where('permissions',array('parent_id' => $p->id))->result();
foreach ($child_permission as $cp) {
$this->db->select('groups_permission.*');
$this->db->from('groups_permission');
$this->db->where('groups_permission.group_id', $id);
$this->db->where('groups_permission.permission_id', $cp->id);
$query1 = $this->db->get();
$permissions1=$query1->row();
if($permissions1)
$cp->checked=1;
else
$cp->checked=0;
}
$p->child=$child_permission;
}
return $permissions;
// echo '<pre>';
// print_r($permissions);
// echo '</pre>';
// die;
// $this->db->where('id', $id);
// $query = $this->db->get('groups_permission');
}
function updateGroupPermission($id, $data) {
$this->db->where('id', $id);
$this->db->update('groups_permission', $data);
}
function delete($id) {
$this->db->where('group_id', $id);
$this->db->delete('groups_permission');
}
}