Add new option: teachers allow students to see the result

This commit is contained in:
Jane Adelmann 2022-07-22 10:20:38 +03:00
parent 59185593d9
commit 39306ca802
No known key found for this signature in database
GPG Key ID: 4CCF39DF30B8AF72
5 changed files with 134 additions and 12 deletions

View File

@ -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

View File

@ -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');

View File

@ -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 <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>

59
lib.php
View File

@ -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(

View File

@ -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,
);