You are here

function spaces_dashboard_group_dashboard in Spaces 5

Same name and namespace in other branches
  1. 5.2 spaces_dashboard/spaces_dashboard.module \spaces_dashboard_group_dashboard()

Implements a group dashboard for users in multiple groups TODO: implement "fires" listing

1 string reference to 'spaces_dashboard_group_dashboard'
spaces_dashboard_menu in spaces_dashboard/spaces_dashboard.module

File

spaces_dashboard/spaces_dashboard.module, line 136

Code

function spaces_dashboard_group_dashboard() {
  global $user;
  if ($gid = spaces_gid()) {
    drupal_goto(spaces_group_path($gid));
  }
  else {
    if ($user->uid != 0) {

      // User is a member of many groups, show the dashboard.
      if (count($user->og_groups)) {
        return views_build_view('page', views_get_view('spaces_group_dashboard'), null, true, 25);
      }
      else {

        // Set the context as if the view were built
        context_ui_set('views', 'spaces_group_dashboard');

        // Check whether any 'joinable' groups exist
        $group_count = db_result(db_query("SELECT count(n.nid) FROM {node} n JOIN {og} og ON n.nid = og.nid WHERE n.status = 1 AND og.selective = 0"));

        // There are groups to join
        if ($group_count) {
          $message = t("You are currently not a member of any groups. You can browse the group directory and join groups that interest you.");
          $buttons = l(t('Group Directory'), 'group_dashboard/group_directory', array(
            'class' => 'button',
          ));
        }
        else {

          // User can make groups
          if (node_access('create', $group_types[0])) {
            $message = t("There are currently no groups available for you to join. Please create your first group to get started.");
            $buttons = theme('spaces_button');
          }
          else {
            $message = t("You are currently not a member of any groups. Please ask a site administrator to add your account to one of the site's groups.");
          }
        }
        drupal_set_message("<p>{$message}</p><div class='buttons'>{$buttons}</div>");
        return '';
      }
    }
    else {

      // User shouldn't be here.
      drupal_access_denied();
      exit;
    }
  }
}