Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
rkingdon authored
Showing with 22 additions and 13 deletions.
  1. +22 −13 mod/workshop/lib.php
View
35 mod/workshop/lib.php
@@ -167,12 +167,13 @@ function workshop_delete_instance($id) {
}
function workshop_user_outline($course, $user, $mod, $workshop) {
- if ($submission = workshop_get_student_submission($workshop, $user)) {
- $result->info = $submission->title;
- if ($submission->finalgrade) {
- $result->info .= ", ".get_string("grade").": $submission->finalgrade";
- }
- $result->time = $submission->timecreated;
+ if ($submissions = workshop_get_user_submissions($workshop, $user)) {
+ $result->info = count($submissions)." ".get_string("submissions", "workshop");
+ // workshop_get_user_submissions returns the newest one first
+ foreach ($submissions as $submission) {
+ $result->time = $submission->timecreated;
+ break;
+ }
return $result;
}
return NULL;
@@ -632,9 +633,15 @@ function workshop_print_recent_activity($course, $isteacher, $timestart) {
function workshop_grades($workshopid) {
/// Must return an array of grades, indexed by user, and a max grade.
+global $CFG;
- $return->grades = get_records_select_menu("workshop_submissions",
- "workshopid = $workshopid", "", "userid, finalgrade");
+ if ($bestsubmissions = get_records_sql("SELECT userid, max(finalgrade) finalgrade FROM
+ {$CFG->prefix}workshop_submissions WHERE workshopid = $workshopid GROUP
+ BY userid")) {
+ foreach ($bestsubmissions as $bestgrade) {
+ $return->grades[$bestgrade->userid] = $bestgrade->finalgrade;
+ }
+ }
$return->maxgrade = get_field("workshop", "grade", "id", "$workshopid");
return $return;
}
@@ -955,8 +962,9 @@ function workshop_count_user_assessments_done($workshop, $user) {
function workshop_count_user_submissions($workshop, $user) {
- // returns the number of submissions make by this user
- return count_records("workshop_submissions", "workshopid", $workshop->id, "userid", $user->id);
+ // returns the number of (real) submissions make by this user
+ return count_records_select("workshop_submissions", "workshopid = $workshop->id AND
+ userid = $user->id AND timecreated > 0");
}
@@ -1222,9 +1230,10 @@ function workshop_get_user_assessments($workshop, $user) {
function workshop_get_user_submissions($workshop, $user) {
- // return submission of user newest first, oldest last
- return get_records_select("workshop_submissions ",
- "workshopid = $workshop->id AND userid = $user->id", "timecreated DESC" );
+ // return real submissions of user newest first, oldest last. Ignores the dummy submissions
+ // which get created to hold the final grades for users for make no submissions)
+ return get_records_select("workshop_submissions", "workshopid = $workshop->id AND
+ userid = $user->id AND timecreated > 0", "timecreated DESC" );
}
Please sign in to comment.
Something went wrong with that request. Please try again.