问题
In Joomla 2.5.16:
- Suppose user 100 belongs to user groups 14 and 16.
- Suppose that the page he's currently viewing has an access level id of 6.
- According to the table 'viewlevels' in the MySQL database, access level 6 is available for groups 8, 16 and 17
My goal is to find the "right" user group for this page. Since the user belongs to 2 user groups and one of them (16) is contained in the array of groups allowed to see this page, how can I query the database to find that group?
I tried:
$usr_id=100;
$access=6;
$query(SELECT rules from 'viewlevels' WHERE ???);
Table viewlevels has a structure like:
ID | rules
6 |[8,16,17]
Table user_usergroup_map has a structure like:
User_id |Group_id
100 |14
100 |16
Any help, please?
回答1:
SELECT * FROM `#__viewlevels` AS `a`
INNER JOIN `#__usergroups` AS `b`
ON `a`.`rules` LIKE CONCAT('%',b.id,'%')
INNER JOIN `#__user_usergroup_map` AS `m`
ON m.group_id=b.id
WHERE m.user_id = 100
来源:https://stackoverflow.com/questions/19894230/joomla-get-the-user-group-from-the-page-access-level-using-php