MDL-47397 assignfeedback_editpdf: Copy stamps to other students in team
authorFrederic Massart <fred@moodle.com>
Thu, 23 Oct 2014 09:37:52 +0000 (17:37 +0800)
committerDan Poltawski <dan@moodle.com>
Fri, 24 Oct 2014 14:09:06 +0000 (15:09 +0100)
During a team submission the stamps were attached to the user that
was graded and not to the other users. This could lead to errors when
generating the PDF for each user.

mod/assign/feedback/editpdf/classes/page_editor.php

index 3dfa071..afa01ef 100644 (file)
@@ -338,6 +338,23 @@ class page_editor {
             $DB->insert_record('assignfeedback_editpdf_cmnt', $comment);
         }
 
+        // Delete the existing stamps and copy the source ones.
+        $fs = get_file_storage();
+        $fs->delete_area_files($assignment->get_context()->id, 'assignfeedback_editpdf', 'stamps', $grade->id);
+        if ($files = $fs->get_area_files($assignment->get_context()->id,
+                                         'assignfeedback_editpdf',
+                                         'stamps',
+                                         $sourceusergrade->id,
+                                         "filename",
+                                         false)) {
+            foreach ($files as $file) {
+                $newrecord = new \stdClass();
+                $newrecord->contextid = $assignment->get_context()->id;
+                $newrecord->itemid = $grade->id;
+                $fs->create_file_from_storedfile($newrecord, $file);
+            }
+        }
+
         return true;
     }