Joomla: get the user group from the page access level using PHP

a 夏天 提交于 2020-01-16 18:31:21

问题


In Joomla 2.5.16:

  1. Suppose user 100 belongs to user groups 14 and 16.
  2. Suppose that the page he's currently viewing has an access level id of 6.
  3. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!