Skip to content

Add plagiarism hook to coderunner questions #149

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
43 changes: 34 additions & 9 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions tests/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]';
$USER->firstname = 'Test';
Expand Down