[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Process ajax requests 19 * 20 * @package assignfeedback_editpdf 21 * @copyright 2012 Davo Smith 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 use \assignfeedback_editpdf\document_services; 26 use \assignfeedback_editpdf\page_editor; 27 use \assignfeedback_editpdf\comments_quick_list; 28 29 define('AJAX_SCRIPT', true); 30 31 require('../../../../config.php'); 32 require_once($CFG->dirroot . '/mod/assign/locallib.php'); 33 34 require_sesskey(); 35 36 $action = optional_param('action', '', PARAM_ALPHANUM); 37 $assignmentid = required_param('assignmentid', PARAM_INT); 38 $userid = required_param('userid', PARAM_INT); 39 $attemptnumber = required_param('attemptnumber', PARAM_INT); 40 $readonly = optional_param('readonly', false, PARAM_BOOL); 41 42 $cm = \get_coursemodule_from_instance('assign', $assignmentid, 0, false, MUST_EXIST); 43 $context = \context_module::instance($cm->id); 44 45 $assignment = new \assign($context, null, null); 46 47 require_login($assignment->get_course(), false, $cm); 48 49 if (!$assignment->can_view_submission($userid)) { 50 print_error('nopermission'); 51 } 52 53 if ($action == 'loadallpages') { 54 $draft = true; 55 if (!has_capability('mod/assign:grade', $context)) { 56 $draft = false; 57 $readonly = true; // A student always sees the readonly version. 58 require_capability('mod/assign:submit', $context); 59 } 60 61 // Whoever is viewing the readonly version should not use the drafts, but the actual annotations. 62 if ($readonly) { 63 $draft = false; 64 } 65 66 $pages = document_services::get_page_images_for_attempt($assignment, 67 $userid, 68 $attemptnumber, 69 $readonly); 70 71 $response = new stdClass(); 72 $response->pagecount = count($pages); 73 $response->pages = array(); 74 75 $grade = $assignment->get_user_grade($userid, true); 76 77 // The readonly files are stored in a different file area. 78 $filearea = document_services::PAGE_IMAGE_FILEAREA; 79 if ($readonly) { 80 $filearea = document_services::PAGE_IMAGE_READONLY_FILEAREA; 81 } 82 83 foreach ($pages as $id => $pagefile) { 84 $index = count($response->pages); 85 $page = new stdClass(); 86 $comments = page_editor::get_comments($grade->id, $index, $draft); 87 $page->url = moodle_url::make_pluginfile_url($context->id, 88 'assignfeedback_editpdf', 89 $filearea, 90 $grade->id, 91 '/', 92 $pagefile->get_filename())->out(); 93 $page->comments = $comments; 94 if ($imageinfo = $pagefile->get_imageinfo()) { 95 $page->width = $imageinfo['width']; 96 $page->height = $imageinfo['height']; 97 } else { 98 $page->width = 0; 99 $page->height = 0; 100 } 101 $annotations = page_editor::get_annotations($grade->id, $index, $draft); 102 $page->annotations = $annotations; 103 array_push($response->pages, $page); 104 } 105 106 echo json_encode($response); 107 die(); 108 } else if ($action == 'savepage') { 109 require_capability('mod/assign:grade', $context); 110 111 $response = new stdClass(); 112 $response->errors = array(); 113 114 $grade = $assignment->get_user_grade($userid, true); 115 116 $pagejson = required_param('page', PARAM_RAW); 117 $page = json_decode($pagejson); 118 $index = required_param('index', PARAM_INT); 119 120 $added = page_editor::set_comments($grade->id, $index, $page->comments); 121 if ($added != count($page->comments)) { 122 array_push($response->errors, get_string('couldnotsavepage', 'assignfeedback_editpdf', $index+1)); 123 } 124 $added = page_editor::set_annotations($grade->id, $index, $page->annotations); 125 if ($added != count($page->annotations)) { 126 array_push($response->errors, get_string('couldnotsavepage', 'assignfeedback_editpdf', $index+1)); 127 } 128 echo json_encode($response); 129 die(); 130 131 } else if ($action == 'generatepdf') { 132 133 require_capability('mod/assign:grade', $context); 134 $response = new stdClass(); 135 $grade = $assignment->get_user_grade($userid, true); 136 $file = document_services::generate_feedback_document($assignment, $userid, $attemptnumber); 137 138 $response->url = ''; 139 if ($file) { 140 $url = moodle_url::make_pluginfile_url($assignment->get_context()->id, 141 'assignfeedback_editpdf', 142 document_services::FINAL_PDF_FILEAREA, 143 $grade->id, 144 '/', 145 $file->get_filename(), 146 false); 147 $response->url = $url->out(true); 148 $response->filename = $file->get_filename(); 149 } 150 151 echo json_encode($response); 152 die(); 153 } else if ($action == 'loadquicklist') { 154 require_capability('mod/assign:grade', $context); 155 156 $result = comments_quick_list::get_comments(); 157 158 echo json_encode($result); 159 die(); 160 161 } else if ($action == 'addtoquicklist') { 162 require_capability('mod/assign:grade', $context); 163 164 $comment = required_param('commenttext', PARAM_RAW); 165 $width = required_param('width', PARAM_INT); 166 $colour = required_param('colour', PARAM_ALPHA); 167 168 $result = comments_quick_list::add_comment($comment, $width, $colour); 169 170 echo json_encode($result); 171 die(); 172 } else if ($action == 'revertchanges') { 173 require_capability('mod/assign:grade', $context); 174 175 $grade = $assignment->get_user_grade($userid, true); 176 177 $result = page_editor::revert_drafts($gradeid); 178 179 echo json_encode($result); 180 die(); 181 } else if ($action == 'removefromquicklist') { 182 require_capability('mod/assign:grade', $context); 183 184 $commentid = required_param('commentid', PARAM_INT); 185 186 $result = comments_quick_list::remove_comment($commentid); 187 188 echo json_encode($result); 189 die(); 190 } else if ($action == 'deletefeedbackdocument') { 191 require_capability('mod/assign:grade', $context); 192 193 $grade = $assignment->get_user_grade($userid, true); 194 $result = document_services::delete_feedback_document($assignment, $userid, $attemptnumber); 195 196 $result = $result && page_editor::unrelease_drafts($grade->id); 197 echo json_encode($result); 198 die(); 199 } 200
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |