You are here

function og_vocab_determine_access in OG Vocabulary 6

Access function to determine if a user has access to the menu item.

Parameters

$node: The group node.

$perm: The permission to check is user has.

$id: Optional; The vocabulary ID or object or term ID, to check if belongs to the group node.

$type: Optional; If $id is populated, then this indicates what ID it represents. Allowed values are "vocabulary" or "term". Defaults to "vocabulary".

Return value

TRUE if user has access to the menu item.

1 string reference to 'og_vocab_determine_access'
og_vocab_menu in ./og_vocab.module
Implementation of hook_menu().

File

./og_vocab.module, line 508
Give each group its own system controlled vocabularies.

Code

function og_vocab_determine_access($node, $perm, $id = 0, $type = 'vocabulary') {
  $access = TRUE;
  if ($id) {
    $access = FALSE;
    if ($type == 'vocabulary') {
      $vocab_id = is_object($id) ? $id->vid : $id;
    }
    else {

      // Load the term, to get its vocabulary ID.
      $term = taxonomy_get_term($id);
      $vocab_id = $term->vid;
    }

    // Make sure vocabulary ID belongs to the group node.
    if ($group = og_vocab_get_group($vocab_id)) {
      $access = $node->nid == $group['nid'];
    }
  }
  if ($access) {

    // User with administer organic groups or group admins should have access
    // regardless of permissions. Otherwise check the user is a member with the
    // right permissions.
    $access = og_is_group_admin($node) || og_is_group_member($node->nid) && user_access($perm) || user_access('administer organic groups');
  }
  return $access;
}