1
Groover
Getting the group name
  • 2004/7/1 20:56

  • Groover

  • Just popping in

  • Posts: 23

  • Since: 2004/7/1 2


OK, I tried searching for my problem and found a couple of suggestions, but they didn't work. Usually left me with a white screen or drove XOOPS nuts.

I would like to display the user's current group. On my site the users will only belong to one group at a time. Here is my code for a custom block.

global $xoopsUser;

if (!is_object($xoopsUser))
{
echo "

Log in to see your membership status

";
return;
}

//$groups = $xoopsUser->getGroups();
$groups = XoopsGroup::getByUser($xoopsUser, true);

echo "

Your current membership status is: ";
foreach ($groups as $group)
{
echo $group->getVar('name');
}
echo "

";

Now I know that I can use MySQL to put the groupid in and get the name, but in this XOOPS system that doesn't seem the "proper" way of doing things. I would be grateful for any help. Thanks!

Groover

2
tl
Re: Getting the group name
  • 2004/7/1 22:13

  • tl

  • Friend of XOOPS

  • Posts: 999

  • Since: 2002/6/23


Never tried to use it, but this piece of codes in common.php might be helpful

if ($xoopsConfig['closesite'] == 1) {
  
$allowed false;
    if (
is_object($xoopsUser)) {
[
color=d84848]foreach ($xoopsUser->getGroups() as $group)[/color] {
    if (
in_array($group$xoopsConfig['closesite_okgrp'])
 || 
XOOPS_GROUP_ADMIN == $group) {
    
$allowed true;
    break;
    }
   }
... ...

3
Dave_L
Re: Getting the group name
  • 2004/7/1 23:04

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Mithrandir and I recently had a discussion about this. XoopsUser::getGroups returns an array of group IDs. Since you want the group names, you would need to get an array of group objects, and then get the names using an object method:


$member_handler =& xoops_gethandler('member');
$groups $member_handler->getGroupsByUser($xoopsUser->getVar('uid'),[color=ff0000]true[/color]);
echo 
'You are in the following groups:';
foreach (
$groups as $group) {
   echo 
$group->getVar('name') . '';
}


Note the second parameter (asobject) to XoopsMemberHandler::getGroupsByUser. That parameter has to be specified as true to get an array of objects. XoopsUser::getGroups calls XoopsMemberHandler::getGroupsByUser with the second parameter omitted, and that parameter defaults to false, which is why XoopsUser::getGroups returns an array of IDs, not objects.

4
Groover
Re: Getting the group name
  • 2004/7/2 16:12

  • Groover

  • Just popping in

  • Posts: 23

  • Since: 2004/7/1 2


Thanks for the replies tl and Dave_L!

Dave_L - that works perfectly! Thanks!

Groover

Login

Who's Online

239 user(s) are online (58 user(s) are browsing Support Forums)


Members: 0


Guests: 239


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Sep 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits