Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.00% covered (success)
90.00%
18 / 20
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
settings_form
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 definition
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
1
 validation
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
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_recertify\form;
18
19defined('MOODLE_INTERNAL') || die();
20
21require_once($CFG->libdir . '/formslib.php');
22
23/**
24 * Recertification settings for a course.
25 *
26 * @package    local_recertify
27 * @copyright  2026 DevLMS <contact@devlms.com>
28 * @license    https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 */
30class settings_form extends \moodleform {
31    /**
32     * Define the fields.
33     */
34    protected function definition() {
35        $mform = $this->_form;
36        $mform->addElement('hidden', 'courseid');
37        $mform->setType('courseid', PARAM_INT);
38        $mform->addElement('header', 'settingshdr', get_string('settings', 'local_recertify'));
39        $mform->addElement('advcheckbox', 'enabled', get_string('enabled', 'local_recertify'));
40        $mform->addHelpButton('enabled', 'enabled', 'local_recertify');
41        $mform->addElement('text', 'perioddays', get_string('perioddays', 'local_recertify'), ['size' => 6]);
42        $mform->setType('perioddays', PARAM_INT);
43        $mform->addRule('perioddays', null, 'required', null, 'client');
44        $mform->addHelpButton('perioddays', 'perioddays', 'local_recertify');
45        $mform->addElement('text', 'reminderdays', get_string('reminderdays', 'local_recertify'), ['size' => 20]);
46        $mform->setType('reminderdays', PARAM_SEQUENCE);
47        $mform->addHelpButton('reminderdays', 'reminderdays', 'local_recertify');
48        $this->add_action_buttons(false);
49    }
50
51    /**
52     * The period must be at least a day.
53     *
54     * @param array $data
55     * @param array $files
56     * @return array
57     */
58    public function validation($data, $files) {
59        $errors = parent::validation($data, $files);
60        if ((int) $data['perioddays'] < 1) {
61            $errors['perioddays'] = get_string('error:period', 'local_recertify');
62        }
63        return $errors;
64    }
65}