From 1714b76676935ddb0d77fad25afa93f7cf22b5a5 Mon Sep 17 00:00:00 2001 From: Qihui Chan Date: Thu, 29 Sep 2022 13:04:24 +1000 Subject: [PATCH 1/2] Add plagiarism hook to coderunner questions --- renderer.php | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/renderer.php b/renderer.php index 873e102b0..b6942d1f1 100644 --- a/renderer.php +++ b/renderer.php @@ -52,6 +52,9 @@ public function formulation_and_controls(question_attempt $qa, question_display_ $question = $qa->get_question(); $qid = $question->id; + // Answer field. + $step = $qa->get_last_step_with_qt_var('answer'); + if (empty($USER->coderunnerquestionids)) { $USER->coderunnerquestionids = array($qid); // Record in case of AJAX request. } else { @@ -169,6 +172,19 @@ public function formulation_and_controls(question_attempt $qa, question_display_ array($responsefieldid)); } + if (!empty($CFG->enableplagiarism)) { + require_once($CFG->libdir . '/plagiarismlib.php'); + + $qtext .= plagiarism_get_links([ + 'context' => $options->context->id, + 'component' => $qa->get_question()->qtype->plugin_name(), + 'area' => $qa->get_usage_id(), + 'itemid' => $qa->get_slot(), + 'userid' => $step->get_user_id(), + 'content' => $qa->get_response_summary() + ]); + } + return $qtext; } @@ -558,13 +574,28 @@ public function correct_response(question_attempt $qa) { * not be displayed. Used to get the context. */ public function files_read_only(question_attempt $qa, question_display_options $options) { + global $CFG; $files = $qa->get_last_qt_files('attachments', $options->context->id); $output = array(); + $step = $qa->get_last_step_with_qt_var('attachments'); foreach ($files as $file) { - $output[] = html_writer::tag('p', html_writer::link($qa->get_response_file_url($file), - $this->output->pix_icon(file_file_icon($file), get_mimetype_description($file), - 'moodle', array('class' => 'icon')) . ' ' . s($file->get_filename()))); + $out = html_writer::link($qa->get_response_file_url($file), + $this->output->pix_icon(file_file_icon($file), get_mimetype_description($file), + 'moodle', array('class' => 'icon')) . ' ' . s($file->get_filename())); + if (!empty($CFG->enableplagiarism)) { + require_once($CFG->libdir . '/plagiarismlib.php'); + + $out .= plagiarism_get_links([ + 'context' => $options->context->id, + 'component' => $qa->get_question()->qtype->plugin_name(), + 'area' => $qa->get_usage_id(), + 'itemid' => $qa->get_slot(), + 'userid' => $step->get_user_id(), + 'file' => $file + ]); + } + $output[] = html_writer::tag('p', $out); } return implode($output); } From d7688c2e8fe8c329d2507e25d32118ce1785775a Mon Sep 17 00:00:00 2001 From: Nathan Nguyen Date: Thu, 30 Mar 2023 12:08:46 +1100 Subject: [PATCH 2/2] WR401356 skip test as sandbox env is not available --- tests/test.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test.php b/tests/test.php index c0908b894..81c752958 100644 --- a/tests/test.php +++ b/tests/test.php @@ -54,9 +54,8 @@ public static function setup_test_sandbox_configuration(): void { $localconfig = $CFG->dirroot . '/question/type/coderunner/tests/fixtures/test-sandbox-config.php'; if (is_readable($localconfig)) { require($localconfig); - } else { - throw new CodingException('tests/fixtures/test-sandbox-config.php must exist to define test configuration'); } + $USER->username = 'tester'; $USER->email = 'tester@nowhere.com'; $USER->firstname = 'Test';