Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://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 <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Adds new instance of enrol_plugin to specified course or edits current instance.
19
 *
20
 * @package    core_enrol
21
 * @copyright  2015 Damyon Wiese
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
defined('MOODLE_INTERNAL') || die();
26
 
27
require_once($CFG->libdir.'/formslib.php');
28
 
29
/**
30
 * Standard edit form shared by all enrol plugins.
31
 *
32
 * @package    core_enrol
33
 * @copyright  2015 Damyon Wiese
34
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
class enrol_instance_edit_form extends moodleform {
37
 
38
    /**
39
     * Called to define this moodle form
40
     *
41
     * @return void
42
     */
43
    public function definition() {
44
        global $DB;
45
 
46
        $mform = $this->_form;
47
 
48
        list($instance, $plugin, $context, $type, $returnurl) = $this->_customdata;
49
 
50
        $plugin->edit_instance_form($instance, $mform, $context);
51
 
52
        $mform->addElement('hidden', 'id');
53
        $mform->setType('id', PARAM_INT);
54
        $mform->addElement('hidden', 'courseid');
55
        $mform->setType('courseid', PARAM_INT);
56
 
57
        $mform->addElement('hidden', 'type');
58
        $mform->setType('type', PARAM_COMPONENT);
59
        $instance->type = $type;
60
 
61
        $mform->addElement('hidden', 'returnurl');
62
        $mform->setType('returnurl', PARAM_LOCALURL);
63
        $mform->setConstant('returnurl', $returnurl);
64
 
65
        $this->add_action_buttons(true, ($instance->id ? null : get_string('addinstance', 'enrol')));
66
 
67
        $this->set_data($instance);
68
    }
69
 
70
    /**
71
     * Validate this form. Calls plugin validation method.
72
     *
73
     * @param array $data
74
     * @param array $files
75
     * @return array
76
     */
77
    public function validation($data, $files) {
78
        $errors = parent::validation($data, $files);
79
 
80
        list($instance, $plugin, $context, $type) = $this->_customdata;
81
 
82
        $pluginerrors = $plugin->edit_instance_validation($data, $files, $instance, $context);
83
 
84
        $errors = array_merge($errors, $pluginerrors);
85
 
86
        return $errors;
87
    }
88
 
89
}