Add new filters for assignment

This commit is contained in:
Jane Adelmann 2022-05-04 20:20:37 +03:00
parent 3917e133c4
commit 17bcf5747f
No known key found for this signature in database
GPG Key ID: 4CCF39DF30B8AF72
6 changed files with 87 additions and 114 deletions

59
.phpcs
View File

@ -1,59 +0,0 @@
<?php
/*
* This file is part of the Moodle Plugin CI package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Copyright (c) 2017 Blackboard Inc. (http://www.blackboard.com)
* License http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$header = <<<'EOF'
This file is part of the Moodle Plugin CI package.
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
Copyright (c) 2018 Blackboard Inc. (http://www.blackboard.com)
License http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
EOF;
return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'combine_consecutive_unsets' => true,
'combine_consecutive_issets' => true,
'general_phpdoc_annotation_remove' => ['expectedException', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp'],
'header_comment' => ['header' => $header],
'heredoc_to_nowdoc' => true,
'no_extra_consecutive_blank_lines' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'],
'no_short_echo_tag' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_imports' => true,
'php_unit_strict' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_order' => true,
'semicolon_after_instruction' => true,
'strict_comparison' => true,
'strict_param' => true,
'binary_operator_spaces' => ['align_equals' => true, 'align_double_arrow' => true],
'align_multiline_comment' => true,
'yoda_style' => false,
'compact_nullable_typehint' => true,
'native_function_invocation' => false,
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude('tests/Fixture')
->exclude('moodle')
->exclude('moodledata')
->name('moodle-plugin-ci')
->in(__DIR__)
);

View File

@ -84,6 +84,7 @@ class plagiarism_pchkorg_api_provider {
* @param $authorhash
* @param $cousereid
* @param $assignmentid
* @param $assignmentname
* @param $submissionid
* @param $attachmentid
* @param $content
@ -96,6 +97,7 @@ class plagiarism_pchkorg_api_provider {
$authorhash,
$cousereid,
$assignmentid,
$assignmentname,
$submissionid,
$attachmentid,
$content,
@ -114,6 +116,7 @@ class plagiarism_pchkorg_api_provider {
$authorhash,
$cousereid,
$assignmentid,
$assignmentname,
$submissionid,
$attachmentid,
$content,
@ -153,6 +156,7 @@ class plagiarism_pchkorg_api_provider {
* @param $authorhash
* @param $cousereid
* @param $assignmentid
* @param $assignmentname
* @param $submissionid
* @param $attachmentid
* @param $content
@ -165,6 +169,7 @@ class plagiarism_pchkorg_api_provider {
$authorhash,
$cousereid,
$assignmentid,
$assignmentname,
$submissionid,
$attachmentid,
$content,
@ -179,6 +184,7 @@ class plagiarism_pchkorg_api_provider {
$body .= $this->get_part('hash', $authorhash, $boundary);
$body .= $this->get_part('course_id', $cousereid, $boundary);
$body .= $this->get_part('assignment_id', $assignmentid, $boundary);
$body .= $this->get_part('assignment_name', $assignmentname, $boundary);
$body .= $this->get_part('submission_id', $submissionid, $boundary);
$body .= $this->get_part('attachment_id', $attachmentid, $boundary);
$body .= $this->get_part('filename', $filename, $boundary);
@ -196,16 +202,24 @@ class plagiarism_pchkorg_api_provider {
}
/**
* Send text to the service for check.
* Send text for originality check.
*
* @param $authorhash
* @param $cousereid
* @param $assignmentid
* @param $assignmentname
* @param $submissionid
* @param $attachmentid
* @param $content
* @param $mime
* @param $filename
*
* @return |null
*/
public function send_text(
$cousereid,
$assignmentid,
$assignmentname,
$submissionid,
$attachmentid,
$content,
@ -222,6 +236,7 @@ class plagiarism_pchkorg_api_provider {
$boundary,
$cousereid,
$assignmentid,
$assignmentname,
$submissionid,
$attachmentid,
$content,
@ -327,9 +342,14 @@ class plagiarism_pchkorg_api_provider {
}
/**
* Build body for http-request.
* Build HTTP body of request.
*
* @param $boundary
* @param $cousereid
* @param $assignmentid
* @param $assignmentname
* @param $submissionid
* @param $attachmentid
* @param $content
* @param $mime
* @param $filename
@ -339,6 +359,7 @@ class plagiarism_pchkorg_api_provider {
$boundary,
$cousereid,
$assignmentid,
$assignmentname,
$submissionid,
$attachmentid,
$content,
@ -354,6 +375,7 @@ class plagiarism_pchkorg_api_provider {
$body .= $this->get_part('skip_percentage_words_validation', '1', $boundary);
$body .= $this->get_part('course_id', $cousereid, $boundary);
$body .= $this->get_part('assignment_id', $assignmentid, $boundary);
$body .= $this->get_part('assignment_name', $assignmentname, $boundary);
$body .= $this->get_part('submission_id', $submissionid, $boundary);
$body .= $this->get_part('attachment_id', $attachmentid, $boundary);
$body .= $this->get_part('lms', 'moodle', $boundary);

View File

@ -66,13 +66,13 @@ class plagiarism_pchkorg_config_model {
/**
*
* Check if plugin is enable for some specific module.
* Result is static.
* Get value for search setting
*
* @param $module
* @param $name
* @return bool
*/
public function get_min_percent_for_module($module) {
public function get_filter_for_module($module, $name) {
global $DB;
static $resultmap = array();
@ -80,21 +80,17 @@ class plagiarism_pchkorg_config_model {
if (!array_key_exists($module, $resultmap)) {
$configs = $DB->get_records('plagiarism_pchkorg_config', array(
'cm' => $module,
'name' => 'pchkorg_min_percent'
'name' => $name
));
$minpercent = null;
$value = null;
foreach ($configs as $record) {
switch ($record->name) {
case 'pchkorg_min_percent':
$minpercent = $record->value;
break;
default:
break;
if ($record->name === $name) {
$value = $record->value;
}
}
$resultmap[$module] = $minpercent;
$resultmap[$module] = $value;
}
return $resultmap[$module];

View File

@ -49,18 +49,6 @@ class plagiarism_pchkorg_setup_form extends moodleform {
if (!isset($mform->exportValues()['pchkorg_use']) || is_null($mform->exportValues()['pchkorg_use'])) {
$mform->setDefault('pchkorg_use', false);
}
if (!isset($mform->exportValues()['pchkorg_exclude_self_plagiarism'])
|| is_null($mform->exportValues()['pchkorg_exclude_self_plagiarism'])) {
$mform->setDefault('pchkorg_exclude_self_plagiarism', 1);
}
if (!isset($mform->exportValues()['pchkorg_include_referenced'])
|| is_null($mform->exportValues()['pchkorg_include_referenced'])) {
$mform->setDefault('pchkorg_include_referenced', 0);
}
if (!isset($mform->exportValues()['pchkorg_include_citation'])
|| is_null($mform->exportValues()['pchkorg_include_citation'])) {
$mform->setDefault('pchkorg_include_citation', 0);
}
$mform->addElement('password', 'pchkorg_token', get_string('pchkorg_token', 'plagiarism_pchkorg'));
$mform->addHelpButton('pchkorg_token', 'pchkorg_token', 'plagiarism_pchkorg');
@ -80,27 +68,6 @@ class plagiarism_pchkorg_setup_form extends moodleform {
$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->addElement(
'select',
'pchkorg_exclude_self_plagiarism',
get_string('pchkorg_exclude_self_plagiarism', 'plagiarism_pchkorg'),
array(get_string('no'), get_string('yes'))
);
$mform->addElement(
'select',
'pchkorg_include_referenced',
get_string('pchkorg_include_referenced', 'plagiarism_pchkorg'),
array(get_string('no'), get_string('yes'))
);
$mform->addElement(
'select',
'pchkorg_include_citation',
get_string('pchkorg_include_citation', 'plagiarism_pchkorg'),
array(get_string('no'), get_string('yes'))
);
$this->add_action_buttons(true);
}

59
lib.php
View File

@ -285,15 +285,24 @@ display: inline-block;"
$cm = optional_param('update', $defaultcmid, PARAM_INT);
$minpercent = $pchkorgconfigmodel->get_system_config('pchkorg_min_percent');
if (!isset($mform->exportValues()['pchkorg_exclude_self_plagiarism'])
|| is_null($mform->exportValues()['pchkorg_exclude_self_plagiarism'])) {
$mform->setDefault('pchkorg_exclude_self_plagiarism', 1);
}
if (!isset($mform->exportValues()['pchkorg_include_referenced'])
|| is_null($mform->exportValues()['pchkorg_include_referenced'])) {
$mform->setDefault('pchkorg_include_referenced', 0);
}
if (!isset($mform->exportValues()['pchkorg_include_citation'])
|| is_null($mform->exportValues()['pchkorg_include_citation'])) {
$mform->setDefault('pchkorg_include_citation', 0);
}
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(
'cm' => $cm,
@ -348,6 +357,27 @@ display: inline-block;"
'check_pchkorg_min_percent'
);
$mform->setType('pchkorg_min_percent', PARAM_INT);
$mform->addElement(
'select',
'pchkorg_exclude_self_plagiarism',
get_string('pchkorg_exclude_self_plagiarism', 'plagiarism_pchkorg'),
array(get_string('no'), get_string('yes'))
);
$mform->addElement(
'select',
'pchkorg_include_referenced',
get_string('pchkorg_include_referenced', 'plagiarism_pchkorg'),
array(get_string('no'), get_string('yes'))
);
$mform->addElement(
'select',
'pchkorg_include_citation',
get_string('pchkorg_include_citation', 'plagiarism_pchkorg'),
array(get_string('no'), get_string('yes'))
);
}
}
@ -617,13 +647,26 @@ display: inline-block;"
// Filter for future search.
$systemminpercent = $pchkorgconfigmodel->get_system_config('pchkorg_min_percent');
// Module filter value has a bigger priority then system config value.
$moduleminpercent = $pchkorgconfigmodel->get_min_percent_for_module($cm->id);
$moduleminpercent = $pchkorgconfigmodel->get_filter_for_module($cm->id, 'source_min_percent');
if ($moduleminpercent) {
$minpercent = $moduleminpercent;
} else {
$minpercent = $systemminpercent;
}
$filters = [];
$filters = [
'include_references' => $pchkorgconfigmodel->get_filter_for_module(
$cm->id,
'include_references'
),
'include_quotes' => $pchkorgconfigmodel->get_filter_for_module(
$cm->id,
'include_quotes'
),
'exclude_self_plagiarism' => $pchkorgconfigmodel->get_filter_for_module(
$cm->id,
'exclude_self_plagiarism'
),
];
if ($minpercent) {
$filters['source_min_percent'] = $minpercent;
}
@ -637,6 +680,7 @@ display: inline-block;"
$apiprovider->user_email_to_hash($user->email),
$cm->course,
$cm->id,
$cm->name,
$moodletextsubmission->id,
$moodletextsubmission->id,
html_to_text($content, 75, false),
@ -648,6 +692,7 @@ display: inline-block;"
$textid = $apiprovider->send_text(
$cm->course,
$cm->id,
$cm->name,
$moodletextsubmission->id,
$moodletextsubmission->id,
html_to_text($content, 75, false),
@ -681,6 +726,7 @@ display: inline-block;"
$apiprovider->user_email_to_hash($user->email),
$cm->course,
$cm->id,
$cm->name,
$moodlesubmission->id,
$file->get_id(),
$file->get_content(),
@ -703,6 +749,7 @@ display: inline-block;"
$textid = $apiprovider->send_text(
$cm->course,
$cm->id,
$cm->name,
$moodlesubmission->id,
$file->get_id(),
$file->get_content(),

View File

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