You are here

function shoutbox_group_group_access in Shoutbox 7.2

Same name and namespace in other branches
  1. 6.2 shoutbox_group/shoutbox_group.module \shoutbox_group_group_access()
  2. 7 shoutbox_group/shoutbox_group.module \shoutbox_group_group_access()

Determine if current user can view the current group

Parameters

$op: The operation which access is checked on (View, Post)

$group: The group node

$user: Optionally specify the user, or user ID

Return value

Whether or not the user has access to the given group operation

1 call to shoutbox_group_group_access()
_shoutbox_group_alter_form in shoutbox_group/shoutbox_group.module
Alter the shoutbox add form Add the group ID to the shout form (if one)
1 string reference to 'shoutbox_group_group_access'
shoutbox_group_menu in shoutbox_group/shoutbox_group.module
Implementation of hook_menu().

File

shoutbox_group/shoutbox_group.module, line 274

Code

function shoutbox_group_group_access($op, $group, $user = NULL) {

  // Make sure the group is a group

  //$nid=isset($group->etid) ? $group->etid : $group->gid;

  //$nid = $group['gid'];

  //$node=node_load($nid);
  if (is_array($group)) {
    $node = node_load($group['gid']);
  }
  else {
    $node = $group;
  }
  if (!og_is_group_type('node', $node->type)) {
    return FALSE;
  }

  // If high access, just return
  if (user_access('administer shoutbox_group')) {
    return TRUE;
  }

  // Load the user
  if (!$user) {
    global $user;
  }
  else {
    if (is_numeric($user)) {
      $user = user_load($user);
    }
  }

  // Check the operation specified
  switch ($op) {
    case 'view':

      // Determine node view access
      return node_access('view', $group, $user);
    case 'post':

      // First check higher access
      if (user_access('post shouts in all groups')) {
        return TRUE;
      }

      // Determine group membership
      return og_is_member('group', $group->gid);
    default:
      return FALSE;
  }
}