Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.91% covered (success)
90.91%
20 / 22
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
move_form
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 definition
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
2
 validation
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
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_integritycase\form;
18
19defined('MOODLE_INTERNAL') || die();
20
21require_once($CFG->libdir . '/formslib.php');
22
23use local_integritycase\local\workflow;
24
25/**
26 * Form to move a case to its next stage.
27 *
28 * @package    local_integritycase
29 * @copyright  2026 DevLMS <contact@devlms.com>
30 * @license    https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31 */
32class move_form extends \moodleform {
33    /**
34     * Define the fields. Custom data: stages, id => name, the moves allowed from the current stage.
35     */
36    protected function definition() {
37        $mform = $this->_form;
38        $mform->addElement('hidden', 'id');
39        $mform->setType('id', PARAM_INT);
40        $mform->addElement('hidden', 'action', 'move');
41        $mform->setType('action', PARAM_ALPHA);
42        $mform->addElement('header', 'movehdr', get_string('nextstep', 'local_integritycase'));
43        $mform->addElement('select', 'stage', get_string('stage', 'local_integritycase'), $this->_customdata['stages']);
44        $outcomes = ['' => get_string('choosedots')];
45        foreach (workflow::outcomes() as $outcome) {
46            $outcomes[$outcome] = get_string("outcome:$outcome", 'local_integritycase');
47        }
48        $mform->addElement('select', 'outcome', get_string('outcome', 'local_integritycase'), $outcomes);
49        $mform->hideIf('outcome', 'stage', 'neq', workflow::DECIDED);
50        $mform->addElement('textarea', 'note', get_string('note', 'local_integritycase'), ['rows' => 4, 'cols' => 60]);
51        $mform->setType('note', PARAM_TEXT);
52        $mform->addHelpButton('note', 'note', 'local_integritycase');
53        $this->add_action_buttons(false, get_string('changestage', 'local_integritycase'));
54    }
55
56    /**
57     * A decision needs an outcome.
58     *
59     * @param array $data
60     * @param array $files
61     * @return array
62     */
63    public function validation($data, $files) {
64        $errors = parent::validation($data, $files);
65        if ($data['stage'] === workflow::DECIDED && !workflow::is_outcome((string) ($data['outcome'] ?? ''))) {
66            $errors['outcome'] = get_string('outcomerequired', 'local_integritycase');
67        }
68        return $errors;
69    }
70}