Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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
/**
18
 * The main mod_subsection configuration form.
19
 *
20
 * @package     mod_subsection
21
 * @copyright   2023 Amaia Anabitarte <amaia@moodle.com>
22
 * @license     https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
defined('MOODLE_INTERNAL') || die();
26
 
27
require_once($CFG->dirroot.'/course/moodleform_mod.php');
28
 
29
use mod_subsection\manager;
30
 
31
/**
32
 * Module instance settings form.
33
 *
34
 * @package     mod_subsection
35
 * @copyright   2023 Amaia Anabitarte <amaia@moodle.com>
36
 * @license     https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class mod_subsection_mod_form extends moodleform_mod {
39
 
40
    /**
41
     * Defines forms elements
42
     */
43
    public function definition() {
44
        global $CFG;
45
 
46
        // Showing edit form. Redirect to the edit section page.
47
        if (!empty($this->current->instance)) {
48
            $manager = manager::create_from_id($this->current->course, $this->current->id);
49
            $editurl = new moodle_url('/course/editsection.php', ['id' => $manager->get_delegated_section_info()->id]);
50
            redirect($editurl->out());
51
        } else {
52
            $mform = $this->_form;
53
 
54
            // Adding the "general" fieldset, where all the common settings are shown.
55
            $mform->addElement('header', 'general', get_string('general', 'form'));
56
 
57
            // Adding the standard "name" field.
58
            $mform->addElement('text', 'name', get_string('subsectionname', 'mod_subsection'), ['size' => '64']);
59
 
60
            if (!empty($CFG->formatstringstriptags)) {
61
                $mform->setType('name', PARAM_TEXT);
62
            } else {
63
                $mform->setType('name', PARAM_CLEANHTML);
64
            }
65
 
66
            $mform->addRule('name', null, 'required', null, 'client');
67
            $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
68
 
69
            // Add standard elements.
70
            $this->standard_coursemodule_elements();
71
 
72
            // Add standard buttons.
73
            $this->add_action_buttons();
74
 
75
            // Show only general and restrictions form sections.
76
            $mform->filter_shown_headers(['general', 'availabilityconditionsheader']);
77
        }
78
    }
79
}