0
Hello!
I am developing a panel to create and change user permission using the plugin jstree.
This works well for me once I use a table called treeview
to mount the tree of jstree
and use the table tb_permission
, to determine the user’s permission.
Relating the field name
table treeview
and the countryside function
table tb_permission
, I check the state of the field allowed
table tb_permission
and if it is TRUE
, then the user has permission for such a function, if it is equal to FALSE
, the user does not have permission.
DOUBT
My question arises at the time of displaying the MENU on the sidebar, respecting the permission that the user has.
I tried to add a field in the table tb_permission
, and create the following rule.
First get the field result parent_id
table tb_permission
, whose the type
is equal to 2 and allowed
be equal to TRUE
.
Then for each of the parent_id
, I check how many results I got and if the value is greater than zero, I mark the field visible
as TRUE
.
And the countryside visible
, i would use as parameter to display the MENU on the sidebar in case of TRUE
But in addition to not working, I believe I have other ways to do.
// in test - check only type functions start
$parent = $this->db->select('parent_id')->from('tb_permission')->where('role_id', $role_id)->where('type', 2)->where('allowed', TRUE)->get()->result();
foreach($parent as $key => $item)
{
//$this->db->where('menu_id', $item->parent_id)->where('role_id', $role_id)->update('tb_permission', ['visible' => TRUE]);
$allowed = $this->db->select('*')->from('tb_permission')->where('parent_id', $item->parent_id)->where('role_id', $role_id)->where('type !=', 0)->where('allowed', TRUE)->get()->num_rows();
$visible = $allowed > 0 ? TRUE : '';
if ($visible)
$this->db->where('menu_id', $item->parent_id)->where('type !=', 2)->where('role_id', $role_id)->update('tb_permission', ['visible' => TRUE]);
}
// in test - check only type functions end