Merge branch 'MDL-38973-master' of https://github.com/damyon/moodle
authorDan Poltawski <dan@moodle.com>
Wed, 10 Apr 2013 06:48:49 +0000 (14:48 +0800)
committerDan Poltawski <dan@moodle.com>
Wed, 10 Apr 2013 06:48:49 +0000 (14:48 +0800)
mod/assign/gradingtable.php
mod/assign/locallib.php
mod/assign/upgrade.txt

index 7033fe7..a168a0b 100644 (file)
@@ -468,7 +468,7 @@ class assign_grading_table extends table_sql implements renderable {
     public function col_team(stdClass $row) {
         $submission = false;
         $group = false;
-        $this->get_group_and_submission($row->id, $group, $submission);
+        $this->get_group_and_submission($row->id, $group, $submission, -1);
         if ($group) {
             return $group->name;
         }
@@ -481,8 +481,9 @@ class assign_grading_table extends table_sql implements renderable {
      * @param int $userid The user id for this submission
      * @param int $groupid The groupid (returned)
      * @param mixed $submission The stdClass submission or false (returned)
+     * @param int $attemptnumber Return a specific attempt number (-1 for latest)
      */
-    public function get_group_and_submission($userid, &$group, &$submission) {
+    protected function get_group_and_submission($userid, &$group, &$submission, $attemptnumber) {
         $group = false;
         if (isset($this->submissiongroups[$userid])) {
             $group = $this->submissiongroups[$userid];
@@ -496,11 +497,13 @@ class assign_grading_table extends table_sql implements renderable {
             $groupid = $group->id;
         }
 
-        if (isset($this->groupsubmissions[$groupid])) {
-            $submission = $this->groupsubmissions[$groupid];
+        // Static cache is keyed by groupid and attemptnumber.
+        // We may need both the latest and previous attempt in the same page.
+        if (isset($this->groupsubmissions[$groupid . ':' . $attemptnumber])) {
+            $submission = $this->groupsubmissions[$groupid . ':' . $attemptnumber];
         } else {
-            $submission = $this->assignment->get_group_submission($userid, $groupid, false);
-            $this->groupsubmissions[$groupid] = $submission;
+            $submission = $this->assignment->get_group_submission($userid, $groupid, false, $attemptnumber);
+            $this->groupsubmissions[$groupid . ':' . $attemptnumber] = $submission;
         }
     }
 
@@ -514,7 +517,7 @@ class assign_grading_table extends table_sql implements renderable {
     public function col_teamstatus(stdClass $row) {
         $submission = false;
         $group = false;
-        $this->get_group_and_submission($row->id, $group, $submission);
+        $this->get_group_and_submission($row->id, $group, $submission, -1);
 
         $status = '';
         if ($submission) {
@@ -965,8 +968,13 @@ class assign_grading_table extends table_sql implements renderable {
                 if ($this->assignment->get_instance()->teamsubmission) {
                     $group = false;
                     $submission = false;
-                    $this->get_group_and_submission($row->id, $group, $submission);
+
+                    $this->get_group_and_submission($row->id, $group, $submission, -1);
                     if ($submission) {
+                        if ($submission->status == ASSIGN_SUBMISSION_STATUS_REOPENED) {
+                            // For a newly reopened submission - we want to show the previous submission in the table.
+                            $this->get_group_and_submission($row->id, $group, $submission, $submission->attemptnumber-1);
+                        }
                         if (isset($field)) {
                             return $plugin->get_editor_text($field, $submission->id);
                         }
@@ -976,15 +984,21 @@ class assign_grading_table extends table_sql implements renderable {
                                                                       array());
                     }
                 } else if ($row->submissionid) {
+                    if ($row->status == ASSIGN_SUBMISSION_STATUS_REOPENED) {
+                        // For a newly reopened submission - we want to show the previous submission in the table.
+                        $submission = $this->assignment->get_user_submission($row->userid, false, $row->attemptnumber - 1);
+                    } else {
+                        $submission = new stdClass();
+                        $submission->id = $row->submissionid;
+                        $submission->timecreated = $row->firstsubmission;
+                        $submission->timemodified = $row->timesubmitted;
+                        $submission->assignment = $this->assignment->get_instance()->id;
+                        $submission->userid = $row->userid;
+                    }
+                    // Field is used for only for import/export and refers the the fieldname for the text editor.
                     if (isset($field)) {
-                        return $plugin->get_editor_text($field, $row->submissionid);
+                        return $plugin->get_editor_text($field, $submission->id);
                     }
-                    $submission = new stdClass();
-                    $submission->id = $row->submissionid;
-                    $submission->timecreated = $row->firstsubmission;
-                    $submission->timemodified = $row->timesubmitted;
-                    $submission->assignment = $this->assignment->get_instance()->id;
-                    $submission->userid = $row->userid;
                     return $this->format_plugin_summary_with_link($plugin,
                                                                   $submission,
                                                                   'grading',
index 646c6ce..5ba28a6 100644 (file)
@@ -3407,22 +3407,22 @@ class assign {
                                                       $this->get_return_params());
 
                 $o .= $this->get_renderer()->render($feedbackstatus);
+            }
 
-                $allsubmissions = $this->get_all_submissions($user->id);
+            $allsubmissions = $this->get_all_submissions($user->id);
 
-                if (count($allsubmissions) > 1) {
-                    $allgrades = $this->get_all_grades($user->id);
-                    $history = new assign_attempt_history($allsubmissions,
-                                                          $allgrades,
-                                                          $this->get_submission_plugins(),
-                                                          $this->get_feedback_plugins(),
-                                                          $this->get_course_module()->id,
-                                                          $this->get_return_action(),
-                                                          $this->get_return_params(),
-                                                          false);
+            if (count($allsubmissions) > 1) {
+                $allgrades = $this->get_all_grades($user->id);
+                $history = new assign_attempt_history($allsubmissions,
+                                                      $allgrades,
+                                                      $this->get_submission_plugins(),
+                                                      $this->get_feedback_plugins(),
+                                                      $this->get_course_module()->id,
+                                                      $this->get_return_action(),
+                                                      $this->get_return_params(),
+                                                      false);
 
-                    $o .= $this->get_renderer()->render($history);
-                }
+                $o .= $this->get_renderer()->render($history);
             }
 
         }
index 51f17e1..d5cd0f6 100644 (file)
@@ -37,6 +37,9 @@ This files describes API changes in the assign code.
     New renderable object "assign_attempt_history" for rendering the list of previous submissions.
     New renderable object "assign_gradingmessage" for rendering a generic grading message.
 
+    assign_grading_table changes:
+        get_group_and_submission is now protected and should not be called from outside this class.
+
 
 === Earlier changes ===