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

Add configuration for activity module.

This commit is contained in:
Jane Adelmann 2022-04-27 17:42:46 +03:00
parent 9151e57228
commit 8d2814a419
No known key found for this signature in database
GPG Key ID: 4CCF39DF30B8AF72
3 changed files with 59 additions and 22 deletions

View File

@ -46,14 +46,14 @@ class plagiarism_pchkorg_setup_form extends moodleform {
$mform->addElement( $mform->addElement(
'select', 'select',
$setting = 'pchkorg_use', 'pchkorg_use',
get_string('pchkorg_use', 'plagiarism_pchkorg'), get_string('pchkorg_use', 'plagiarism_pchkorg'),
array(get_string('no'), get_string('yes')) array(get_string('no'), get_string('yes'))
); );
$mform->addHelpButton('pchkorg_use', 'pchkorg_use', 'plagiarism_pchkorg'); $mform->addHelpButton('pchkorg_use', 'pchkorg_use', 'plagiarism_pchkorg');
if (!isset($mform->exportValues()[$setting]) || is_null($mform->exportValues()[$setting])) { if (!isset($mform->exportValues()['pchkorg_use']) || is_null($mform->exportValues()['pchkorg_use'])) {
$mform->setDefault($setting, false); $mform->setDefault('pchkorg_use', false);
} }
$mform->addElement('password', 'pchkorg_token', get_string('pchkorg_token', 'plagiarism_pchkorg')); $mform->addElement('password', 'pchkorg_token', get_string('pchkorg_token', 'plagiarism_pchkorg'));
@ -63,7 +63,12 @@ class plagiarism_pchkorg_setup_form extends moodleform {
$mform->registerRule('check_pchkorg_min_percent', 'callback', 'pchkorg_check_pchkorg_min_percent'); $mform->registerRule('check_pchkorg_min_percent', 'callback', 'pchkorg_check_pchkorg_min_percent');
$mform->addElement('text', 'pchkorg_min_percent', get_string('pchkorg_min_percent', 'plagiarism_pchkorg')); $label = get_string('pchkorg_min_percent', 'plagiarism_pchkorg');
if (!empty($minpercent)) {
$label = \str_replace('X%', $minpercent . '%', $label);
}
$mform->addElement('text', 'pchkorg_min_percent', $label);
$mform->addHelpButton('pchkorg_min_percent', 'pchkorg_min_percent', 'plagiarism_pchkorg'); $mform->addHelpButton('pchkorg_min_percent', 'pchkorg_min_percent', 'plagiarism_pchkorg');
$mform->addRule('pchkorg_min_percent', null, 'numeric', null, 'client'); $mform->addRule('pchkorg_min_percent', null, 'numeric', null, 'client');
$mform->addRule('pchkorg_min_percent', get_string('pchkorg_min_percent_range', 'plagiarism_pchkorg'), 'check_pchkorg_min_percent'); $mform->addRule('pchkorg_min_percent', get_string('pchkorg_min_percent_range', 'plagiarism_pchkorg'), 'check_pchkorg_min_percent');

64
lib.php
View File

@ -215,15 +215,13 @@ display: inline-block;"
return; return;
} }
if (!isset($data->pchkorg_module_use)) {
return;
}
$fields = array('pchkorg_module_use', 'pchkorg_min_percent'); $fields = array('pchkorg_module_use', 'pchkorg_min_percent');
$records = $DB->get_records('plagiarism_pchkorg_config', array( $records = $DB->get_records('plagiarism_pchkorg_config', array(
'cm' => $data->coursemodule 'cm' => $data->coursemodule
)); ));
foreach ($fields as $field) { foreach ($fields as $field) {
$isfounded = false; $isfounded = false;
foreach ($records as $record) { foreach ($records as $record) {
@ -234,7 +232,7 @@ display: inline-block;"
break; break;
} }
} }
if (!$isfounded) { if (!$isfounded && isset($data->{$field})) {
$insert = new \stdClass(); $insert = new \stdClass();
$insert->cm = $data->coursemodule; $insert->cm = $data->coursemodule;
$insert->name = $field; $insert->name = $field;
@ -269,37 +267,71 @@ display: inline-block;"
if ('1' == $config && $enabled) { if ('1' == $config && $enabled) {
$defaultcmid = null; $defaultcmid = null;
$cm = optional_param('update', $defaultcmid, PARAM_INT); $cm = optional_param('update', $defaultcmid, PARAM_INT);
if (null !== $cm) { $minpercent = $pchkorgconfigmodel->get_system_config('pchkorg_min_percent');
if (null === $cm) {
if (!isset($mform->exportValues()['pchkorg_module_use'])
|| is_null($mform->exportValues()['pchkorg_module_use'])) {
$mform->setDefault('pchkorg_module_use', '1');
}
if (!isset($mform->exportValues()['pchkorg_min_percent'])
|| is_null($mform->exportValues()['pchkorg_min_percent'])) {
$mform->setDefault('pchkorg_min_percent', $minpercent);
}
} else {
$records = $DB->get_records('plagiarism_pchkorg_config', array( $records = $DB->get_records('plagiarism_pchkorg_config', array(
'cm' => $cm, 'cm' => $cm,
)); ));
if (!empty($records)) { if (!empty($records)) {
$record = end($records); foreach ($records as $record) {
$mform->setDefault($record->name, $record->value); $mform->setDefault($record->name, $record->value);
}
} }
} }
$mform->addElement('header', 'plagiarism_pchkorg', get_string('pluginname', 'plagiarism_pchkorg')); $mform->addElement(
'header',
'plagiarism_pchkorg',
get_string('pluginname', 'plagiarism_pchkorg')
);
$mform->addElement( $mform->addElement(
'select', 'select',
$setting = 'pchkorg_module_use', 'pchkorg_module_use',
get_string('pchkorg_module_use', 'plagiarism_pchkorg'), get_string('pchkorg_module_use', 'plagiarism_pchkorg'),
array(get_string('no'), get_string('yes')) array(get_string('no'), get_string('yes'))
); );
$mform->addHelpButton('pchkorg_module_use', 'pchkorg_module_use', 'plagiarism_pchkorg'); $mform->addHelpButton('pchkorg_module_use', 'pchkorg_module_use', 'plagiarism_pchkorg');
if (!isset($mform->exportValues()[$setting]) || is_null($mform->exportValues()[$setting])) { $canchangeminpercent = has_capability(capability::CHANGE_MIN_PERCENT_FILTER, $context);
$mform->setDefault($setting, '1'); if ($canchangeminpercent) {
$dissabledattribute = '';
} else {
$dissabledattribute = 'disabled="disabled"';
}
$mform->registerRule(
'check_pchkorg_min_percent',
'callback',
'pchkorg_check_pchkorg_min_percent'
);
$label = get_string('pchkorg_min_percent', 'plagiarism_pchkorg');
if (!empty($minpercent)) {
$label = \str_replace('X%', $minpercent . '%', $label);
} }
$mform->registerRule('check_pchkorg_min_percent', 'callback', 'pchkorg_check_pchkorg_min_percent'); $mform->addElement(
'text',
$mform->addElement('text', 'pchkorg_min_percent', get_string('pchkorg_min_percent', 'plagiarism_pchkorg')); 'pchkorg_min_percent',
$label,
$dissabledattribute
);
$mform->addHelpButton('pchkorg_min_percent', 'pchkorg_min_percent', 'plagiarism_pchkorg'); $mform->addHelpButton('pchkorg_min_percent', 'pchkorg_min_percent', 'plagiarism_pchkorg');
$mform->addRule('pchkorg_min_percent', null, 'numeric', null, 'client'); $mform->addRule('pchkorg_min_percent', null, 'numeric', null, 'client');
$mform->addRule('pchkorg_min_percent', get_string('pchkorg_min_percent_range', 'plagiarism_pchkorg'), 'check_pchkorg_min_percent'); $mform->addRule(
'pchkorg_min_percent',
get_string('pchkorg_min_percent_range', 'plagiarism_pchkorg'),
'check_pchkorg_min_percent'
);
$mform->setType('pchkorg_min_percent', PARAM_INT); $mform->setType('pchkorg_min_percent', PARAM_INT);
} }
} }

View File

@ -26,9 +26,9 @@ defined('MOODLE_INTERNAL') || die();
if (!isset($plugin)) { if (!isset($plugin)) {
$plugin = new stdClass(); $plugin = new stdClass();
} }
$plugin->version = 2021100101; $plugin->version = 2022042714;
$plugin->requires = 2017051500; // Requires Moodle 3.3 . $plugin->requires = 2017051500; // Requires Moodle 3.3 .
$plugin->release = 'v3.7.5'; $plugin->release = 'v3.8.1';
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;
$plugin->component = 'plagiarism_pchkorg'; $plugin->component = 'plagiarism_pchkorg';
$plugin->dependencies = array( $plugin->dependencies = array(