简体   繁体   English

joomla没有显示用户组php的完整地图

[英]joomla not showing full map of user group php

So I have made some custom user groups in Joomla from backend. 因此,我从后端在Joomla中创建了一些自定义用户组。 I put the registered users under these custom groups. 我将注册用户置于这些自定义组下。 Groups are like this- 团体就像这样-

Public 上市
|— Users | —用户
|—|— Auditor | — | —审核员
|—|— Custom_group1 | — | — Custom_group1
|—|—|— Custom_group2 | — | — | — Custom_group2
|—|—|—|— Custom_group3 | — | — || — | — Custom_group3
|—|—|—|—|— Administrator | — | — || — |||| —管理员
|—|—|—|—|—|— Super User | — | — ||||||||| —超级用户
|—|— Custom_group4 | — | — Custom_group4

So, say that user_b is under group Custom_group4 and also under Custom_group3 ,where the ids of custom group 3 and 4 are 2 and 11 respectively(say), The MySql database would look like- 因此,假设user_bCustom_group4Custom_group4 ,也在Custom_group3下,其中自定义组3和4的ID分别为2和11(例如),则MySql数据库看起来像-

Table: #__users 表格:#__个用户

id       name           username           email               password     
523     User A          user_a          user_a@mysite.com      blablabla...
524     User B          user_b          user_b@mysite.com      blablabla... 

Table: #__user_usergroup_map 表格:#__ user_usergroup_map

user_id(Foreign Key to #__users.id)       group_id(Foreign Key to #__usergroups.id)
    523                                       8
    524                                       2
    524                                       11

You can see there are two groups assigned for user id 524. Now I have this PHP code to get the group id for user(user id-524) 您可以看到为用户ID 524分配了两个组。现在,我有了此PHP代码来获取用户的组ID(用户ID-524)

        $user = JFactory::getUser();
        $userId = $user->id;
        $db = JFactory::getDbo();
        $recursive = False;

        // Build the database query to get the rules for the asset.
        $query  = $db->getQuery(true);
        $query->select('ug.group_id');
        $query->from('#__user_usergroup_map AS ug');
        $query->leftJoin('#__users AS a ON a.id = ug.user_id');
        $query->where('a.id = '.(int) $userId);

        // Execute the query and load the rules from the result.
        $db->setQuery($query);
        $result = $db->loadResult();
        print_r((array)$result);

of which, I get the output- 其中,我得到的输出是

Array([0] => 2)

but I want it to be Array([0] => 2, [1]=> 11) 但我希望它是Array([0] => 2, [1]=> 11)

Can anyone help me? 谁能帮我?

Solved. 解决了。

I looked upon and find a similar function here , using the similar query(better as expected). 我查看了一下,并在这里找到了类似的功能,使用了类似的查询(比预期的要好)。

Here is part of that code- 这是该代码的一部分-

        $query  = $db->getQuery(true);
        $query->select($recursive ? 'b.id' : 'a.id');
        $query->from('#__user_usergroup_map AS map');
        $query->where('map.user_id = '.(int) $userId);
        $query->leftJoin('#__usergroups AS a ON a.id = map.group_id');

        // If we want the rules cascading up to the global asset node we need a self-join.
        if ($recursive) {
                $query->leftJoin('#__usergroups AS b ON b.lft <= a.lft AND b.rgt >= a.rgt');
        }

        // Execute the query and load the rules from the result.
        $db->setQuery($query);
        $result = $db->loadResultArray();

The only difference lies in the way of obtaining table information. 唯一的区别在于获取表信息的方式。

I would now simple use this as- 我现在将其简单地用作-

jimport( 'joomla.access.access' );
$groups = JAccess::getGroupsByUser(526, False); //526 is the user_id for user b
print_r($groups);

and this did what I want- 这就是我想要的

Array ( [0] => 2 [1] => 11 )

Thanks google. 谢谢谷歌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM