Since comment permissions are different than group permissions, many times the user may not be aware they are not member of a public group since they can comment on a page fine. I would like to add a line just before the comment tetx box " You are not currently member of this group, click here to join this group" to encourage user to joing the group.

any theme or block snippet that can be used for this purpose?

Comments

druojajay’s picture

subscribe

druojajay’s picture

Found it, by chance, while looking at this discussion.

$current_group = $node->nid;
global $user;

if ($user->og_groups[$current_group]['nid'] == $current_group) {  //if user is member of current group
      print 'I am a member!';
} else {
      print 'I am not a member';
}
ajayg’s picture

Tried this but did not help. I created a new custom content panel. Then cut and paste above code. It somehow always shows "I am a member" all the time even if I log out and visit as anonymous user.

garyh’s picture

Hi,

I achieved this by writing a db query...

<?php

global $user;
$currentGroup = og_get_group_context(); 
$nid = $currentGroup->nid;


$is_active = db_result(db_query('SELECT is_active FROM og_uid WHERE uid = %d AND nid = %d', $user->uid, $nid));

if ($is_active==1){
print "a member of this group";
}

else{
print "not a member of this group";
}

?>

lias’s picture

Using the code submitted in #4 is there a way to instead hide the "add comment" link from non-group users? That would eliminate the need for the "not a member of this group."

aangel’s picture

In answer to #5, I had to made two modifications in my Drupal 5 site.

First, I implemented form_alter like this:

function mymodule_link_alter(&$node, &$links) {
  if (isset($node->type)) {
    switch ($node->type) {
        case 'group_post':
                  
        // remove the link if user is not member of group  
        if ( (array_key_exists('comment_add', $links)) && (!mymodule_is_user_group_member($user->uid))) {
          unset($links['comment_add']);
        }
        break;
    }
  }

mymodule_is_user_group_member() performs the test described in #4.

But there are links in the comments that have to be removed, too. So I implemented theme_links() in template.php and put this code just before the foreach:

    // Remove links if the user does not have rights to this group.
    if (!mymodule_is_user_group_member($user->uid)) {
        unset($links['comment_reply']);
        unset($links['comment_edit']);
        unset($links['comment_delete']);
        unset($links['flag_content_add']);
    }    
ajayg’s picture

About #4. I am questioning do we need #4 since that information should be already elsewhere and the solution needs one extra query for each page view.
Before the page is even shown og_node_acess (or similar function) already checks if the user is part of the group and whether he/she has permission to see the page. So that information (is member or not) must be available somewhere which we can reuse.

SeanBannister’s picture

I'm using #2 in a block to display content if the user is a member of the group. To do this you need to first define $node as the block has no concept of the current node:

if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2) ) {
  $node = node_load(arg(1));
}

$current_group = $node->nid;
global $user;

if ($user->og_groups[$current_group]['nid'] == $current_group) {  //if user is member of current group
  print 'I am a member!';
} else {
  print 'I am not a member';
}