1
0
mirror of https://github.com/PlagiarismCheck/moodle-plagiarism_pchkorg.git synced 2024-12-22 12:10:08 +00:00

Add support for moodle 4.0.2

This commit is contained in:
Jane Adelmann 2022-09-27 18:41:01 +03:00
parent c071dae607
commit 5a44f324ae
No known key found for this signature in database
GPG Key ID: 4CCF39DF30B8AF72
2 changed files with 70 additions and 68 deletions

134
lib.php
View File

@ -192,7 +192,67 @@ function plagiarism_pchkorg_coursemodule_standard_elements($formwrapper, $mform)
function plagiarism_pchkorg_coursemodule_edit_post_actions($data, $course) function plagiarism_pchkorg_coursemodule_edit_post_actions($data, $course)
{ {
global $DB;
$pchkorgconfigmodel = new plagiarism_pchkorg_config_model();
$config = $pchkorgconfigmodel->get_system_config('pchkorg_use');
if ('1' != $config) {
return;
}
$fields = array(
'pchkorg_module_use',
'pchkorg_min_percent',
'pchkorg_include_citation',
'pchkorg_include_referenced',
'pchkorg_exclude_self_plagiarism',
'pchkorg_student_can_see_widget',
'pchkorg_student_can_see_report'
);
$records = $DB->get_records('plagiarism_pchkorg_config', array(
'cm' => $data->coursemodule
));
$context = context_module::instance($data->coursemodule);
$canchangeminpercent = has_capability(capability::CHANGE_MIN_PERCENT_FILTER, $context);
foreach ($fields as $field) {
$isfounded = false;
foreach ($records as $record) {
if ($record->name === $field) {
$isfounded = true;
if ($field === 'pchkorg_min_percent' && !$canchangeminpercent) {
$DB->delete_records('plagiarism_pchkorg_config', array('id' => $record->id));
break;
}
if ($field === 'pchkorg_min_percent' && 0 == $data->{$record->name}) {
$DB->delete_records('plagiarism_pchkorg_config', array('id' => $record->id));
break;
}
$record->value = $data->{$record->name};
$DB->update_record('plagiarism_pchkorg_config', $record);
break;
}
}
if (!$isfounded && isset($data->{$field})) {
if ($field === 'pchkorg_min_percent' && !$canchangeminpercent) {
continue;
}
if ($field === 'pchkorg_min_percent' && 0 == $data->{$field}) {
continue;
}
$insert = new \stdClass();
$insert->cm = $data->coursemodule;
$insert->name = $field;
$insert->value = $data->{$field};
$DB->insert_record('plagiarism_pchkorg_config', $insert);
}
}
return $data;
} }
/** /**
@ -390,27 +450,27 @@ window.plagiarism_check_full_report = function (action, token) {
const form = document.createElement('form'); const form = document.createElement('form');
const element1 = document.createElement('input'); const element1 = document.createElement('input');
const element2 = document.createElement('input'); const element2 = document.createElement('input');
form.method = 'POST'; form.method = 'POST';
form.target = '_blank'; form.target = '_blank';
form.action = action; form.action = action;
element1.value = 'moodle'; element1.value = 'moodle';
element1.name = 'lms-type'; element1.name = 'lms-type';
element1.type = 'hidden'; element1.type = 'hidden';
form.appendChild(element1); form.appendChild(element1);
element2.value = token; element2.value = token;
element2.name = 'token'; element2.name = 'token';
element2.type = 'hidden'; element2.type = 'hidden';
form.appendChild(element2); form.appendChild(element2);
document.body.appendChild(form); document.body.appendChild(form);
form.submit(); form.submit();
}; };
require(['jquery'], function ($) { require(['jquery'], function ($) {
$(function () { $(function () {
var spans = window.document.getElementsByClassName('plagiarism-pchkorg-widget'); var spans = window.document.getElementsByClassName('plagiarism-pchkorg-widget');
for (var s in spans) { for (var s in spans) {
@ -453,7 +513,7 @@ require(['jquery'], function ($) {
} }
} }
} }
$(window.document.body).on('click', '.plagiarism-pchkorg-widget', function(e) { $(window.document.body).on('click', '.plagiarism-pchkorg-widget', function(e) {
var id = $(e.target).closest('a').attr('data-id') var id = $(e.target).closest('a').attr('data-id')
if (id) { if (id) {
@ -548,65 +608,7 @@ display: inline-block;"
* @throws dml_exception * @throws dml_exception
*/ */
public function save_form_elements($data) { public function save_form_elements($data) {
global $DB; return plagiarism_pchkorg_coursemodule_edit_post_actions($data, null);
$pchkorgconfigmodel = new plagiarism_pchkorg_config_model();
$config = $pchkorgconfigmodel->get_system_config('pchkorg_use');
if ('1' != $config) {
return;
}
$fields = array(
'pchkorg_module_use',
'pchkorg_min_percent',
'pchkorg_include_citation',
'pchkorg_include_referenced',
'pchkorg_exclude_self_plagiarism',
'pchkorg_student_can_see_widget',
'pchkorg_student_can_see_report'
);
$records = $DB->get_records('plagiarism_pchkorg_config', array(
'cm' => $data->coursemodule
));
$context = context_module::instance($data->coursemodule);
$canchangeminpercent = has_capability(capability::CHANGE_MIN_PERCENT_FILTER, $context);
foreach ($fields as $field) {
$isfounded = false;
foreach ($records as $record) {
if ($record->name === $field) {
$isfounded = true;
if ($field === 'pchkorg_min_percent' && !$canchangeminpercent) {
$DB->delete_records('plagiarism_pchkorg_config', array('id' => $record->id));
break;
}
if ($field === 'pchkorg_min_percent' && 0 == $data->{$record->name}) {
$DB->delete_records('plagiarism_pchkorg_config', array('id' => $record->id));
break;
}
$record->value = $data->{$record->name};
$DB->update_record('plagiarism_pchkorg_config', $record);
break;
}
}
if (!$isfounded && isset($data->{$field})) {
if ($field === 'pchkorg_min_percent' && !$canchangeminpercent) {
continue;
}
if ($field === 'pchkorg_min_percent' && 0 == $data->{$field}) {
continue;
}
$insert = new \stdClass();
$insert->cm = $data->coursemodule;
$insert->name = $field;
$insert->value = $data->{$field};
$DB->insert_record('plagiarism_pchkorg_config', $insert);
}
}
} }
/** /**

View File

@ -26,9 +26,9 @@ defined('MOODLE_INTERNAL') || die();
if (!isset($plugin)) { if (!isset($plugin)) {
$plugin = new stdClass(); $plugin = new stdClass();
} }
$plugin->version = 2022092613; $plugin->version = 2022092718;
$plugin->requires = 2020061501; // Requires Moodle 3.9 . $plugin->requires = 2020061501; // Requires Moodle 3.9 .
$plugin->release = 'v3.11.1'; $plugin->release = 'v3.11.2';
$plugin->component = 'plagiarism_pchkorg'; $plugin->component = 'plagiarism_pchkorg';
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;
$plugin->dependencies = array( $plugin->dependencies = array(