[BETA] Show group memberships in memberlist 0.1.0

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment!
Ideas Centre
Locked
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

[BETA] Show group memberships in memberlist 0.1.0

Post by javiexin »

NOTE: This has been turned into a full mod, available for download later in this topic.
Please, disregard this post, and start reading from the post below: http://www.phpbb.com/community/viewtopi ... #p13153342

________________________________________________________________

Hello,

Here is a code snippet to show group memberships of certain groups in the memberlist. Only visible to Admins and Mods (Mods may be removed). General users do not see this. It could be done, but would require significant permission checks for hidden groups.

Membership is shown as ticked/unticked checkboxes below the user name in the memberlist, indicating the membership (or not) of the user in a certain group.

The list of groups shown in the memberlist must be configured (as a list of group_id's separated by comma) as an entry in the phpbb_config table.

This will NOT be developed to a full MOD, as it is a simple enough snippet, and I am currently not considering the ACP configuration that would be required/helpful.

So, here are the instructions:

1) Edit memberlist.php
Find:

Code: Select all

            // Load custom profile fields
            if ($config['load_cpf_memberlist'])
            {
                include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
                $cp = new custom_profile();

                // Grab all profile fields from users in id cache for later use - similar to the poster cache
                $profile_fields_cache = $cp->generate_profile_fields_template('grab', $user_list);
            } 
Add after:

Code: Select all

            // User Memberships by javiexin
            $show_members = ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? true : false; // Admins see group memberships
            $show_members = ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? true : $show_members; // Mods also see group memberships; comment out if you do not want Moderators to see this
            if ($show_members && $config['group_memberships'])
            {
                $group_list = array_map('intval', explode(',', $config['group_memberships']));
                $memberships = $group_names = array();

                $sql = 'SELECT group_id, group_name, group_type
                    FROM ' . GROUPS_TABLE . '
                    WHERE ' . $db->sql_in_set('group_id', $group_list);

                $result = $db->sql_query($sql);
                
                while ($row = $db->sql_fetchrow($result))
                {
                    $group_names[$row['group_id']] = (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']);
                }
                $db->sql_freeresult($result);

                $sql = 'SELECT ug.*
                    FROM ' . USER_GROUP_TABLE . ' ug
                    WHERE ug.user_pending = 0' .
                    ' AND ' . $db->sql_in_set('ug.group_id', $group_list) .
                    ' AND ' . $db->sql_in_set('ug.user_id', $user_list);

                $result = $db->sql_query($sql);

                while ($row = $db->sql_fetchrow($result))
                {
                    $memberships[$row['user_id']][$row['group_id']] = true;
                }
                $db->sql_freeresult($result);
            } 
Then find:

Code: Select all

                if (isset($cp_row['blockrow']) && sizeof($cp_row['blockrow']))
                {
                    foreach ($cp_row['blockrow'] as $field_data)
                    {
                        $template->assign_block_vars('memberrow.custom_fields', $field_data);
                    }
                } 
Add after:

Code: Select all

                // User Memberships by javiexin
                if ($show_members && $config['group_memberships'])
                {
                    foreach ($group_list as $group_id)
                    {
                        if (isset($group_names[$group_id]))
                        {
                            $template->assign_block_vars('memberrow.membership', array(
                                'GROUP_ID'        => $group_id,
                                'GROUP_NAME'    => $group_names[$group_id],
                                'S_IN_GROUP'    => (isset($memberships[$user_id][$group_id]) ? true : false),
                            ));
                        }
                    }
                }
And finally find:

Code: Select all

            'S_SHOW_GROUP'        => ($mode == 'group') ? true : false,
Add after:

Code: Select all

            'S_SHOW_MEMBERSHIPS'    => ($show_members && $config['group_memberships']) ? true : false,
2) Now edit styles/prosilver/template/memberlist_body.html
Find:

Code: Select all

{memberrow.USERNAME_FULL}
Inline add after:

Code: Select all

<!-- IF S_SHOW_MEMBERSHIPS and not S_IN_SEARCH_POPUP and not S_SELECT_SINGLE --><br /><div style="margin-top: 6px;" class="memberships"><!-- BEGIN membership --><input type="checkbox" name="membership-{memberrow.membership.GROUP_ID}" title="{memberrow.membership.GROUP_NAME}" <!-- IF memberrow.membership.S_IN_GROUP -->checked="checked" <!-- ENDIF -->onclick="return false;" style="margin-right: 8px;" /><!-- END membership --></div><!-- ENDIF -->
3) Finally, run the following SQL command (typically, from phpmyadmin):

Code: Select all

INSERT INTO phpbb_config (config_name, config_value, is_dynamic)
VALUES ('group_memberships', '5,8', FALSE);
Note that you should use as the value a list of numbers, separated by comma, that correspond to the GROUP_IDs of the groups you intend to show in the memberlist. That is, you should replace '5,8' with the correct group ids.

4) Clean the ftp cache, remove the file cache/data_global.php from your ftp server

5) Clean the template cache of your style

You are all set...

If you want to change the list of groups to show (or the order of these), just repeat steps 3 and 4 above, using in step 3 the following SQL command instead of the one above:

Code: Select all

