jenkins Posted February 10, 2013 Share Posted February 10, 2013 (edited) 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! Edited February 10, 2013 by jenkins Quote Link to comment https://forums.phpfreaks.com/topic/274291-user-permissions-and-dynamic-menu-parent-child-grandchild/ Share on other sites More sharing options...
kicken Posted February 10, 2013 Share Posted February 10, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/274291-user-permissions-and-dynamic-menu-parent-child-grandchild/#findComment-1411530 Share on other sites More sharing options...
jenkins Posted February 10, 2013 Author Share Posted February 10, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/274291-user-permissions-and-dynamic-menu-parent-child-grandchild/#findComment-1411538 Share on other sites More sharing options...
kicken Posted February 10, 2013 Share Posted February 10, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/274291-user-permissions-and-dynamic-menu-parent-child-grandchild/#findComment-1411540 Share on other sites More sharing options...
jenkins Posted February 14, 2013 Author Share Posted February 14, 2013 Hi Kicken, Sorry for the delayed reply. I'll give this a try and see what happens Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/274291-user-permissions-and-dynamic-menu-parent-child-grandchild/#findComment-1412389 Share on other sites More sharing options...
jenkins Posted April 29, 2013 Author Share Posted April 29, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/274291-user-permissions-and-dynamic-menu-parent-child-grandchild/#findComment-1427128 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.