From 17bcf5747fad6a9e40d4374357fd325b632f2ad6 Mon Sep 17 00:00:00 2001 From: Jane Adelmann Date: Wed, 4 May 2022 20:20:37 +0300 Subject: [PATCH] Add new filters for assignment --- .phpcs | 59 --------------------- classes/plagiarism_pchkorg_api_provider.php | 26 ++++++++- classes/plagiarism_pchkorg_config_model.php | 20 +++---- form/plagiarism_pchkorg_setup_form.php | 33 ------------ lib.php | 59 ++++++++++++++++++--- version.php | 4 +- 6 files changed, 87 insertions(+), 114 deletions(-) delete mode 100644 .phpcs diff --git a/.phpcs b/.phpcs deleted file mode 100644 index d715535..0000000 --- a/.phpcs +++ /dev/null @@ -1,59 +0,0 @@ -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__) - ); diff --git a/classes/plagiarism_pchkorg_api_provider.php b/classes/plagiarism_pchkorg_api_provider.php index 9c713fa..3830c0f 100644 --- a/classes/plagiarism_pchkorg_api_provider.php +++ b/classes/plagiarism_pchkorg_api_provider.php @@ -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); diff --git a/classes/plagiarism_pchkorg_config_model.php b/classes/plagiarism_pchkorg_config_model.php index 5cbc88f..cfd7e50 100644 --- a/classes/plagiarism_pchkorg_config_model.php +++ b/classes/plagiarism_pchkorg_config_model.php @@ -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]; diff --git a/form/plagiarism_pchkorg_setup_form.php b/form/plagiarism_pchkorg_setup_form.php index 65035ae..0d8bd73 100644 --- a/form/plagiarism_pchkorg_setup_form.php +++ b/form/plagiarism_pchkorg_setup_form.php @@ -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); } diff --git a/lib.php b/lib.php index c2222b4..b448dbb 100644 --- a/lib.php +++ b/lib.php @@ -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(), diff --git a/version.php b/version.php index 58cac0c..8c3f3a7 100644 --- a/version.php +++ b/version.php @@ -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(