Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
reason_form
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 definition
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 validation
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
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
17namespace local_finalgrades\form;
18
19defined('MOODLE_INTERNAL') || die();
20
21global $CFG;
22require_once($CFG->libdir . '/formslib.php');
23
24/**
25 * The reason for withdrawing or returning a submitted grade.
26 *
27 * @package    local_finalgrades
28 * @copyright  2026 DevLMS <contact@devlms.com>
29 * @license    https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 */
31class reason_form extends \moodleform {
32    /**
33     * Form fields.
34     */
35    protected function definition() {
36        $mform = $this->_form;
37        $action = $this->_customdata['action'];
38        $mform->addElement('textarea', 'reason', get_string('reason', 'local_finalgrades'), ['rows' => 4, 'cols' => 60]);
39        $mform->setType('reason', PARAM_TEXT);
40        $mform->addRule('reason', get_string('reasonrequired', 'local_finalgrades'), 'required', null, 'client');
41        $this->add_action_buttons(true, get_string($action, 'local_finalgrades'));
42    }
43
44    /**
45     * A reason of spaces is not a reason.
46     *
47     * @param array $data
48     * @param array $files
49     * @return array
50     */
51    public function validation($data, $files) {
52        $errors = parent::validation($data, $files);
53        if (trim($data['reason'] ?? '') === '') {
54            $errors['reason'] = get_string('reasonrequired', 'local_finalgrades');
55        }
56        return $errors;
57    }
58}