From 8d2814a4195c9ac015ae7d2f81b4e19885ac446c Mon Sep 17 00:00:00 2001 From: Jane Adelmann Date: Wed, 27 Apr 2022 17:42:46 +0300 Subject: [PATCH] Add configuration for activity module. --- form/plagiarism_pchkorg_setup_form.php | 13 ++++-- lib.php | 64 +++++++++++++++++++------- version.php | 4 +- 3 files changed, 59 insertions(+), 22 deletions(-) diff --git a/form/plagiarism_pchkorg_setup_form.php b/form/plagiarism_pchkorg_setup_form.php index 84f9469..3510222 100644 --- a/form/plagiarism_pchkorg_setup_form.php +++ b/form/plagiarism_pchkorg_setup_form.php @@ -46,14 +46,14 @@ class plagiarism_pchkorg_setup_form extends moodleform { $mform->addElement( 'select', - $setting = 'pchkorg_use', + 'pchkorg_use', get_string('pchkorg_use', 'plagiarism_pchkorg'), array(get_string('no'), get_string('yes')) ); $mform->addHelpButton('pchkorg_use', 'pchkorg_use', 'plagiarism_pchkorg'); - if (!isset($mform->exportValues()[$setting]) || is_null($mform->exportValues()[$setting])) { - $mform->setDefault($setting, false); + 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')); @@ -63,7 +63,12 @@ class plagiarism_pchkorg_setup_form extends moodleform { $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')); + $label = get_string('pchkorg_min_percent', 'plagiarism_pchkorg'); + if (!empty($minpercent)) { + $label = \str_replace('X%', $minpercent . '%', $label); + } + + $mform->addElement('text', 'pchkorg_min_percent', $label); $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'); diff --git a/lib.php b/lib.php index 6df7eab..30d36bf 100644 --- a/lib.php +++ b/lib.php @@ -215,15 +215,13 @@ display: inline-block;" return; } - 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 )); + foreach ($fields as $field) { $isfounded = false; foreach ($records as $record) { @@ -234,7 +232,7 @@ display: inline-block;" break; } } - if (!$isfounded) { + if (!$isfounded && isset($data->{$field})) { $insert = new \stdClass(); $insert->cm = $data->coursemodule; $insert->name = $field; @@ -269,37 +267,71 @@ display: inline-block;" if ('1' == $config && $enabled) { $defaultcmid = null; $cm = optional_param('update', $defaultcmid, PARAM_INT); - if (null !== $cm) { + $minpercent = $pchkorgconfigmodel->get_system_config('pchkorg_min_percent'); + + 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, )); if (!empty($records)) { - $record = end($records); - $mform->setDefault($record->name, $record->value); + foreach ($records as $record) { + $mform->setDefault($record->name, $record->value); + } } } - $mform->addElement('header', 'plagiarism_pchkorg', get_string('pluginname', 'plagiarism_pchkorg')); + $mform->addElement( + 'header', + 'plagiarism_pchkorg', + get_string('pluginname', 'plagiarism_pchkorg') + ); $mform->addElement( 'select', - $setting = 'pchkorg_module_use', + 'pchkorg_module_use', get_string('pchkorg_module_use', 'plagiarism_pchkorg'), array(get_string('no'), get_string('yes')) ); $mform->addHelpButton('pchkorg_module_use', 'pchkorg_module_use', 'plagiarism_pchkorg'); - if (!isset($mform->exportValues()[$setting]) || is_null($mform->exportValues()[$setting])) { - $mform->setDefault($setting, '1'); + $canchangeminpercent = has_capability(capability::CHANGE_MIN_PERCENT_FILTER, $context); + if ($canchangeminpercent) { + $dissabledattribute = ''; + } else { + $dissabledattribute = 'disabled="disabled"'; + } + $mform->registerRule( + 'check_pchkorg_min_percent', + 'callback', + 'pchkorg_check_pchkorg_min_percent' + ); + $label = get_string('pchkorg_min_percent', 'plagiarism_pchkorg'); + if (!empty($minpercent)) { + $label = \str_replace('X%', $minpercent . '%', $label); } - $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->addElement( + 'text', + 'pchkorg_min_percent', + $label, + $dissabledattribute + ); $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->addRule( + 'pchkorg_min_percent', + get_string('pchkorg_min_percent_range', 'plagiarism_pchkorg'), + 'check_pchkorg_min_percent' + ); $mform->setType('pchkorg_min_percent', PARAM_INT); - } } diff --git a/version.php b/version.php index 94ef462..1250ea5 100644 --- a/version.php +++ b/version.php @@ -26,9 +26,9 @@ defined('MOODLE_INTERNAL') || die(); if (!isset($plugin)) { $plugin = new stdClass(); } -$plugin->version = 2021100101; +$plugin->version = 2022042714; $plugin->requires = 2017051500; // Requires Moodle 3.3 . -$plugin->release = 'v3.7.5'; +$plugin->release = 'v3.8.1'; $plugin->maturity = MATURITY_STABLE; $plugin->component = 'plagiarism_pchkorg'; $plugin->dependencies = array(