0
votes

I'm writing a Joomla 3.x component and I search now the possibility to get from a user (which is assigned to multiple user groups) the 'ID' from the user group with the 'highest level'.

Example: - user is a member from registered and manager and some other groups.

I can get in a first step the ID from 'all' assigned user groups:

jimport( 'joomla.access.access' );
$groups = JAccess::getGroupsByUser($user->id);

But how can i get now the 'id' from the user group with the 'highest' level? I can not found a method for this in the core files.

Edit: I have in my component added a backend part where it is possible to define many special settings for every user group. But i have not an idea how i can get then in the frontend the correct settings, when a user is a member in multiple groups. I need in this case not any 'permissions' from the Joomla assets table. Only the 'ID' from the 'most important' group. It is useful to check then the 'parent' ID from every group? Or use getGroupPath($groupId)?

1
That's not how the ACL really works… it more about permissions, i.e. what the user can do… As this question is about Joomla specific implementation details, I would try asking on the Joomla Q&A StackExhange site - Craig
There is no such thing as highest unless you require that there be a strictly hierarchical structure of some kind. Someone can have delete permission on category x but not edit permission on category y. Even delete and edit are considered orthogonal meaning it is possible to give a group only delete and not edit. - Elin
Humph. I have in my component added a backend part where it is possible to define many special settings for every user group. But i have not an idea how i can get then in the frontend the correct settings, when a user is a member in multiple groups. Okay, it seems easy for default groups, but not when it exist some other (new created) groups. - mikael
I need in this case not any permissions from the Joomla users or assets table. Only the ID from the 'most important' group. It is useful to check then the 'parent' ID from every group? Or use getGroupPath($groupId)? - mikael
Look at how the core components manage this, the API is pretty straightforward. The api just lets you give it a user id and an asset and say can this user .... (edit, delete, edit.state and so on). - Elin

1 Answers

0
votes

Since $groups is an array: $highestLevel = max($groups); should do the trick!