Add new options for min percent of plagiarism

This commit is contained in:
Jane Adelmann 2022-04-26 19:13:24 +03:00
parent 10b4ac6dd3
commit 9151e57228
No known key found for this signature in database
GPG Key ID: 4CCF39DF30B8AF72
5 changed files with 114 additions and 58 deletions

View File

@ -32,7 +32,6 @@ if (!defined('MOODLE_INTERNAL')) {
class capability
{
/**
* ENABLE
*/
@ -41,4 +40,8 @@ class capability
* VIEW_SIMILARITY
*/
const VIEW_SIMILARITY = 'plagiarism/pchkorg:viewsimilarity';
/**
* CHANGE_MIN_PERCENT_FILTER
*/
const CHANGE_MIN_PERCENT_FILTER = 'plagiarism/pchkorg:changeminpercentfilter';
}

View File

@ -45,4 +45,15 @@ $capabilities = array(
'coursecreator' => CAP_ALLOW
),
),
'plagiarism/pchkorg:changeminpercentfilter' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
'student' => CAP_ALLOW,
'coursecreator' => CAP_ALLOW
),
),
);

View File

@ -23,6 +23,12 @@
defined('MOODLE_INTERNAL') || die();
//function pchkorg_check_pchkorg_min_percent($value)
//{
// return 0 <= $value && $value < 100;
//}
/**
* Class defined plugin settings form.
*/
@ -55,6 +61,16 @@ class plagiarism_pchkorg_setup_form extends moodleform {
$mform->addRule('pchkorg_token', null, 'required', null, 'client');
$mform->setType('pchkorg_token', PARAM_TEXT);
$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'));
$mform->addHelpButton('pchkorg_min_percent', 'pchkorg_min_percent', 'plagiarism_pchkorg');
$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->setType('pchkorg_min_percent', PARAM_INT);
$this->add_action_buttons(true);
}
}

View File

@ -36,6 +36,9 @@ $string['pchkorg_submit'] = 'Submit';
$string['pchkorg_check_for_plagiarism_report'] = 'View report';
$string['savedconfigsuccess'] = 'Settings had been changed';
$string['pchkorg_check_for_plagiarism'] = 'Check for plagiarism';
$string['pchkorg_min_percent'] = 'Exclude sources below X% similarity';
$string['pchkorg_min_percent_help'] = 'Exclude sources below X% similarity';
$string['pchkorg_min_percent_range'] = 'Must be between 0 and 99';
$string['pchkorg_disclosure'] = 'Submission will be sent to <a target="_blank" href="https://plagiarismcheck.org/">PlagiarismCheck.org</a> for check.
<br />
By submitting assignment I agree with <a target="_blank" href="https://plagiarismcheck.org/terms-of-service/">Terms &amp; Conditions</a>
@ -70,3 +73,4 @@ $string['pchkorg_label_sent'] = 'ID: %s Sent';
$string['pchkorg_label_queued'] = 'In queue';
$string['pchkorg:enable'] = 'Allow to enable/disable PlagiarismCheck.org inside an activity';
$string['pchkorg:viewsimilarity'] = 'Allow to view similarity value from PlagiarismCheck.org';
$string['pchkorg:changeminpercentfilter'] = 'Allow changing "Exclude sources below X% similarity"';

36
lib.php
View File

@ -34,6 +34,11 @@ require_once(__DIR__ . '/classes/permissions/capability.class.php');
use plagiarism_pchkorg\classes\permissions\capability;
function pchkorg_check_pchkorg_min_percent($value)
{
return 0 <= $value && $value < 100;
}
/**
* Class plagiarism_plugin_pchkorg
*/
@ -213,21 +218,29 @@ display: inline-block;"
if (!isset($data->pchkorg_module_use)) {
return;
}
$fields = array('pchkorg_module_use', 'pchkorg_min_percent');
$records = $DB->get_records('plagiarism_pchkorg_config', array(
'cm' => $data->coursemodule
));
if (empty($records)) {
$insert = new \stdClass();
$insert->cm = $data->coursemodule;
$insert->name = 'pchkorg_module_use';
$insert->value = $data->pchkorg_module_use;
$DB->insert_record('plagiarism_pchkorg_config', $insert);
} else {
foreach ($fields as $field) {
$isfounded = false;
foreach ($records as $record) {
if ($record->name === $field) {
$isfounded = true;
$record->value = $data->{$record->name};
$DB->update_record('plagiarism_pchkorg_config', $record);
break;
}
}
if (!$isfounded) {
$insert = new \stdClass();
$insert->cm = $data->coursemodule;
$insert->name = $field;
$insert->value = $data->{$field};
$DB->insert_record('plagiarism_pchkorg_config', $insert);
}
}
}
@ -278,6 +291,15 @@ display: inline-block;"
if (!isset($mform->exportValues()[$setting]) || is_null($mform->exportValues()[$setting])) {
$mform->setDefault($setting, '1');
}
$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'));
$mform->addHelpButton('pchkorg_min_percent', 'pchkorg_min_percent', 'plagiarism_pchkorg');
$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->setType('pchkorg_min_percent', PARAM_INT);
}
}