Example #1
0
     $draft = false;
 }
 $pages = document_services::get_page_images_for_attempt($seplment, $userid, $attemptnumber, $readonly);
 $response = new stdClass();
 $response->pagecount = count($pages);
 $response->pages = array();
 $grade = $seplment->get_user_grade($userid, true);
 // The readonly files are stored in a different file area.
 $filearea = document_services::PAGE_IMAGE_FILEAREA;
 if ($readonly) {
     $filearea = document_services::PAGE_IMAGE_READONLY_FILEAREA;
 }
 foreach ($pages as $id => $pagefile) {
     $index = count($response->pages);
     $page = new stdClass();
     $comments = page_editor::get_comments($grade->id, $index, $draft);
     $page->url = moodle_url::make_pluginfile_url($context->id, 'seplfeedback_editpdf', $filearea, $grade->id, '/', $pagefile->get_filename())->out();
     $page->comments = $comments;
     if ($imageinfo = $pagefile->get_imageinfo()) {
         $page->width = $imageinfo['width'];
         $page->height = $imageinfo['height'];
     } else {
         $page->width = 0;
         $page->height = 0;
     }
     $annotations = page_editor::get_annotations($grade->id, $index, $draft);
     $page->annotations = $annotations;
     array_push($response->pages, $page);
 }
 echo json_encode($response);
 die;
 public function test_page_editor()
 {
     $sepl = $this->create_sepl_and_submit_pdf();
     $this->setUser($this->teachers[0]);
     $grade = $sepl->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);
 }