MDL-45580 assignfeedback_editpdf: Delete draft content on new submission

This commit is contained in:
Frederic Massart 2014-06-13 10:41:45 +08:00
parent 098f7dd438
commit 7dbbb848c6
2 changed files with 20 additions and 1 deletions

View File

@ -438,8 +438,10 @@ class document_services {
if (!empty($files)) {
$first = reset($files);
if (!$readonly && $first->get_timemodified() < $submission->timemodified) {
// Image files are stale - regenerate them, except in readonly mode.
// Image files are stale, we need to regenerate them, except in readonly mode.
// We also need to remove the draft annotations and comments associated with this attempt.
$fs->delete_area_files($contextid, $component, $filearea, $itemid);
page_editor::delete_draft_content($itemid);
$files = array();
} else {

View File

@ -340,4 +340,21 @@ class page_editor {
return true;
}
/**
* Delete the draft annotations and comments.
*
* This is intended to be used when the version of the PDF has changed and the annotations
* might not be relevant any more, therefore we should delete them.
*
* @param int $gradeid The grade ID.
* @return bool
*/
public static function delete_draft_content($gradeid) {
global $DB;
$conditions = array('gradeid' => $gradeid, 'draft' => 1);
$result = $DB->delete_records('assignfeedback_editpdf_annot', $conditions);
$result = $result && $DB->delete_records('assignfeedback_editpdf_cmnt', $conditions);
return $result;
}
}