Greetings,

I have 6 groups I've setup. Some content in the site is specific to certain groups. I have a menu that shows up on a block only when a user is logged in. What I desire to put in this menu is items based on their group membership. This is a hand-written menu at the moment, since I don't know how to do this programmatically.

I want to do something rather simple (to my thinking), but am array-handling challenged and need some help.

So, I can see my group info by entering this command:

global $user;
print_r($user->og_groups);

Here's the output:
Array ( [284] => Array ( [title] => Coaches [type] => og [status] => 1 [nid] => 284 [og_role] => 0 [is_active] => 1 [is_admin] => 1 [uid] => 1 [mail_type] => [created] => 1168499797 [changed] => 1168502183 ) [285] => Array ( [title] => Employees [type] => og [status] => 1 [nid] => 285 [og_role] => 0 [is_active] => 1 [is_admin] => 1 [uid] => 1 [mail_type] => [created] => 1168499934 [changed] => 1168507203 ) [286] => Array ( [title] => Level 1 [type] => og [status] => 1 [nid] => 286 [og_role] => 0 [is_active] => 1 [is_admin] => 1 [uid] => 1 [mail_type] => [created] => 1168506126 [changed] => 1168507257 ) [288] => Array ( [title] => Level 2 [type] => og [status] => 1 [nid] => 288 [og_role] => 0 [is_active] => 1 [is_admin] => 1 [uid] => 1 [mail_type] => [created] => 1168507030 [changed] => 1168507223 ) [287] => Array ( [title] => Level 3 [type] => og [status] => 1 [nid] => 287 [og_role] => 0 [is_active] => 1 [is_admin] => 1 [uid] => 1 [mail_type] => [created] => 1168506194 [changed] => 1168507239 ) [281] => Array ( [title] => Registered [type] => og [status] => 1 [nid] => 281 [og_role] => 0 [is_active] => 1 [is_admin] => 1 [uid] => 1 [mail_type] => [created] => 1168499313 [changed] => 1168502078 ) [282] => Array ( [title] => Success Strategies Curriculum [type] => og [status] => 1 [nid] => 282 [og_role] => 0 [is_active] => 1 [is_admin] => 1 [uid] => 1 [mail_type] => [created] => 1168499517 [changed] => 1168502119 ) )

I'm trying to write an conditional statement that checks each group that the user belongs to and then check the title within that array against some given string like 'Level', and if it matches, then show the menu item, else don't show it.

I took this post http://drupal.org/node/77414 as inspiration, but, like I said, I'm array-challenged and don't know how to extend it for this purpose I have.

Your help will be appreciated. I'd imagine this kind of thing would be useful for many other people, but haven't found info on it.

Thanks.

Comments

spjsche’s picture

You want to use the OG Block Visibility module for that, I use it, and it works a treat.

skhatri’s picture

hi, I tried that. There are 2 problems with OG block:
1) When I tell the block to only show for a certain group, then, unless I'm in content belonging to that group, i don't see the block. I want the menu items to be visible through the site, as long as you're a member of a particular group (especially the home page).
2) My blocks are hierarchical - for example - level 1 group access includes registered group access plus some more. level 2 group access includes level 2 group access plus some more Therefore, for someone belonging to level 2 group, they' see 3 og blocks - 1 for level 2, 1 for level 1, and 1 for registered groups. Not desirable.

Thanks for the fast response spjsche.

Unless I'm not using it right, of course.
Shahnawaz Khatri, owner
Internet Marketing 4 Real Estate

bpocanada’s picture

global $user;            // get globally defined user
$string = 'Level';           // define string for search in grop
$url = 'http://drupal.org';          // put menu link url here

if( $user->uid ) {            // check for user
 if( $user->og_groups ) {         // check user has group
    foreach( $user->og_groups as $gid => $group ) {  // loop through all
user group
    if( strstr($group['title'], $string ) ) {   // search for string in
group title
   // show menu item
   echo l('Level' , $url);       // show some menu to this user only

    }
    }
 }
}

--
Roshan Shah
T : 604-630-4292
Vancouver, Canada
http://www.drupaldesigns.com - Drupal Portfolio

skhatri’s picture

Thank you very much. This was a great help.

Shahnawaz Khatri, owner
Internet Marketing 4 Real Estate