From 39306ca802d0f0b7f521e24b9234eafd77cfd153 Mon Sep 17 00:00:00 2001 From: Jane Adelmann Date: Fri, 22 Jul 2022 10:20:38 +0300 Subject: [PATCH] Add new option: teachers allow students to see the result --- classes/plagiarism_pchkorg_config_model.php | 72 +++++++++++++++++++++ form/plagiarism_pchkorg_setup_form.php | 4 -- lang/en/plagiarism_pchkorg.php | 3 + lib.php | 59 +++++++++++++++-- version.php | 8 +-- 5 files changed, 134 insertions(+), 12 deletions(-) diff --git a/classes/plagiarism_pchkorg_config_model.php b/classes/plagiarism_pchkorg_config_model.php index 6164f37..08c350d 100644 --- a/classes/plagiarism_pchkorg_config_model.php +++ b/classes/plagiarism_pchkorg_config_model.php @@ -64,6 +64,78 @@ class plagiarism_pchkorg_config_model { return $resultmap[$module]; } + /** + * + * Check if plugin show widget to student. + * Result is static. + * + * @param $module + * @return bool + */ + public function show_widget_for_student($module) { + global $DB; + + static $resultmap = array(); + // This will be called only once per module. + if (!array_key_exists($module, $resultmap)) { + $configs = $DB->get_records('plagiarism_pchkorg_config', array( + 'cm' => $module, + 'name' => 'pchkorg_student_can_see_widget' + )); + + $enabled = null; + foreach ($configs as $record) { + switch ($record->name) { + case 'pchkorg_student_can_see_widget': + $enabled = '1' == $record->value; + break; + default: + break; + } + } + + $resultmap[$module] = $enabled; + } + + return $resultmap[$module]; + } + + /** + * + * Check if plugin show report to student. + * Result is static. + * + * @param $module + * @return bool + */ + public function show_report_for_student($module) { + global $DB; + + static $resultmap = array(); + // This will be called only once per module. + if (!array_key_exists($module, $resultmap)) { + $configs = $DB->get_records('plagiarism_pchkorg_config', array( + 'cm' => $module, + 'name' => 'pchkorg_student_can_see_report' + )); + + $enabled = null; + foreach ($configs as $record) { + switch ($record->name) { + case 'pchkorg_student_can_see_report': + $enabled = '1' == $record->value; + break; + default: + break; + } + } + + $resultmap[$module] = $enabled; + } + + return $resultmap[$module]; + } + /** * * Get value for search setting diff --git a/form/plagiarism_pchkorg_setup_form.php b/form/plagiarism_pchkorg_setup_form.php index cee17f7..8767b15 100644 --- a/form/plagiarism_pchkorg_setup_form.php +++ b/form/plagiarism_pchkorg_setup_form.php @@ -46,10 +46,6 @@ class plagiarism_pchkorg_setup_form extends moodleform { ); $mform->addHelpButton('pchkorg_use', 'pchkorg_use', 'plagiarism_pchkorg'); - if (!isset($mform->exportValues()['pchkorg_use']) || is_null($mform->exportValues()['pchkorg_use'])) { - $mform->setDefault('pchkorg_use', false); - } - $mform->addElement('password', 'pchkorg_token', get_string('pchkorg_token', 'plagiarism_pchkorg')); $mform->addHelpButton('pchkorg_token', 'pchkorg_token', 'plagiarism_pchkorg'); $mform->addRule('pchkorg_token', null, 'required', null, 'client'); diff --git a/lang/en/plagiarism_pchkorg.php b/lang/en/plagiarism_pchkorg.php index c00573b..56bb89f 100644 --- a/lang/en/plagiarism_pchkorg.php +++ b/lang/en/plagiarism_pchkorg.php @@ -55,6 +55,9 @@ $string['pchkorg_debug_not_member'] = 'User is not a member of plagiarismcheck g $string['pchkorg_debug_user_has_no_capability'] = 'User does not have capability'; $string['pchkorg_debug_no_check'] = 'There is no checks for this activity'; $string['pchkorg_debug_status_error'] = 'Some error for this file'; +$string['pchkorg_debug_student_not_allowed_see_widget'] = 'Students can not see a similarity score'; +$string['pchkorg_student_can_see_widget'] = 'Students can see a similarity score'; +$string['pchkorg_student_can_see_report'] = 'Students can access a similarity report'; $string['pchkorg_disclosure'] = 'Submission will be sent to PlagiarismCheck.org for check.
By submitting assignment I agree with Terms & Conditions diff --git a/lib.php b/lib.php index 70cb335..3f90a90 100644 --- a/lib.php +++ b/lib.php @@ -83,6 +83,17 @@ function plagiarism_pchkorg_coursemodule_standard_elements($formwrapper, $mform) $mform->setDefault('pchkorg_include_citation', 0); } + if (!isset($exportedvalues['pchkorg_student_can_see_report']) || is_null( + $exportedvalues['pchkorg_student_can_see_report'] + )) { + $mform->setDefault('pchkorg_student_can_see_report', 1); + } + if (!isset($exportedvalues['pchkorg_student_can_see_widget']) || is_null( + $exportedvalues['pchkorg_student_can_see_widget'] + )) { + $mform->setDefault('pchkorg_student_can_see_widget', 1); + } + if (null === $cm) { if (!isset($exportedvalues['pchkorg_module_use']) || is_null($exportedvalues['pchkorg_module_use'])) { @@ -161,6 +172,21 @@ function plagiarism_pchkorg_coursemodule_standard_elements($formwrapper, $mform) get_string('pchkorg_include_citation', 'plagiarism_pchkorg'), array(get_string('no'), get_string('yes')) ); + + + $mform->addElement( + 'select', + 'pchkorg_student_can_see_widget', + get_string('pchkorg_student_can_see_widget', 'plagiarism_pchkorg'), + array(get_string('no'), get_string('yes')) + ); + + $mform->addElement( + 'select', + 'pchkorg_student_can_see_report', + get_string('pchkorg_student_can_see_report', 'plagiarism_pchkorg'), + array(get_string('no'), get_string('yes')) + ); } } @@ -221,7 +247,6 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin { $component = !empty($linkarray['component']) ? $linkarray['component'] : ''; if ($cmid === null && $component == 'qtype_essay' && !empty($linkarray['area'])) { $questions = question_engine::load_questions_usage_by_activity($linkarray['area']); - $context = $questions->get_owning_context(); if ($cmid === null && $context->contextlevel == CONTEXT_MODULE) { $cmid = $context->instanceid; @@ -238,8 +263,21 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin { $isdebugenabled ); } + $roleDatas = get_user_roles($context, $USER->id, true); + $roles = []; + foreach ($roleDatas as $rolesData) { + $roles[] = strtolower($rolesData->shortname); + } + // Moodle has multiple roles in courses. + $isstudent = in_array('student', $roles) + && !in_array('teacher', $roles) + && !in_array('editingteacher', $roles) + && !in_array('managerteacher', $roles); $canview = has_capability(capability::VIEW_SIMILARITY, $context); + + $pchkorgconfigmodel->show_widget_for_student($cmid); + if (!$canview) { return $this->exit_message( get_string('pchkorg_debug_user_has_no_permission', 'plagiarism_pchkorg'), @@ -255,6 +293,16 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin { ); } + // Widget for student is disabled. + if ($isstudent && $pchkorgconfigmodel->show_widget_for_student($cmid) === false) { + return $this->exit_message( + get_string('pchkorg_debug_student_not_allowed_see_widget', 'plagiarism_pchkorg'), + $isdebugenabled + ); + } + + $isreportallowed = !$isstudent || $pchkorgconfigmodel->show_report_for_student($cmid) === true; + // Only for some type of account, method will call a remote HTTP API. // The API will be called only once, because result is static. // Also, there is timeout 2 seconds for response. @@ -329,7 +377,8 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin { 'token' => $reporttoken, 'image' => $imgsrc, 'label' => $label, - 'color' => $color + 'color' => $color, + 'isreportallowed' => $isreportallowed, ); static $isjsfuncinjected = false; if (!$isjsfuncinjected) { @@ -410,7 +459,7 @@ require(['jquery'], function ($) { if (id) { for (var d in window.plagiarism_check_data) { var data = window.plagiarism_check_data[d]; - if (data && data.id == id) { + if (data && data.id == id && data.isreportallowed) { window.plagiarism_check_full_report(data.action, data.token); break; } @@ -513,7 +562,9 @@ display: inline-block;" 'pchkorg_min_percent', 'pchkorg_include_citation', 'pchkorg_include_referenced', - 'pchkorg_exclude_self_plagiarism' + 'pchkorg_exclude_self_plagiarism', + 'pchkorg_student_can_see_widget', + 'pchkorg_student_can_see_report' ); $records = $DB->get_records('plagiarism_pchkorg_config', array( diff --git a/version.php b/version.php index 1f3bc0e..3c662df 100644 --- a/version.php +++ b/version.php @@ -26,11 +26,11 @@ defined('MOODLE_INTERNAL') || die(); if (!isset($plugin)) { $plugin = new stdClass(); } -$plugin->version = 2022071720; -$plugin->requires = 2020061501; // Requires Moodle 3.9 . -$plugin->release = 'v3.9.7'; +$plugin->version = 2022072210; +$plugin->requires = 2020071703; // Requires Moodle 3.9 . +$plugin->release = 'v3.10.1'; $plugin->component = 'plagiarism_pchkorg'; $plugin->maturity = MATURITY_STABLE; $plugin->dependencies = array( - 'mod_assign' => ANY_VERSION, + 'mod_assign' => ANY_VERSION, );