Hack from Roberto Pinna (Bobo) to add sorting when viewing submissions
authormoodler <moodler>
Fri, 21 Mar 2003 14:07:25 +0000 (14:07 +0000)
committermoodler <moodler>
Fri, 21 Mar 2003 14:07:25 +0000 (14:07 +0000)
Might need some tidying up still but it's functional ..

mod/assignment/lib.php
mod/assignment/submissions.php

index bdcb607..12bd5b9 100644 (file)
@@ -233,16 +233,26 @@ function assignment_log_info($log) {
                               AND u.id = '$log->userid'");
 }
 
-function assignment_get_all_submissions($assignment) {
+function assignment_get_all_submissions($assignment, $sort="timemodified", $dir="DESC") {
 /// Return all assignment submissions by ENROLLED students
     global $CFG;
+
+    if ($sort == "lastname" or $sort == "firstname") {
+        $sort = "u.$sort $dir";
+    } else if (empty($sort)) {
+        $sort = "a.timemodified DESC";
+    } else {
+        $sort = "a.$sort $dir";
+    }
     return get_records_sql("SELECT a.* 
                               FROM {$CFG->prefix}assignment_submissions a, 
-                                   {$CFG->prefix}user_students s
+                                   {$CFG->prefix}user_students s,
+                                   {$CFG->prefix}user u
                              WHERE a.userid = s.userid
+                                          AND u.id = a.userid
                                AND s.course = '$assignment->course'
                                AND a.assignment = '$assignment->id' 
-                          ORDER BY a.timemodified DESC");
+                          ORDER BY $sort");
 }
 
 function assignment_get_users_done($assignment) {
index 5f7d5c7..132bd36 100644 (file)
@@ -46,7 +46,7 @@
     }
 
 /// Make some easy ways to reference submissions
-    if ($submissions = assignment_get_all_submissions($assignment)) {
+    if ($submissions = assignment_get_all_submissions($assignment, $sort)) {
         foreach ($submissions as $submission) {
             $submissionbyuser[$submission->userid] = $submission;
         }
@@ -65,7 +65,7 @@
     }
 
     if (isset($newsubmission)) {   // Get them all out again to be sure
-        $submissions = assignment_get_all_submissions($assignment);
+        $submissions = assignment_get_all_submissions($assignment, $sort);
     }
 
 
                 }
             }
         }
-        $submissions = assignment_get_all_submissions($assignment);
+        $submissions = assignment_get_all_submissions($assignment,$sort);
         add_to_log($course->id, "assignment", "update grades", "submissions.php?id=$assignment->id", "$count users");
         notify(get_string("feedbackupdated", "assignment", $count));
     } else {
         $grades[$i] = $i;
     }
 
-    echo "<FORM ACTION=submissions.php METHOD=post>\n";
+    // Submission sorting
+    print_simple_box_start("CENTER", "50%");
+    echo "<P align=\"CENTER\">";
+    print_string("order");
+    echo ": <A HREF=\"$ME?id=$assignment->id&sort=lastname&dir=ASC\">".get_string("name")."</a> - ";
+    echo "<A HREF=\"$ME?id=$assignment->id\">".get_string("lastmodified")."</a> - ";
+    echo "<A HREF=\"$ME?id=$assignment->id&sort=grade\">".get_string("feedback")."</a>";
+    echo "</P>";
+    print_simple_box_end();
+    print_spacer(8,1);
 
+    echo "<FORM ACTION=submissions.php METHOD=post>\n";
+    
     foreach ($submissions as $submission) {
         $user = $users[$submission->userid];
         assignment_print_submission($assignment, $user, $submission, $teachers, $grades);