Skip to content

Commit

Permalink
MDL-45582: Apply grades and feedback to entire group does not work wi…
Browse files Browse the repository at this point in the history
…th Annotate PDF feature
  • Loading branch information
greg-or committed Jun 16, 2014
1 parent e6c69d8 commit 8b1596c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
32 changes: 32 additions & 0 deletions mod/assign/feedback/editpdf/classes/page_editor.php
Expand Up @@ -308,4 +308,36 @@ public static function remove_annotation($annotationid) {

return $DB->delete_records('assignfeedback_editpdf_annot', array('id'=>$annotationid));
}

/**
* This function copies annotations and comments from the source user
* to the current group member being processed when using applytoall.
* @param int|\assign $assignment
* @param stdClass $grade
* @param int $sourceuserid
* @return bool
*/
public static function copy_drafts_from_to($assignment, $grade, $sourceuserid) {
global $DB;

// Delete any existing annotations and comments from current user.
$DB->delete_records('assignfeedback_editpdf_annot', array('gradeid' => $grade->id));
$DB->delete_records('assignfeedback_editpdf_cmnt', array('gradeid' => $grade->id));
// Get gradeid, annotations and comments from sourceuserid.
$sourceusergrade = $assignment->get_user_grade($sourceuserid, true, $grade->attemptnumber);
$annotations = $DB->get_records('assignfeedback_editpdf_annot', array('gradeid' => $sourceusergrade->id, 'draft' => 1));
$comments = $DB->get_records('assignfeedback_editpdf_cmnt', array('gradeid' => $sourceusergrade->id, 'draft' => 1));

// Add annotations and comments to current user to generate feedback file.
foreach ($annotations as $annotation) {
$annotation->gradeid = $grade->id;
$DB->insert_record('assignfeedback_editpdf_annot', $annotation);
}
foreach ($comments as $comment) {
$comment->gradeid = $grade->id;
$DB->insert_record('assignfeedback_editpdf_cmnt', $comment);
}

return true;
}
}
8 changes: 8 additions & 0 deletions mod/assign/feedback/editpdf/locallib.php
Expand Up @@ -178,6 +178,9 @@ public function get_form_elements_for_user($grade, MoodleQuickForm $mform, stdCl
$html = $renderer->render($widget);
$mform->addElement('static', 'editpdf', get_string('editpdf', 'assignfeedback_editpdf'), $html);
$mform->addHelpButton('editpdf', 'editpdf', 'assignfeedback_editpdf');
$mform->addElement('hidden', 'editpdf_source_userid', $userid);
$mform->setType('editpdf_source_userid', PARAM_INT);
$mform->setConstant('editpdf_source_userid', $userid);
}
}

Expand All @@ -189,6 +192,11 @@ public function get_form_elements_for_user($grade, MoodleQuickForm $mform, stdCl
* @return bool
*/
public function save(stdClass $grade, stdClass $data) {
$sourceuserid = $data->editpdf_source_userid;
// Copy drafts annotations and comments if current user is different to sourceuserid.
if ($sourceuserid != $grade->userid) {
page_editor::copy_drafts_from_to($this->assignment, $grade, $sourceuserid);
}
if (page_editor::has_annotations_or_comments($grade->id, true)) {
document_services::generate_feedback_document($this->assignment, $grade->userid, $grade->attemptnumber);
}
Expand Down

0 comments on commit 8b1596c

Please sign in to comment.