/** * Do the job. * Throw exceptions on errors (the job will be retried). */ public function execute() { global $CFG, $DB; require_once $CFG->dirroot . '/mod/assign/locallib.php'; $records = $DB->get_records('assignfeedback_editpdf_queue'); $assignmentcache = array(); foreach ($records as $record) { $submissionid = $record->submissionid; $submission = $DB->get_record('assign_submission', array('id' => $submissionid), '*', IGNORE_MISSING); if (!$submission) { // Submission no longer exists. $DB->delete_records('assignfeedback_editpdf_queue', array('id' => $record->id)); continue; } $assignmentid = $submission->assignment; $attemptnumber = $record->submissionattempt; if (empty($assignmentcache[$assignmentid])) { $cm = get_coursemodule_from_instance('assign', $assignmentid, 0, false, MUST_EXIST); $context = context_module::instance($cm->id); $assignment = new assign($context, null, null); $assignmentcache[$assignmentid] = $assignment; } else { $assignment = $assignmentcache[$assignmentid]; } $users = array(); if ($submission->userid) { array_push($users, $submission->userid); } else { $members = $assignment->get_submission_group_members($submission->groupid, true); foreach ($members as $member) { array_push($users, $member->id); } } mtrace('Convert ' . count($users) . ' submission attempt(s) for assignment ' . $assignmentid); foreach ($users as $userid) { document_services::get_page_images_for_attempt($assignment, $userid, $attemptnumber, true); document_services::get_page_images_for_attempt($assignment, $userid, $attemptnumber, false); } $DB->delete_records('assignfeedback_editpdf_queue', array('id' => $record->id)); } }
die; } else { if ($action == 'revertchanges') { require_capability('mod/assign:grade', $context); $grade = $assignment->get_user_grade($userid, true, $attemptnumber); $result = page_editor::revert_drafts($gradeid); echo json_encode($result); die; } else { if ($action == 'removefromquicklist') { require_capability('mod/assign:grade', $context); $commentid = required_param('commentid', PARAM_INT); $result = comments_quick_list::remove_comment($commentid); echo json_encode($result); die; } else { if ($action == 'deletefeedbackdocument') { require_capability('mod/assign:grade', $context); $grade = $assignment->get_user_grade($userid, true, $attemptnumber); $result = document_services::delete_feedback_document($assignment, $userid, $attemptnumber); $result = $result && page_editor::unrelease_drafts($grade->id); echo json_encode($result); die; } } } } } } } }
/** * Generate the pdf. * * @param stdClass $grade * @param stdClass $data * @return bool */ public function save(stdClass $grade, stdClass $data) { // Source user id is only added to the form if there was a pdf. if (!empty($data->editpdf_source_userid)) { $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); } return true; }
public function test_document_services() { $assign = $this->create_assign_and_submit_pdf(); $this->setUser($this->teachers[0]); $grade = $assign->get_user_grade($this->students[0]->id, true); $notempty = page_editor::has_annotations_or_comments($grade->id, false); $this->assertFalse($notempty); $comment = new comment(); $comment->rawtext = 'Comment text'; $comment->width = 100; $comment->x = 100; $comment->y = 100; $comment->colour = 'red'; page_editor::set_comments($grade->id, 0, array($comment)); $annotations = array(); $annotation = new annotation(); $annotation->path = ''; $annotation->x = 100; $annotation->y = 100; $annotation->endx = 200; $annotation->endy = 200; $annotation->type = 'line'; $annotation->colour = 'red'; array_push($annotations, $annotation); $annotation = new annotation(); $annotation->path = ''; $annotation->x = 100; $annotation->y = 100; $annotation->endx = 200; $annotation->endy = 200; $annotation->type = 'rectangle'; $annotation->colour = 'yellow'; array_push($annotations, $annotation); $annotation = new annotation(); $annotation->path = ''; $annotation->x = 100; $annotation->y = 100; $annotation->endx = 200; $annotation->endy = 200; $annotation->type = 'oval'; $annotation->colour = 'green'; array_push($annotations, $annotation); $annotation = new annotation(); $annotation->path = ''; $annotation->x = 100; $annotation->y = 100; $annotation->endx = 200; $annotation->endy = 116; $annotation->type = 'highlight'; $annotation->colour = 'blue'; array_push($annotations, $annotation); $annotation = new annotation(); $annotation->path = '100,100:105,105:110,100'; $annotation->x = 100; $annotation->y = 100; $annotation->endx = 110; $annotation->endy = 105; $annotation->type = 'pen'; $annotation->colour = 'black'; array_push($annotations, $annotation); page_editor::set_annotations($grade->id, 0, $annotations); page_editor::release_drafts($grade->id); $notempty = page_editor::has_annotations_or_comments($grade->id, false); $this->assertTrue($notempty); $file = document_services::generate_feedback_document($assign->get_instance()->id, $grade->userid, $grade->attemptnumber); $this->assertNotEmpty($file); $file2 = document_services::get_feedback_document($assign->get_instance()->id, $grade->userid, $grade->attemptnumber); $this->assertEquals($file, $file2); document_services::delete_feedback_document($assign->get_instance()->id, $grade->userid, $grade->attemptnumber); $file3 = document_services::get_feedback_document($assign->get_instance()->id, $grade->userid, $grade->attemptnumber); $this->assertEmpty($file3); }
/** * Generate the pdf. * * @param stdClass $grade * @param stdClass $data * @return bool */ public function save(stdClass $grade, stdClass $data) { if (page_editor::has_annotations_or_comments($grade->id, true)) { document_services::generate_feedback_document($this->assignment, $grade->userid, $grade->attemptnumber); } return true; }