Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix a bug in final grades when users submit more than one piece of work

(some grades were appearing as zero); workshop_user_outline now returns
number of submissions and date of last submission.
  • Loading branch information...
commit 42fd37e574b9c48c2daf7c4f32cc884ed4044d26 1 parent 266d6b7
authored September 08, 2003

Showing 1 changed file with 22 additions and 13 deletions. Show diff stats Hide diff stats

  1. 35  mod/workshop/lib.php
35  mod/workshop/lib.php
@@ -167,12 +167,13 @@ function workshop_delete_instance($id) {
167 167
 }
168 168
 
169 169
 function workshop_user_outline($course, $user, $mod, $workshop) {
170  
-    if ($submission = workshop_get_student_submission($workshop, $user)) {
171  
-		$result->info = $submission->title;
172  
-        if ($submission->finalgrade) {
173  
-            $result->info .= ", ".get_string("grade").": $submission->finalgrade";
174  
-        }
175  
-        $result->time = $submission->timecreated;
  170
+    if ($submissions = workshop_get_user_submissions($workshop, $user)) {
  171
+		$result->info = count($submissions)." ".get_string("submissions", "workshop");
  172
+		// workshop_get_user_submissions returns the newest one first
  173
+		foreach ($submissions as $submission) {
  174
+			$result->time = $submission->timecreated;
  175
+			break;
  176
+			}
176 177
         return $result;
177 178
     }
178 179
     return NULL;
@@ -632,9 +633,15 @@ function workshop_print_recent_activity($course, $isteacher, $timestart) {
632 633
 
633 634
 function workshop_grades($workshopid) {
634 635
 /// Must return an array of grades, indexed by user, and a max grade.
  636
+global $CFG;
635 637
 
636  
-    $return->grades = get_records_select_menu("workshop_submissions", 
637  
-		"workshopid = $workshopid", "", "userid, finalgrade");
  638
+	if ($bestsubmissions = get_records_sql("SELECT userid, max(finalgrade) finalgrade FROM
  639
+			{$CFG->prefix}workshop_submissions WHERE workshopid = $workshopid GROUP
  640
+			BY userid")) {
  641
+		foreach ($bestsubmissions as $bestgrade) {
  642
+			$return->grades[$bestgrade->userid] = $bestgrade->finalgrade;
  643
+			}
  644
+		}		
638 645
     $return->maxgrade = get_field("workshop", "grade", "id", "$workshopid");
639 646
     return $return;
640 647
 }
@@ -955,8 +962,9 @@ function workshop_count_user_assessments_done($workshop, $user) {
955 962
 
956 963
 
957 964
 function workshop_count_user_submissions($workshop, $user) {
958  
-	// returns the number of submissions make by this user
959  
-	return count_records("workshop_submissions", "workshopid", $workshop->id, "userid", $user->id);
  965
+	// returns the number of (real) submissions make by this user
  966
+	return count_records_select("workshop_submissions", "workshopid = $workshop->id AND 
  967
+		userid = $user->id AND timecreated > 0");
960 968
 	}
961 969
 
962 970
 
@@ -1222,9 +1230,10 @@ function workshop_get_user_assessments($workshop, $user) {
1222 1230
 
1223 1231
 
1224 1232
 function workshop_get_user_submissions($workshop, $user) {
1225  
-	// return submission of user newest first, oldest last
1226  
-    return get_records_select("workshop_submissions ",
1227  
-             "workshopid = $workshop->id AND userid = $user->id", "timecreated DESC" );
  1233
+	// return real submissions of user newest first, oldest last. Ignores the dummy submissions
  1234
+	// which get created to hold the final grades for users for make no submissions)
  1235
+    return get_records_select("workshop_submissions", "workshopid = $workshop->id AND 
  1236
+		userid = $user->id AND timecreated > 0", "timecreated DESC" );
1228 1237
 }
1229 1238
 
1230 1239
 

0 notes on commit 42fd37e

Please sign in to comment.
Something went wrong with that request. Please try again.