Skip to content

Commit

Permalink
Add plagiarism hook to coderunner questions
Browse files Browse the repository at this point in the history
  • Loading branch information
Qihui Chan committed Jan 15, 2023
1 parent b8e7fb7 commit 65c535c
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -169,6 +172,18 @@ public function formulation_and_controls(question_attempt $qa, question_display_
array($responsefieldid));
}

if (!empty($options->readonly) && !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;
}

Expand Down Expand Up @@ -558,13 +573,27 @@ 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);
}
Expand Down

0 comments on commit 65c535c

Please sign in to comment.