You are here

function og_menu_access in Organic Groups Menu (OG Menu) 7.3

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.2 og_menu.module \og_menu_access()

Access function.

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

File

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

Code

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

  // Make sure that gid is id of an organic group.
  if (!og_is_group($group_type, $gid)) {
    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
      ->condition('ogm.gid', $gid, '=');
    $query
      ->condition('ogm.menu_name', $menu['menu_name'], '=');
    $query
      ->condition('ogm.group_type', $group_type, '=');
    $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_entity('administer og menu', $group_type, $gid)) {
    if ($op == 'new-menu') {
      $query = db_select('og_menu', 'ogm');
      $query
        ->condition('ogm.gid', $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;
}