Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plagiarism hook to coderunner questions #152

Open
wants to merge 1 commit into
base: MOODLE_3X_STABLE
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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