Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| mark_form | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| definition | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| validation | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| 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 | defined('MOODLE_INTERNAL') || die(); |
| 20 | |
| 21 | require_once($CFG->libdir . '/formslib.php'); |
| 22 | |
| 23 | /** |
| 24 | * A marker's independent mark and private comment. |
| 25 | * |
| 26 | * Custom data: maxgrade (float). |
| 27 | * |
| 28 | * @package local_doublemark |
| 29 | * @copyright 2026 DevLMS <contact@devlms.com> |
| 30 | * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 31 | */ |
| 32 | class mark_form extends \moodleform { |
| 33 | /** |
| 34 | * Fields. |
| 35 | */ |
| 36 | protected function definition() { |
| 37 | $mform = $this->_form; |
| 38 | foreach (['cmid', 'userid'] as $name) { |
| 39 | $mform->addElement('hidden', $name); |
| 40 | $mform->setType($name, PARAM_INT); |
| 41 | } |
| 42 | $mform->addElement('float', 'grade', get_string('yourmark', 'local_doublemark', $this->_customdata['maxgrade'])); |
| 43 | $mform->addRule('grade', null, 'required', null, 'client'); |
| 44 | $mform->addElement('textarea', 'comment', get_string('yourcomment', 'local_doublemark'), ['rows' => 6]); |
| 45 | $mform->setType('comment', PARAM_TEXT); |
| 46 | $mform->addHelpButton('comment', 'yourcomment', 'local_doublemark'); |
| 47 | $this->add_action_buttons(true, get_string('savemark', 'local_doublemark')); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Grade within range. |
| 52 | * |
| 53 | * @param array $data |
| 54 | * @param array $files |
| 55 | * @return array |
| 56 | */ |
| 57 | public function validation($data, $files) { |
| 58 | $errors = parent::validation($data, $files); |
| 59 | $max = (float) $this->_customdata['maxgrade']; |
| 60 | if ($data['grade'] < 0 || $data['grade'] > $max) { |
| 61 | $errors['grade'] = get_string('error:range', 'local_doublemark', format_float($max, -1)); |
| 62 | } |
| 63 | return $errors; |
| 64 | } |
| 65 | } |