Jump to content

Recommended Posts

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!

post-138495-0-73450100-1360501330_thumb.png

Edited by jenkins

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

 

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.

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.

 

  • 2 months later...

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.

 

 

post-138495-0-44106600-1367250973_thumb.png

post-138495-0-54598300-1367251368_thumb.png

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.