Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| settings_form | |
0.00% |
0 / 26 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
| definition | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
6 | |||
| validation | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | // This file is part of Moodle - https://moodle.org/ |
| 3 | // |
| 4 | // Moodle is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // Moodle is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with Moodle. If not, see <https://www.gnu.org/licenses/>. |
| 16 | |
| 17 | namespace local_doublemark\form; |
| 18 | |
| 19 | use local_doublemark\local\reconciler; |
| 20 | |
| 21 | defined('MOODLE_INTERNAL') || die(); |
| 22 | |
| 23 | require_once($CFG->libdir . '/formslib.php'); |
| 24 | |
| 25 | /** |
| 26 | * Turn double marking on or off and choose how two marks become one. |
| 27 | * |
| 28 | * Custom data: maxgrade (float). |
| 29 | * |
| 30 | * @package local_doublemark |
| 31 | * @copyright 2026 DevLMS <contact@devlms.com> |
| 32 | * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 33 | */ |
| 34 | class settings_form extends \moodleform { |
| 35 | /** |
| 36 | * Fields. |
| 37 | */ |
| 38 | protected function definition() { |
| 39 | $mform = $this->_form; |
| 40 | $mform->addElement('hidden', 'cmid'); |
| 41 | $mform->setType('cmid', PARAM_INT); |
| 42 | $mform->addElement('hidden', 'tab', 'settings'); |
| 43 | $mform->setType('tab', PARAM_ALPHA); |
| 44 | |
| 45 | $mform->addElement( |
| 46 | 'advcheckbox', |
| 47 | 'enabled', |
| 48 | get_string('enabled', 'local_doublemark'), |
| 49 | get_string('enabled_desc', 'local_doublemark') |
| 50 | ); |
| 51 | $mform->addElement('float', 'tolerance', get_string('tolerance', 'local_doublemark')); |
| 52 | $mform->setDefault('tolerance', 5); |
| 53 | $mform->addHelpButton('tolerance', 'tolerance', 'local_doublemark'); |
| 54 | $mform->hideIf('tolerance', 'enabled'); |
| 55 | $rules = []; |
| 56 | foreach (reconciler::RULES as $rule) { |
| 57 | $rules[$rule] = get_string('rule:' . $rule, 'local_doublemark'); |
| 58 | } |
| 59 | $mform->addElement('select', 'agreerule', get_string('agreerule', 'local_doublemark'), $rules); |
| 60 | $mform->addHelpButton('agreerule', 'agreerule', 'local_doublemark'); |
| 61 | $mform->hideIf('agreerule', 'enabled'); |
| 62 | $this->add_action_buttons(false); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Tolerance between 0 and the highest grade. |
| 67 | * |
| 68 | * @param array $data |
| 69 | * @param array $files |
| 70 | * @return array |
| 71 | */ |
| 72 | public function validation($data, $files) { |
| 73 | $errors = parent::validation($data, $files); |
| 74 | if (!empty($data['enabled']) && ($data['tolerance'] < 0 || $data['tolerance'] > $this->_customdata['maxgrade'])) { |
| 75 | $errors['tolerance'] = get_string('error:badtolerance', 'local_doublemark'); |
| 76 | } |
| 77 | return $errors; |
| 78 | } |
| 79 | } |