Jump to content


Photo

User Permissions and Dynamic Menu (parent, child, grandchild)

dynamic menu parent child grandchild user permissions

  • Please log in to reply
5 replies to this topic

#1 jenkins

jenkins

    Member

  • Members
  • PipPip
  • 26 posts

Posted 10 February 2013 - 08:09 AM

Hello,

I am using the following Menu Manager http://codecanyon.ne...r-system/637633 to create a dynamic menu for an application.
The menu contains a parent, child and grandchild (or parents, children, grandchildren)

Here is an example:

Home
User Profile
WLM
| --> Faculty Dashboard
        | --> Dashboard Settings
        | --> Send Faculty Email
|
| --> Exam Schedule
        | --> Add/Edit Exam Time
        | --> View Exam Schedule

When the user logs in to the application, I would like a specific menu to be displayed depending on the user's role/group (Admin gets all menu items and has full access).

I have researched various ways to get the user's permissions (sessions, arrays, query the DB each time the user clicks a page, etc.) but I want to avoid unnecessary overhead but allow users to see their menus (and not be able to access other pages).

For example, let's say I have a user who has the role of "Leader" and I want to give the user/role/group access to the following page only: WLM --> Faculty Dashboard --> Send Faculty Email (as shown above).

I was thinking of several DB tables (User, Group/Role, Resources/Pages, Permissions), however, how would I go about getting only the specific menu items for the user/group?

The challenge is the Menu Manager stores the menu items (parent, child, grandchild) in one database table (please see the attached screenshot).

Is there a way to easily go through the table for this? OR should I not use the menu manager and try a different approach?

Any help/feedback would be greatly appreciated.

Thank you!

Attached Files


Edited by jenkins, 10 February 2013 - 08:12 AM.


#2 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,569 posts
  • LocationBonita, FL

Posted 10 February 2013 - 10:36 AM

Have a table that associates the menu id's with the users (or groups) then just join to the menu table using that ID to pull the menu data.  Eg:
users:
  UserID  |  Username    |  GroupID
--------------------------------------
    1     |  Blah        |     1
    2     |  Flarg       |     2

groups:
  GroupID    |  Groupname
----------------------------
    1        |    Admins
    2        |    Users

group_menu_items:
   GroupId   |  MenuID 
--------------------------
      1      |    1
      1      |    4
      2      |    2
      2      |    3
      1      |    6

menu:
  MenuID    |    Name
----------------------
    1       |    Manage Users
    2       |    Profile
    3       |    Invite
    4       |    Mass Email
    6       |    Bans

SELECT
	m.Name
FROM users u
INNER JOIN groups g ON u.GroupId=g.GroupId
INNER JOIN group_menu_items gm ON gm.GroupId=g.GroupId 
INNER JOIN menu m ON gm.MenuId=m.MenuId
WHERE
	u.UserId=1

Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#3 jenkins

jenkins

    Member

  • Members
  • PipPip
  • 26 posts

Posted 10 February 2013 - 11:00 AM

Hi Gurus,
Thanks for your reply.
Based on your suggestion, if the user is part of a group that has permission to view a grandchild menu item, how can I display the parent in the main menu, then the child in the sub-menu and finally the grandchild (as a sub-menu of the child)?
Thanks again.

#4 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,569 posts
  • LocationBonita, FL

Posted 10 February 2013 - 11:17 AM

Since the menu uses the nested set model it's relatively easy to query for the parents of a menu item.

Something like this would probably do:
SELECT
	m.MenuId, m.Name, p.MenuId, p.Name
FROM users u
INNER JOIN groups g ON u.GroupId=g.GroupId
INNER JOIN group_menu_items gm ON gm.GroupId=g.GroupId 
INNER JOIN menu m ON gm.MenuId=m.MenuId
LEFT JOIN menu p ON m.lft BETWEEN p.lft AND p.rgt
WHERE
	u.UserId=1

You'd probably need to do a little processing of the results within PHP to get them in whatever format the menu system's render function needs.

Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#5 jenkins

jenkins

    Member

  • Members
  • PipPip
  • 26 posts

Posted 14 February 2013 - 02:52 AM

Hi Kicken,
Sorry for the delayed reply.
I'll give this a try and see what happens :)
Thanks for your help!

#6 jenkins

jenkins

    Member

  • Members
  • PipPip
  • 26 posts

Posted 29 April 2013 - 11:05 AM

Hi again,

I'm not sure if it is acceptable to return to this previous post or start a new one.  

I have since changed my approach for the dynamic menu than the one noted above.

The current menu system works better for me in regards to creating menu items. 

However, assigning page permissions to a role is challenging.  I have a page that displays the hierarchy tree and on clicking a submenu item I would like to have the parent automatically checked. 

Since the submenus can go deep several levels I think I need a recursive function to accomplish this. I would also like to do this using jQuery/ajax.

And yet another challenge is when I edit the permissions for a role - if permissions have been previously set, I would like to have those check boxes populated.

Permissions for each role will be saved in a dbTable.  

I have attached some screenshots of the menu and the dbTable of the menu items.

Any advice on how to go about this?  Any sample code? 

Thanks! Much appreciated.

 

 

Attached Files






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com