? user_grade_tab.patch
Index: gradebook.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gradebook/gradebook.module,v
retrieving revision 1.15.4.2.2.14
diff -u -r1.15.4.2.2.14 gradebook.module
--- gradebook.module	18 Nov 2009 11:51:15 -0000	1.15.4.2.2.14
+++ gradebook.module	5 Dec 2009 21:41:49 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: gradebook.module,v 1.15.4.2.2.14 2009/11/18 11:51:15 mgn Exp $
+// $Id$
 /**
  * @file
  * Provides a simple gradebook
@@ -24,6 +24,7 @@
     'gradebook_assignment_grade' => array('arguments' => array('gradebook', 'grade', 'export')),
     'gradebook_term_grade' => array('arguments' => array('gradebook', 'grade', 'export')),
     'gradebook_grade_form' => array('arguments' => array('form_state' => NULL)),
+    'gradebook_grade_summary' => array('arguments' => array('account' => NULL, 'data' => NULL)),
   );
 }
 
@@ -249,6 +250,15 @@
     'file'               => 'gradebook.pages.inc',
   );
 
+  $items['user/%user/grades'] = array(
+    'type' => MENU_LOCAL_TASK,
+    'title' => t('Grade Summary'),
+    'page callback' => 'gradebook_page_grade_summary',
+    'page arguments' => array(1),
+    'access callback' => 'gradebook_page_grade_summary_access',
+    'access arguments' => array(1),
+  );
+
   return $items;
 }
 
@@ -458,7 +468,6 @@
  *  Get Sorted Assignments
  *
  */
-
 function gradebook_get_sorted_assignments($gradebook, $tids, $pager, $order, $sort) {
 
   switch ($order) {
@@ -488,6 +497,53 @@
   return $assignments;
 }
 
+function gradebook_page_grade_summary_access($account) {
+  global $user;
+  // Only display a grade summary tab if the user is a student in some gradebook and
+  // the logged in user is either the owner of the account or a gradebook administrator.
+  $count = db_result(db_query("SELECT COUNT(*) FROM {gradebookapi_cache} WHERE uid=%d", $account->uid));
+  return ($count > 0) && (($account->uid == $user->uid) || user_access('administer gradebook'));
+}
+
+function gradebook_page_grade_summary($account) {
+  // Get overall grades for this user and display in a themeable table.
+  $uid = $account->uid;
+  $vid = gradebookapi_get_vid();
+  $result = db_query('SELECT DISTINCT t.tid FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE h.parent = 0 AND t.vid = %d', $vid);
+  // Gather data for gradebook summary page.
+  $data = array();
+  while ($tid = db_result($result)) {
+    $gradebook = gradebookapi_gradebook_load($tid);
+    if (gradebookapi_is_student($gradebook, $account)) {
+      $grade = gradebookapi_get_term_grade($uid, $gradebook->tid);
+      $data[$tid] = array('gradebook' => $gradebook, 'grade' => $grade);
+    }
+  }
+  return theme('gradebook_grade_summary', $account, $data);
+}
+
+function theme_gradebook_grade_summary($account, $data) {
+
+  // If no data is available, print a helpful message!
+  if (empty($data)) {
+    $output = t('No grades are available for @user', array('@user' => $account->name));
+    return $output;
+  }
+
+  $headers = array(t('Course'), t('Grade'));
+  $rows = array();
+  foreach ($data as $tid => $entry) {
+    $row = array();
+    $gradebook = $entry['gradebook'];
+    $grade = $entry['grade'];
+    $row[] = l($gradebook->name, 'gradebook/'. $tid);
+    // Get the term grades.
+    $row[] = theme('gradebook_term_grade', $gradebook, $grade, TRUE);
+    $rows[] = $row;
+  }
+  return theme('table', $headers, $rows);
+}
+
 /**
  * Menu callback; prints an assignment list with student grades.
  * Leave this callback in gradebook.module to make it easy for other gradebook modules to find and use.
