You are here

function og_menu_access in Organic Groups Menu (OG Menu) 7.2

Same name and namespace in other branches
  1. 6.2 og_menu.module \og_menu_access()
  2. 6 og_menu.module \og_menu_access()
  3. 7.3 og_menu.module \og_menu_access()

Access function.

Parameters

node: The group node for which the menu is edited.

menu: The edited menu.

1 string reference to 'og_menu_access'
og_menu_menu in ./og_menu.module
Implementation of hook_menu().

File

./og_menu.module, line 769
Integrates Menu with Organic Groups. Lots of menu forms duplication in OG context.

Code

function og_menu_access($node, $menu = NULL, $op = NULL, $menu_item = NULL) {

  // Make sure that node is an organic group.
  if (!$node) {
    return FALSE;
  }
  elseif (!og_is_group_type('node', $node->type)) {
    return FALSE;
  }

  // Make sure that menu, is an og_menu-menu and belongs to the given group
  // of given group type.
  if ($menu) {
    $query = db_select('og_menu', 'ogm');
    $query
      ->join('og', 'og', 'ogm.gid = og.gid');
    $query
      ->condition('og.etid', $node->nid, '=');
    $query
      ->condition('ogm.menu_name', $menu['menu_name'], '=');
    $count = $query
      ->countQuery()
      ->execute()
      ->fetchField();
    if (!$count) {
      return FALSE;
    }

    // Make sure, that menu-item is an item of the og_menu-menu.
    if ($menu_item && $menu['menu_name'] != $menu_item['menu_name']) {
      return FALSE;
    }
  }
  if (user_access('administer menu')) {
    return TRUE;
  }
  elseif (user_access('administer og menu') || og_user_access_by_entity('administer og menu', 'node', $node->nid)) {
    if ($op == 'new-menu') {
      $group = og_get_group('node', $node->nid, FALSE, array(
        OG_STATE_ACTIVE,
        OG_STATE_PENDING,
      ));
      $query = db_select('og_menu', 'ogm');
      $query
        ->condition('ogm.gid', $group->gid, '=');
      $count = $query
        ->countQuery()
        ->execute()
        ->fetchField();
      $max = variable_get('og_menu_max_menus_per_group', 1);
      if ($max > 0 && $count >= $max) {
        return FALSE;
      }
      else {
        return TRUE;
      }
    }
    else {

      // return true for all other cases edit menu, add/edit links
      return TRUE;
    }
  }
  return FALSE;
}