Skip to content

Commit 13d5293

Browse files
author
Qihui Chan
committed
Add plagiarism hook to coderunner questions
1 parent b8e7fb7 commit 13d5293

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

renderer.php

+34-4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public function formulation_and_controls(question_attempt $qa, question_display_
5252

5353
$question = $qa->get_question();
5454
$qid = $question->id;
55+
// Answer field.
56+
$step = $qa->get_last_step_with_qt_var('answer');
57+
5558
if (empty($USER->coderunnerquestionids)) {
5659
$USER->coderunnerquestionids = array($qid); // Record in case of AJAX request.
5760
} else {
@@ -126,6 +129,19 @@ public function formulation_and_controls(question_attempt $qa, question_display_
126129
$currentanswer = "\n" . $currentanswer;
127130
}
128131

132+
if (!empty($options->readonly) && !empty($CFG->enableplagiarism)) {
133+
require_once($CFG->libdir . '/plagiarismlib.php');
134+
135+
$currentanswer .= plagiarism_get_links([
136+
'context' => $options->context->id,
137+
'component' => $qa->get_question()->qtype->plugin_name(),
138+
'area' => $qa->get_usage_id(),
139+
'itemid' => $qa->get_slot(),
140+
'userid' => $step->get_user_id(),
141+
'content' => $qa->get_response_summary()
142+
]);
143+
}
144+
129145
$rows = isset($question->answerboxlines) ? $question->answerboxlines : constants::DEFAULT_NUM_ROWS;
130146
$taattributes = $this->answerbox_attributes($responsefieldname, $rows,
131147
$question, $currentlanguage, $options->readonly);
@@ -558,13 +574,27 @@ public function correct_response(question_attempt $qa) {
558574
* not be displayed. Used to get the context.
559575
*/
560576
public function files_read_only(question_attempt $qa, question_display_options $options) {
577+
global $CFG;
561578
$files = $qa->get_last_qt_files('attachments', $options->context->id);
562579
$output = array();
563-
580+
$step = $qa->get_last_step_with_qt_var('attachments');
564581
foreach ($files as $file) {
565-
$output[] = html_writer::tag('p', html_writer::link($qa->get_response_file_url($file),
566-
$this->output->pix_icon(file_file_icon($file), get_mimetype_description($file),
567-
'moodle', array('class' => 'icon')) . ' ' . s($file->get_filename())));
582+
$out = html_writer::link($qa->get_response_file_url($file),
583+
$this->output->pix_icon(file_file_icon($file), get_mimetype_description($file),
584+
'moodle', array('class' => 'icon')) . ' ' . s($file->get_filename()));
585+
if (!empty($CFG->enableplagiarism)) {
586+
require_once($CFG->libdir . '/plagiarismlib.php');
587+
588+
$out .= plagiarism_get_links([
589+
'context' => $options->context->id,
590+
'component' => $qa->get_question()->qtype->plugin_name(),
591+
'area' => $qa->get_usage_id(),
592+
'itemid' => $qa->get_slot(),
593+
'userid' => $step->get_user_id(),
594+
'file' => $file
595+
]);
596+
}
597+
$output[] = html_writer::tag('p', $out);
568598
}
569599
return implode($output);
570600
}

0 commit comments

Comments
 (0)