|
14 | 14 | // You should have received a copy of the GNU General Public License |
15 | 15 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 |
|
| 17 | +/** |
| 18 | + * Turnitin ajax file |
| 19 | + * |
| 20 | + * @package plagiarism_turnitin |
| 21 | + * @copyright 2013 iParadigms LLC |
| 22 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 23 | + */ |
| 24 | + |
17 | 25 | use Integrations\PhpSdk\TiiClass; |
18 | 26 |
|
19 | 27 | require_once(__DIR__.'/../../config.php'); |
|
23 | 31 |
|
24 | 32 | require_login(); |
25 | 33 |
|
| 34 | +if ($_SERVER['REQUEST_METHOD'] === 'GET') { |
| 35 | + \core\session\manager::write_close(); |
| 36 | +} |
| 37 | + |
26 | 38 | $action = required_param('action', PARAM_ALPHAEXT); |
27 | 39 | $cmid = optional_param('cmid', 0, PARAM_INT); |
28 | 40 | $itemid = optional_param('itemid', 0, PARAM_INT); |
|
45 | 57 |
|
46 | 58 | $pathnamehash = optional_param('pathnamehash', "", PARAM_ALPHANUM); |
47 | 59 | $submissiontype = optional_param('submission_type', "", PARAM_ALPHAEXT); |
48 | | -$return = array(); |
| 60 | +$return = []; |
49 | 61 |
|
50 | 62 | // Initialise plugin class. |
51 | 63 | $pluginturnitin = new plagiarism_plugin_turnitin(); |
|
79 | 91 | $userrole, |
80 | 92 | '' |
81 | 93 | ), |
82 | | - array('style' => 'display: none') |
| 94 | + ['style' => 'display: none'] |
83 | 95 | ); |
84 | 96 | } |
85 | 97 | break; |
86 | 98 |
|
87 | 99 | case "update_grade": |
88 | 100 | if (!confirm_sesskey()) { |
89 | | - throw new moodle_exception('invalidsesskey', 'error'); |
| 101 | + throw new \moodle_exception('invalidsesskey', 'error'); |
90 | 102 | } |
91 | 103 |
|
92 | 104 | include_once($CFG->libdir."/gradelib.php"); |
|
102 | 114 |
|
103 | 115 | // If we have a turnitin timestamp stored then update it, otherwise create it. |
104 | 116 | if ($timestampid = $DB->get_record('plagiarism_turnitin_config', |
105 | | - array('cm' => $cm->id, 'name' => 'grades_last_synced'), 'id')) { |
| 117 | + ['cm' => $cm->id, 'name' => 'grades_last_synced'], 'id')) { |
106 | 118 | $moduleconfigvalue->id = $timestampid->id; |
107 | 119 | $DB->update_record('plagiarism_turnitin_config', $moduleconfigvalue); |
108 | 120 | } else { |
|
119 | 131 |
|
120 | 132 | case "refresh_peermark_assignments": |
121 | 133 | if (!confirm_sesskey()) { |
122 | | - throw new moodle_exception('invalidsesskey', 'error'); |
| 134 | + throw new \moodle_exception('invalidsesskey', 'error'); |
123 | 135 | } |
124 | 136 |
|
125 | | - $tiiassignment = $DB->get_record('plagiarism_turnitin_config', array('cm' => $cm->id, 'name' => 'turnitin_assignid')); |
| 137 | + $tiiassignment = $DB->get_record('plagiarism_turnitin_config', ['cm' => $cm->id, 'name' => 'turnitin_assignid']); |
126 | 138 | $pluginturnitin->refresh_peermark_assignments($cm, $tiiassignment->value); |
127 | 139 | break; |
128 | 140 |
|
|
132 | 144 | $plagiarismpluginturnitin = new plagiarism_plugin_turnitin(); |
133 | 145 | $coursedata = $plagiarismpluginturnitin->get_course_data($cm->id, $cm->course); |
134 | 146 |
|
135 | | - $tiiassignment = $DB->get_record('plagiarism_turnitin_config', array('cm' => $cm->id, 'name' => 'turnitin_assignid')); |
| 147 | + $tiiassignment = $DB->get_record('plagiarism_turnitin_config', ['cm' => $cm->id, 'name' => 'turnitin_assignid']); |
136 | 148 |
|
137 | 149 | if ($tiiassignment) { |
138 | 150 | $tiiassignmentid = $tiiassignment->value; |
|
148 | 160 | echo html_writer::tag( |
149 | 161 | 'div', |
150 | 162 | turnitin_view::output_lti_form_launch('peermark_manager', 'Instructor', $tiiassignmentid), |
151 | | - array( |
| 163 | + [ |
152 | 164 | 'class' => 'launch_form', |
153 | | - 'style' => 'display:none;' |
154 | | - ) |
| 165 | + 'style' => 'display:none;', |
| 166 | + ] |
155 | 167 | ); |
156 | 168 |
|
157 | 169 | echo html_writer::script("<!-- |
|
161 | 173 | break; |
162 | 174 |
|
163 | 175 | case "rubricview": |
164 | | - if ($cm->modname == "forum") { |
165 | | - $isstudent = has_capability('mod/forum:replypost', $context); |
166 | | - } |
167 | | - elseif ($cm->modname == "quiz") { |
168 | | - $isstudent = !has_capability('mod/quiz:viewoverrides', $context); |
169 | | - } |
170 | | - else { |
171 | | - $isstudent = has_capability('mod/'.$cm->modname.':submit', $context); |
172 | | - } |
173 | | - |
174 | | - if ($isstudent) { |
175 | | - $tiiassignment = $DB->get_record('plagiarism_turnitin_config', array('cm' => $cm->id, 'name' => 'turnitin_assignid')); |
| 176 | + if (is_enrolled($context)) { |
| 177 | + $tiiassignment = $DB->get_record('plagiarism_turnitin_config', [ 'cm' => $cm->id, 'name' => 'turnitin_assignid' ]); |
176 | 178 |
|
177 | 179 | $user = new turnitin_user($USER->id, "Learner"); |
178 | 180 | $coursedata = turnitin_assignment::get_course_data($cm->course); |
|
181 | 183 | echo html_writer::tag( |
182 | 184 | 'div', |
183 | 185 | turnitin_view::output_lti_form_launch('rubric_view', 'Learner', $tiiassignment->value), |
184 | | - array( |
| 186 | + [ |
185 | 187 | 'class' => 'launch_form', |
186 | | - 'style' => 'display:none;' |
187 | | - ) |
| 188 | + 'style' => 'display:none;', |
| 189 | + ] |
188 | 190 | ); |
189 | 191 |
|
190 | 192 | echo html_writer::script("<!-- |
|
199 | 201 | $isstudent = ($cm->modname == "forum") ? has_capability($replypost, $context) : has_capability($submit, $context); |
200 | 202 |
|
201 | 203 | if ($userrole == 'Instructor' || $isstudent) { |
202 | | - $tiiassignment = $DB->get_record('plagiarism_turnitin_config', array('cm' => $cm->id, 'name' => 'turnitin_assignid')); |
| 204 | + $tiiassignment = $DB->get_record('plagiarism_turnitin_config', ['cm' => $cm->id, 'name' => 'turnitin_assignid']); |
203 | 205 |
|
204 | 206 | $user = new turnitin_user($USER->id, $userrole); |
205 | 207 | $coursedata = turnitin_assignment::get_course_data($cm->course); |
|
208 | 210 | echo html_writer::tag( |
209 | 211 | 'div', |
210 | 212 | turnitin_view::output_lti_form_launch('peermark_reviews', $userrole, $tiiassignment->value), |
211 | | - array( |
| 213 | + [ |
212 | 214 | 'class' => 'launch_form', |
213 | | - 'style' => 'display:none;' |
214 | | - ) |
| 215 | + 'style' => 'display:none;', |
| 216 | + ] |
215 | 217 | ); |
216 | 218 |
|
217 | 219 | echo html_writer::script("<!-- |
|
222 | 224 |
|
223 | 225 | case "actionuseragreement": |
224 | 226 | if (!confirm_sesskey()) { |
225 | | - throw new moodle_exception('invalidsesskey', 'error'); |
| 227 | + throw new \moodle_exception('invalidsesskey', 'error'); |
226 | 228 | } |
227 | 229 |
|
228 | 230 | $message = optional_param('message', '', PARAM_ALPHAEXT); |
229 | 231 |
|
230 | 232 | // Get the id from the plagiarism_turnitin_users table so we can update. |
231 | | - $turnitinuser = $DB->get_record('plagiarism_turnitin_users', array('userid' => $USER->id)); |
| 233 | + $turnitinuser = $DB->get_record('plagiarism_turnitin_users', ['userid' => $USER->id]); |
232 | 234 |
|
233 | 235 | // Build user object for update. |
234 | 236 | $eulauser = new stdClass(); |
|
250 | 252 |
|
251 | 253 | case "resubmit_event": |
252 | 254 | if (!confirm_sesskey()) { |
253 | | - throw new moodle_exception('invalidsesskey', 'error'); |
| 255 | + throw new \moodle_exception('invalidsesskey', 'error'); |
254 | 256 | } |
255 | 257 |
|
256 | | - $forumdata = optional_param('forumdata', '', PARAM_ALPHAEXT); |
257 | | - $forumpost = optional_param('forumpost', '', PARAM_ALPHAEXT); |
| 258 | + $forumdata = optional_param('forumdata', '', PARAM_ALPHANUMEXT); |
| 259 | + $forumpost = optional_param('forumpost', '', PARAM_BASE64); |
258 | 260 | $submissionid = required_param('submissionid', PARAM_INT); |
259 | 261 |
|
260 | 262 | $tiisubmission = new turnitin_submission($submissionid, |
261 | | - array('forumdata' => $forumdata, 'forumpost' => $forumpost)); |
| 263 | + ['forumdata' => $forumdata, 'forumpost' => $forumpost]); |
262 | 264 |
|
263 | 265 | if ($tiisubmission->recreate_submission_event()) { |
264 | | - $return = array('success' => true); |
| 266 | + $return = ['success' => true]; |
265 | 267 | } |
266 | 268 | break; |
267 | 269 |
|
268 | 270 | case "resubmit_events": |
269 | 271 |
|
270 | 272 | if (!confirm_sesskey()) { |
271 | | - throw new moodle_exception('invalidsesskey', 'error'); |
| 273 | + throw new \moodle_exception('invalidsesskey', 'error'); |
272 | 274 | } |
273 | 275 |
|
274 | | - $submissionids = optional_param_array('submission_ids', array(), PARAM_INT); |
| 276 | + $submissionids = optional_param_array('submission_ids', [], PARAM_INT); |
275 | 277 |
|
276 | | - $submissionids = optional_param_array('submission_ids', array(), PARAM_INT); |
277 | | - $errors = array(); |
| 278 | + $submissionids = optional_param_array('submission_ids', [], PARAM_INT); |
| 279 | + $errors = []; |
278 | 280 | $return['success'] = true; |
279 | 281 | foreach ($submissionids as $submissionid) { |
280 | 282 | $tiisubmission = new turnitin_submission($submissionid); |
|
288 | 290 |
|
289 | 291 | case "test_connection": |
290 | 292 | if (!confirm_sesskey()) { |
291 | | - throw new moodle_exception('invalidsesskey', 'error'); |
| 293 | + throw new \moodle_exception('invalidsesskey', 'error'); |
292 | 294 | } |
293 | | - $data = array("connection_status" => "fail", "msg" => get_string('connecttestcommerror', 'plagiarism_turnitin')); |
| 295 | + $data = ["connection_status" => "fail", "msg" => get_string('connecttestcommerror', 'plagiarism_turnitin')]; |
294 | 296 |
|
295 | 297 | $PAGE->set_context(context_system::instance()); |
296 | 298 | if (is_siteadmin()) { |
|
306 | 308 | if (empty($config)) { |
307 | 309 | $config = plagiarism_plugin_turnitin::plagiarism_turnitin_admin_config(); |
308 | 310 | } |
309 | | - if (!isset($config->plagiarism_turnitin_enablediagnostic)) { |
| 311 | + if (empty($config->plagiarism_turnitin_enablediagnostic)) { |
310 | 312 | $turnitincomms->set_diagnostic(0); |
311 | 313 | } else { |
312 | 314 | if ($config->plagiarism_turnitin_enablediagnostic != 2) { |
|
336 | 338 | header('Content-type: application/json; charset=utf-8'); |
337 | 339 | echo json_encode(turnitin_user::plagiarism_turnitin_getusers()); |
338 | 340 | } else { |
339 | | - throw new moodle_exception('accessdenied', 'admin'); |
| 341 | + throw new \moodle_exception('accessdenied', 'admin'); |
340 | 342 | } |
341 | 343 | break; |
342 | 344 |
|
|
353 | 355 | $instructor->set_user_values_from_tii(); |
354 | 356 | $instructorrubrics = $instructor->get_instructor_rubrics(); |
355 | 357 |
|
356 | | - $options = array(0 => get_string('norubric', 'plagiarism_turnitin')) + $instructorrubrics; |
| 358 | + $options = [0 => get_string('norubric', 'plagiarism_turnitin')] + $instructorrubrics; |
357 | 359 |
|
358 | 360 | // Get rubrics that are shared on the Turnitin account. |
359 | 361 | $turnitinclass = new turnitin_class($courseid); |
|
385 | 387 | } |
386 | 388 | } |
387 | 389 | } else { |
388 | | - $options = array(); |
| 390 | + $options = []; |
389 | 391 | } |
390 | 392 |
|
391 | 393 | echo json_encode($options); |
|
0 commit comments