[support] How can I tell if a user if a user is a member of an OG group?

Earnie Boyd earnie at users.sourceforge.net
Tue May 27 12:53:06 UTC 2008


Quoting "Neil: esl-lounge.com" <neil at esl-lounge.com>:

> Hmm, it doesn't seem to exist. When I print out $user, this is what I see on
> a group node I'm a member of:
>
> [og_groups] => Array ( [217] => Array ( [title] => Test Group 1 [type] =>
> group [status] => 1 [nid] => 217 [og_role] => 0 [is_active] => 1 [is_admin]
> => 1 [uid] => 2 [mail_type] => [created] => 1210943771 [changed] =>
> 1211236434 ) [229] => Array ( [title] => Test Group 2 [type] => group
> [status] => 1 [nid] => 229 [og_role] => 0 [is_active] => 1 [is_admin] => 1
> [uid] => 2 [mail_type] => [created] => 1211457708 [changed] =>
> 1211457721 ) )
>
> so the is_active part of that array seems important. I could use the
> $node->nid (217) to access this info. Does that sound possible? It's a
> nested array (217 inside og_groups). So the code I would need would be: if
> is_active equals 1 inside 217 inside og_groups. More or less?? :-)

Since $user->og_groups already has all you need then just use that.  
The key to the OG table appears to be the nid so you would use 
$user->og_groups[$group]['is_active'] in the condition clause.  You'll 
have to determine what variable to use for $group, I'm out-of-office 
and I'm in development mode enough to look.

>
> Neil
>
> ----- Original Message -----
> From: "Earnie Boyd" <earnie at users.sourceforge.net>
> To: <support at drupal.org>
> Sent: Monday, May 26, 2008 5:22 PM
> Subject: Re: [support] How can I tell if a user if a user is a member ofan
> OG group?
>
>
>> Quoting "Neil: esl-lounge.com" <neil at esl-lounge.com>:
>>
>>> I would like to show a link on a group node if a user is a member and
>>> another link if they are not. I looked through og.module and found
>>> the $subscription variable. I tried both the following without any
>>> success:
>>>
>>> <?php if($subscription == 'active') : ?>
>>> already a member!
>>> <?php else: ?>
>>> Join Today!
>>> <?php endif; ?>
>>>
>>> <?php if($subscription) : ?>
>>> already a member!
>>> <?php else: ?>
>>> Join Today!
>>> <?php endif; ?>
>>>
>>> But I'm getting "Join Today" showing whether the user is a member or
>>> not. I imagine this means the $subscription variable isn't available
>>> in this context.
>>>
>>> does anyone know how to find out if a user is a member of an OG group?
>>>
>>
>> I'm guessing you need a global $subscription; added to the code.
>>
>> Earnie -- http://for-my-kids.com/
>> -- http://give-me-an-offer.com/
>>
>> --
>> [ Drupal support list | http://lists.drupal.org/ ]
>>
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>


Earnie -- http://for-my-kids.com/
-- http://give-me-an-offer.com/



More information about the support mailing list