diff --git a/renderer.php b/renderer.php index 2e36f7ca..69c493b0 100644 --- a/renderer.php +++ b/renderer.php @@ -48,6 +48,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 = [$qid]; // Record in case of AJAX request. } else { @@ -188,6 +191,19 @@ public function formulation_and_controls(question_attempt $qa, question_display_ ); } + 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; } @@ -647,19 +663,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 = []; + $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', - ['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); } diff --git a/tests/test.php b/tests/test.php index d81c9c1a..4af18199 100644 --- a/tests/test.php +++ b/tests/test.php @@ -59,9 +59,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 coding_exception('tests/fixtures/test-sandbox-config.php must exist to define test configuration'); } + $USER->username = 'tester'; $USER->email = 'tester@nowhere.com'; $USER->firstname = 'Test';