UPDATE phpbb_config 
SET config_value = '631,632,228,213,487,257' 
WHERE config_name = 'group_memberships';
Hope this helps someone... I remember someone asking for something like this recently, but I failed to find this request.
Regards,
-javiexin

PS: If someone wants to take over and make it to a full MOD, go ahead, just keep the credits.
PS: Any code improvement is also very welcome.
Last edited by javiexin on Thu Jun 07, 2012 6:17 pm, edited 4 times in total.
User avatar
4_seven
I've Been Banned!
Posts: 5155
Joined: Wed Apr 30, 2008 1:41 am

Re: [DEV] Show group memberships in memberlist

Post by 4_seven »

Thanks for bringing the group_mempership thing to Array, without performance overkill. Long time the most wanted.
Current Mods | Mod Base | php(BB) programming | No help via PM
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: [DEV] Show group memberships in memberlist

Post by javiexin »

You're welcome, 4_seven. I hope this is useful for more people.

Rgds,
-javiexin
User avatar
RMcGirr83
Former Team Member
Posts: 22016
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: [DEV] Show group memberships in memberlist

Post by RMcGirr83 »

Code: Select all

            $show_members = ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? true : false; // Admins see group memberships
            $show_members = ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? true : false; // Mods also see group memberships; comment out if you do not want Moderators to see this
Your $show_members for admins will be overridden by the $show_members for mods. If an admin isn't a moderator then they won't see the list.

Code: Select all

                $sql = 'SELECT ug.*
                    FROM ' . USER_GROUP_TABLE . ' ug
                    WHERE ug.user_pending = 0';

                $sql .= ' AND ' . $db->sql_in_set('ug.group_id', $group_list);
                $sql .= ' AND ' . $db->sql_in_set('ug.user_id', $user_list);
why aren't you just combining all that? You should also have an ACP entry somewhere where the groups can be added/removed without running sql code everytime to do so.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beer Image
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: [DEV] Show group memberships in memberlist

Post by javiexin »

RMcGirr83 wrote:

Code: Select all

 $show_members = ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? true : false; // Admins see group memberships
$show_members = ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? true : false; // Mods also see group memberships; comment out if you do not want Moderators to see this
Your $show_members for admins will be overridden by the $show_members for mods. If an admin isn't a moderator then they won't see the list.
You are right, my bad...
Second line should be:

Code: Select all

$show_members = ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? true : $show_members; // Mods also see group memberships; comment out if you do not want Moderators to see this    
Corrected in first message, to keep it consolidated.
RMcGirr83 wrote:

Code: Select all

 $sql = 'SELECT ug.*
FROM ' . USER_GROUP_TABLE . ' ug
WHERE ug.user_pending = 0';

$sql .= ' AND ' . $db->sql_in_set('ug.group_id', $group_list);
$sql .= ' AND ' . $db->sql_in_set('ug.user_id', $user_list);
why aren't you just combining all that?
Yeah, right again... it is mostly due to the way the code evolved, where it came from. Changed also in first post, although it is also correct as is.
RMcGirr83 wrote:You should also have an ACP entry somewhere where the groups can be added/removed without running sql code everytime to do so.
I know, but...
javiexin wrote:This will NOT be developed to a full MOD, as it is a simple enough snippet, and I am currently not considering the ACP configuration that would be required/helpful.
To make it the "right" way, it should take into consideration multiple permission options, group ordering, group removal, etc. A lot of changes for very sheldom use.
Anyhow:
javiexin wrote:PS: If someone wants to take over and make it to a full MOD, go ahead, just keep the credits.
Or maybe become a co-author...
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: [BETA] Show group memberships in memberlist 0.1.0

Post by javiexin »

Ok, so I finally decided to turn this into a full MOD. I am renaming this as a BETA, with the corresponding download, and full ACP support.

So, here is the MOD basic description.
_____________________________________

Modification Name: Group Membership in Memberlist
Author: javiexin

Modification Description:: Displays Group Memberships in the Memberlist.
Controlled by a new (user global) permission (admins always see this when the MOD is enabled).
ACP module to select what groups to show, and in what order.

Modification Version:: 0.1.0 BETA

Features: These are the main features of the MOD:
  • Shows the membership of each user in certain groups in the memberlist
  • This is shown as checkboxes under the user name in the memberlist; a tooltip shows the group name of each checkbox
  • Visible in the normal view and in the group view of the memberlist
  • MODX installer, with UMIL support
  • ACP module to control enabling/disabling of the MOD
  • Control of what groups, and in what order, are shown in the memberlist; done also from the ACP module
  • Access to main functionality is always available for ADMINS (that have group access permissions)
  • Other users access this functionality controlled by a new (global user) permission that must be configured
  • No user, regardless of permission, is able to see "hidden" groups, unless he/she is a member of that group
Screenshots: N/A

Demo URL: N/A

Modification Download: MOD Download - Group Membership 0.1.0
User avatar
4_seven
I've Been Banned!
Posts: 5155
Joined: Wed Apr 30, 2008 1:41 am

Re: [BETA] Show group memberships in memberlist 0.1.0

Post by 4_seven »

Great. Thanks for the update :geek:
Current Mods | Mod Base | php(BB) programming | No help via PM
Locked

Return to “[3.0.x] MODs in Development”