phpBB.com     phpBB Academy     phpBB Modders     phpBB Weekly     ktuk     phpBB Hacks     Vlad Studio  

Group List in Viewtopic

Shows a list of all a users groups under their post details in viewtopic

Not enough for a full proper MOD, but too useful not to share
Forum rules
Please read over our forum guidelines

Group List in Viewtopic

Postby kenny » 19 Oct 2009, 13:41

Carrying on from here, this snippet was requested by nasadows in the same topic. Instead of just showing a posters default group, it lists every group that they are a member of. Only those with permissions to see a group will see it's name in the list, as this snippet make use of the same auth check that is used in the memberlist view profile section.

*CAUTION*
This snippet runs quite an expensive query in viewtopic. I haven't looked into trimming it down, so you may want to try and find a way reduce the load caused by this before installing. If anyone finds a less expensive query, please post it here and I will update this article. Full credit will be given :)

Comment:
#
#-----[ OPEN ]------------------------------------------
#
viewtopic.php
#
#-----[ FIND ]------------------------------------------
#
Code: Select all
    //
    $postrow = array( 

#
#-----[ BEFORE, ADD ]------------------------------------------
#
Code: Select all
    // Stolen from memberlist.php - get a dropdown list of all users groups (checking for auths as well)
    $gsql = 'SELECT g.group_id, g.group_name, g.group_type
        FROM '
 . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug
        WHERE ug.user_id = $poster_id
            AND g.group_id = ug.group_id"
 . ((!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? ' AND g.group_type <> ' . GROUP_HIDDEN : '') . '
            AND ug.user_pending = 0
        ORDER BY g.group_type, g.group_name'
;
    $res = $db->sql_query($gsql);

    $group_list = array();
    while ($grow = $db->sql_fetchrow($res))
    {
        $group_list[]    = ($grow['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $grow['group_name']] : $grow['group_name'];
    }
    $db->sql_freeresult($res);    
    $group_list 
= implode(', ', $group_list); 

#
#-----[ FIND ]------------------------------------------
#
Code: Select all
        'S_IGNORE_POST'            => ($row['hide_post']) ? true : false, 

#
#-----[ BEFORE, ADD ]------------------------------------------
#
Code: Select all
        'S_GROUP_LIST'        => $group_list, 

#
#-----[ OPEN ]------------------------------------------
#
styles/prosilver/template/viewtopic_body.html
#
#-----[ FIND ]------------------------------------------
#
Code: Select all
      <!-- IF postrow.POSTER_FROM --><dd><strong>{L_LOCATION}:</strong> {postrow.POSTER_FROM}</dd><!-- ENDIF -->

#
#-----[ AFTER, ADD ]------------------------------------------
#
Code: Select all
      <!-- IF postrow.S_GROUP_LIST --><dd><strong>{L_GROUPS}:</strong> {postrow.S_GROUP_LIST}</dd><!-- ENDIF -->


Edit: nasadows has come up with a great addition to this snippet - his code will split each group on to a new line, link the group name to the groups page and add the groups color to the text :)
It can be found here - http://www.phpbb.com/community/viewtopi ... #p11033705
A screenshot of the updated code is below

modgrouplistwcolorinvie.jpg
modgrouplistwcolorinvie.jpg (10.59 KiB) Viewed 2474 times
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

Donate to 6 String MODs
If you like any of the work that I do here, please consider donating.
click the image on the left for a list of some of the advantages of donating



Re: Group List in Viewtopic

Postby kenny » 19 Oct 2009, 17:00

Ok, here's another little add-on - this will place a mark next to whichever group is the users default :)

Comment:
#
#-----[ OPEN ]------------------------------------------
#
viewtopic.php
#
#-----[ FIND ]------------------------------------------
#
Code: Select all
        if ($poster_id == ANONYMOUS)
        {  

#
#-----[ FIND ]------------------------------------------
#
Code: Select all
                'user_colour'        => $row['user_colour'],  

#
#-----[ AFTER, ADD ]------------------------------------------
#
Code: Select all
                'group_id'            => '',      

#
#-----[ FIND ]------------------------------------------
# Not a duplicate here, there's an array for guests and an array for registered users ;)
Code: Select all
                'user_colour'        => $row['user_colour'],  

#
#-----[ AFTER, ADD ]------------------------------------------
#
Code: Select all
                'group_id'            => $row['group_id'],      

#
#-----[ FIND ]------------------------------------------
#
Code: Select all
            $group_list[] = ($grow['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $grow['group_name']] : $grow['group_name']; 

#
#-----[ REPLACE WITH ]------------------------------------------
#
Code: Select all
        if ($grow['group_id'] == $user_cache[$poster_id]['group_id'])
        {
            $group_list[] = ($grow['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $grow['group_name']] . '<a title="Default Group">*</a>' : $grow['group_name'] . '<a title="Default Group">*</a>';
        }
        else
        
{
            $group_list[] = ($grow['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $grow['group_name']] : $grow['group_name'];
        } 


To add your own mark in - it can be an image or anything you like, change both instances of this code -
Code: Select all
<a title="Default Group">*</a>
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK




Return to Code Snippets

Who is online

Yahoo [Bot]


cron