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; } } } } } } } }
public function test_page_editor() { $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'; $comment2 = new comment(); $comment2->rawtext = 'Comment text 2'; $comment2->width = 100; $comment2->x = 200; $comment2->y = 100; $comment2->colour = 'clear'; page_editor::set_comments($grade->id, 0, array($comment, $comment2)); $annotation = new annotation(); $annotation->path = ''; $annotation->x = 100; $annotation->y = 100; $annotation->endx = 200; $annotation->endy = 200; $annotation->type = 'line'; $annotation->colour = 'red'; $annotation2 = new annotation(); $annotation2->path = ''; $annotation2->x = 100; $annotation2->y = 100; $annotation2->endx = 200; $annotation2->endy = 200; $annotation2->type = 'rectangle'; $annotation2->colour = 'yellow'; page_editor::set_annotations($grade->id, 0, array($annotation, $annotation2)); $notempty = page_editor::has_annotations_or_comments($grade->id, false); // Still empty because all edits are still drafts. $this->assertFalse($notempty); $comments = page_editor::get_comments($grade->id, 0, false); $this->assertEmpty($comments); $comments = page_editor::get_comments($grade->id, 0, true); $this->assertEquals(count($comments), 2); $annotations = page_editor::get_annotations($grade->id, 0, false); $this->assertEmpty($annotations); $annotations = page_editor::get_annotations($grade->id, 0, true); $this->assertEquals(count($annotations), 2); $comment = reset($comments); $annotation = reset($annotations); page_editor::remove_comment($comment->id); page_editor::remove_annotation($annotation->id); $comments = page_editor::get_comments($grade->id, 0, true); $this->assertEquals(count($comments), 1); $annotations = page_editor::get_annotations($grade->id, 0, true); $this->assertEquals(count($annotations), 1); page_editor::release_drafts($grade->id); $notempty = page_editor::has_annotations_or_comments($grade->id, false); $this->assertTrue($notempty); page_editor::unrelease_drafts($grade->id); $notempty = page_editor::has_annotations_or_comments($grade->id, false); $this->assertFalse($notempty); }