News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Enable Display of Multiple Member Groups

Started by rpaveza, November 01, 2004, 03:42:59 PM

Previous topic - Next topic

rpaveza

Hi!

I'd like to enable the display of multiple member groups in threads.  For example, as an Admin, I belong to three other member groups, but only Administrator comes up.  I'd like those to display because they're informative.  :)

dschwab9

You should be able to do that in the template.  Why would an admin need to be in another group?  They should already have access to everything.

rpaveza

Quote from: dschwab9 on November 01, 2004, 04:28:46 PM
You should be able to do that in the template.  Why would an admin need to be in another group?  They should already have access to everything.

Quote from: rpaveza on November 01, 2004, 03:42:59 PM
I'd like those to display because they're informative.  :)

[Unknown]

Additional group information is currently not provided because it is a waste of extra queries.

The purpose has always been for additional groups to be hidden.  By no means does this mean a mod could not, or should not, be made to give this functionality to those who want it.

-[Unknown]

dschwab9

 Aren't the additional groups loaded at the point for the purpose of permissions?

[Unknown]

Quote from: dschwab9 on November 02, 2004, 04:43:45 AM
Aren't the additional groups loaded at the point for the purpose of permissions?

Only the user's (the person currently using the forum) are loaded, not the member being displayed.

Why do I need to know all the permissions for a person just because they replied to my topic?

-[Unknown]

dschwab9

Quote from: [Unknown] on November 02, 2004, 04:46:10 AM
Why do I need to know all the permissions for a person just because they replied to my topic?

I guess you don't.  I'm just brain dead tonight.

goetzi

I need to display multiple groups too. It's a small board, so there shouldn't be any performance problems. I use SMF 1.1 RC1.

I would be happy if anyone could tell me how I could do this.

goetzi

goetzi

I did it by my self now.

I don't know if it is elegant or just very bad, but it is working.

Search for the following code in "Display.template.php"
// Show the member's primary group (like 'Administrator') if they have one.
if (isset($message['member']['group']) && $message['member']['group'] != '')
echo '<strong>
', $message['member']['group'], '</strong><br />';


Add below:
##############################################################
##############################################################

$id = $message['member']['id'];

$sql = "SELECT additionalGroups FROM smf_members WHERE ID_MEMBER=$id LIMIT 1";
$result = db_query($sql);
$row = mysql_fetch_assoc($result);

$groups = explode(',', $row['additionalGroups']);


if ((count($groups)>=1) && ($groups[0]!=""))
{
for($i=0; $i<count($groups); $i++)
{
$groupid = $groups[$i];
$sql = "SELECT groupName FROM smf_membergroups WHERE ID_GROUP=$groupid LIMIT 1";
$result = db_query($sql);
$row = mysql_fetch_assoc($result);
echo '<strong>'.$row['groupName'].'</strong><br />';
}
}

####################################################################
####################################################################

Oldiesmann

#9
It's actually not as complicated as you've made it...

$query1 = db_query("SELECT additionalGroups FROM {$db_prefix}members WHERE ID_MEMBER = '$message[member][id]'", __FILE__, __LINE__);
if(mysql_result($query1, 0))
{
$additionalGroups = explode(',', mysql_result($query1, 0));

foreach($additionalGroups as $a_group)
{
// If we get an empty string, leave.
if($a_group == '')
break 2;

$query2 = db_query("SELECT groupName FROM {$db_prefix}membergroups WHERE ID_GROUP = '$a_group'");
echo '<strong>', mysql_result($query2, 0), '</strong><br />';
}
}


(Note: For more info on the mysql_result function, check out www.php.net/mysql_result.)
Michael Eshom
Christian Metal Fans

Sheepy

You can load groups for all displaying members at Load.php with one query IIRC.  The same way basic member infos are loaded in one batch.  Sorry not at home so can't check my code.

goetzi

Quote from: Sheepy on November 16, 2005, 07:21:27 PM
You can load groups for all displaying members at Load.php with one query IIRC.  The same way basic member infos are loaded in one batch.  Sorry not at home so can't check my code.

Would be interested in this.. Do you have the code?

Sheepy

Yes. Let me see...

First, I'm using SMF 1.0.5, and I just realised I integrated it into loadUserSettings, not loadMemberData, but I think it should works the same.

I basically changed the 'group' of $user_info into an array, so many changes in other places / templates are necessary, for example pm, display, and profile.

Soon after loadMemberData, change the query so it includes mem.additionalGroups.

Then somewhere after that do this on every profile:


<?php
$user_settings = &$user_profile[$id];
if (empty($user_settings['additionalGroups']))
$user_info = array(
'group' => array($user_settings['ID_GROUP'], $user_settings['ID_POST_GROUP'])
);
else
$user_info = array(
'group' => array_merge(
array($user_settings['ID_GROUP'], $user_settings['ID_POST_GROUP']),
explode(','$user_settings['additionalGroups'])
)
);
$user_info['group'] = array_unique($user_info['groups']);
?>


In my forum it goes like below (working code).  It adds a single query to every call to loadMemberData.

<?php
if (empty($board_info['moderators']) || (!$is_name && count(array_intersect($usersarray_keys($board_info['moderators']))) == 0))
      
$cond 'IF (mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP)';
    else
    
$cond 'IF (mem.ID_GROUP IN (1, 2) OR mem.ID_MEMBER IN ('.implode(', 'array_keys($board_info['moderators'])).'), IF (mem.ID_GROUP = 0, 3, mem.ID_GROUP), mem.ID_POST_GROUP)';
    
    
// Load multiple group name, colour & stars
    
$request db_query("
    SELECT mem.ID_MEMBER, mg.groupName, mg.stars, mg.onlineColor
    FROM smf_membergroups AS mg, smf_members AS mem
    WHERE mem.ID_MEMBER " 
. (count($loaded_ids) == '= ' $loaded_ids[0] : 'IN (' implode(', '$loaded_ids) . ')') . ' AND
    ((FIND_IN_SET(mg.ID_GROUP, mem.additionalGroups) AND mg.showAddName=1)
      OR mg.ID_GROUP='
.$cond.')
    '
__FILE____LINE__);

while (list($id$name$star$colour) = mysql_fetch_row($request)) {
  if (!array_key_exists($id$user_profile)) continue;
  $pro = &$user_profile[$id];
  if (!array_key_exists('group'$user_profile[$id])) {
$pro['group'] = array();
   }
  $pro['group'][] = array($name$star$colour);
    }

mysql_free_result($request);

foreach ($user_profile as $user)
  if (!array_key_exists('group'$user))
   $user['group'] = array();
?>

rebelminion

Quote from: [Unknown] on November 02, 2004, 04:46:10 AM
Why do I need to know all the permissions for a person just because they replied to my topic?

In the case of my site, different membergroups do not just indicate access to different forums, it is also an indication that they have been verified with certain credentials - as a que to the visitor that the person giving advice on a certain subject has the license or training in the real world to be considered a good source of advice or information.

R

Advertisement: