You are here

function groupmenu_access in Group Menu 7

Access function.

1 string reference to 'groupmenu_access'
groupmenu_menu in ./groupmenu.module
Implements hook_menu().

File

./groupmenu.module, line 600
Integrates menu with Group.

Code

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

  // Make sure that menu, is an groupmenu-menu and belongs to the given group.
  if ($menu) {
    $query = db_select('group_menu', 'gm');
    $query
      ->condition('gm.gid', $gid, '=');
    $query
      ->condition('gm.menu_name', $menu['menu_name'], '=');
    $count = $query
      ->countQuery()
      ->execute()
      ->fetchField();
    if (!$count) {
      return FALSE;
    }

    // Make sure, that menu-item is an item of the groupmenu-menu.
    if ($menu_item && $menu['menu_name'] != $menu_item['menu_name']) {
      return FALSE;
    }
  }
  $group = group_load($gid);
  if (empty($group)) {
    return FALSE;
  }
  if (user_access('administer menu')) {
    return TRUE;
  }
  elseif (group_access('administer group menu', $group)) {
    if ($op == 'new-menu') {
      $query = db_select('group_menu', 'gm');
      $query
        ->condition('gm.gid', $gid, '=');
      $count = $query
        ->countQuery()
        ->execute()
        ->fetchField();
      $max = variable_get('groupmenu_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;
}