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:
parent
c071dae607
commit
5a44f324ae
120
lib.php
120
lib.php
@ -192,7 +192,67 @@ function plagiarism_pchkorg_coursemodule_standard_elements($formwrapper, $mform)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -548,65 +608,7 @@ display: inline-block;"
|
||||
* @throws dml_exception
|
||||
*/
|
||||
public function save_form_elements($data) {
|
||||
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 plagiarism_pchkorg_coursemodule_edit_post_actions($data, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,9 +26,9 @@ defined('MOODLE_INTERNAL') || die();
|
||||
if (!isset($plugin)) {
|
||||
$plugin = new stdClass();
|
||||
}
|
||||
$plugin->version = 2022092613;
|
||||
$plugin->version = 2022092718;
|
||||
$plugin->requires = 2020061501; // Requires Moodle 3.9 .
|
||||
$plugin->release = 'v3.11.1';
|
||||
$plugin->release = 'v3.11.2';
|
||||
$plugin->component = 'plagiarism_pchkorg';
|
||||
$plugin->maturity = MATURITY_STABLE;
|
||||
$plugin->dependencies = array(
|
||||
|
Loading…
Reference in New Issue
Block a user