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 the customcert module for 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
 * This file contains the form for handling editing a customcert element.
19
 *
20
 * @package    mod_customcert
21
 * @copyright  2013 Mark Nelson <markn@moodle.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace mod_customcert;
26
 
27
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
28
 
29
require_once($CFG->dirroot . '/course/moodleform_mod.php');
30
require_once($CFG->dirroot . '/mod/customcert/includes/colourpicker.php');
31
 
32
\MoodleQuickForm::registerElementType('customcert_colourpicker',
33
    $CFG->dirroot . '/mod/customcert/includes/colourpicker.php', 'MoodleQuickForm_customcert_colourpicker');
34
 
35
/**
36
 * The form for handling editing a customcert element.
37
 *
38
 * @package    mod_customcert
39
 * @copyright  2013 Mark Nelson <markn@moodle.com>
40
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41
 */
42
class edit_element_form extends \moodleform {
43
 
44
    /**
45
     * @var \mod_customcert\element The element object.
46
     */
47
    protected $element;
48
 
49
    /**
50
     * Form definition.
51
     */
52
    public function definition() {
53
        $mform =& $this->_form;
54
 
55
        $mform->updateAttributes(['id' => 'editelementform']);
56
 
57
        $element = $this->_customdata['element'];
58
 
59
        // Add the field for the name of the element, this is required for all elements.
60
        $mform->addElement('text', 'name', get_string('elementname', 'customcert'), 'maxlength="255"');
61
        $mform->setType('name', PARAM_TEXT);
62
        $mform->setDefault('name', get_string('pluginname', 'customcertelement_' . $element->element));
63
        $mform->addRule('name', get_string('required'), 'required', null, 'client');
64
        $mform->addHelpButton('name', 'elementname', 'customcert');
65
 
66
        $this->element = \mod_customcert\element_factory::get_element_instance($element);
67
        $this->element->set_edit_element_form($this);
68
        $this->element->render_form_elements($mform);
69
 
70
        $this->add_action_buttons(true);
71
    }
72
 
73
    /**
74
     * Fill in the current page data for this customcert.
75
     */
76
    public function definition_after_data() {
77
        $this->element->definition_after_data($this->_form);
78
    }
79
 
80
    /**
81
     * Validation.
82
     *
83
     * @param array $data
84
     * @param array $files
85
     * @return array the errors that were found
86
     */
87
    public function validation($data, $files) {
88
        $errors = [];
89
 
90
        if (\core_text::strlen($data['name']) > 255) {
91
            $errors['name'] = get_string('nametoolong', 'customcert');
92
        }
93
 
94
        $errors += $this->element->validate_form_elements($data, $files);
95
 
96
        return $errors;
97
    }
98
}