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
 * Configurable Reports
19
 * A Moodle block for creating Configurable Reports
20
 * @package blocks
21
 * @author: Juan leyva <http://www.twitter.com/jleyvadelgado>
22
 * @date: 2009
23
 */
24
 
25
if (!defined('MOODLE_INTERNAL')) {
26
    //  Must be included from a Moodle page.
27
    die('Direct access to this script is forbidden.');
28
}
29
 
30
require_once($CFG->libdir.'/formslib.php');
31
 
32
class report_edit_form extends moodleform {
33
    public function definition() {
34
        global $DB, $USER, $CFG;
35
 
36
        $adminmode = optional_param('adminmode', null, PARAM_INT);
37
 
38
        $mform =& $this->_form;
39
 
40
        $mform->addElement('header', 'general', get_string('general', 'form'));
41
 
42
        $mform->addElement('text', 'name', get_string('name'), array('maxlength' => 60, 'size' => 58));
43
        if (!empty($CFG->formatstringstriptags)) {
44
            $mform->setType('name', PARAM_TEXT);
45
        } else {
46
            $mform->setType('name', PARAM_NOTAGS);
47
        }
48
        $mform->addRule('name', null, 'required', null, 'client');
49
 
50
        $mform->addElement('editor', 'summary_editor', get_string('summary'), null, $this->get_editor_options());
51
        $mform->setType('summary_editor', PARAM_RAW);
52
        $typeoptions = cr_get_report_plugins($this->_customdata['courseid']);
53
 
54
        $eloptions = array();
55
        if (isset($this->_customdata['report']->id) && $this->_customdata['report']->id) {
56
            $eloptions = array('disabled' => 'disabled');
57
        }
58
        $select = $mform->addElement('select', 'type', get_string('typeofreport', 'block_configurable_reports'), $typeoptions, $eloptions);
59
        $mform->addHelpButton('type', 'typeofreport', 'block_configurable_reports');
60
        $select->setSelected('sql');
61
 
62
        for ($i = 0; $i <= 100; $i++) {
63
            $pagoptions[$i] = $i;
64
        }
65
        $mform->addElement('select', 'pagination', get_string('pagination', 'block_configurable_reports'), $pagoptions);
66
        $mform->setDefault('pagination', 0);
67
        $mform->addHelpButton('pagination', 'pagination', 'block_configurable_reports');
68
 
69
        $mform->addElement('checkbox', 'global', get_string('global', 'block_configurable_reports'), get_string('enableglobal', 'block_configurable_reports'));
70
        $mform->addHelpButton('global', 'global', 'block_configurable_reports');
71
        $mform->setDefault('global', 0);
72
 
73
        $mform->addElement('checkbox', 'jsordering', get_string('ordering', 'block_configurable_reports'), get_string('enablejsordering', 'block_configurable_reports'));
74
        $mform->addHelpButton('jsordering', 'jsordering', 'block_configurable_reports');
75
        $mform->setDefault('jsordering', 1);
76
 
77
        $mform->addElement('checkbox', 'cron', get_string('cron', 'block_configurable_reports'), get_string('crondescription', 'block_configurable_reports'));
78
        $mform->addHelpButton('cron', 'cron', 'block_configurable_reports');
79
        $mform->setDefault('cron', 0);
80
        $mform->disabledIf('cron', 'type', 'neq', 'sql');
81
 
82
        $mform->addElement('checkbox', 'remote', get_string('remote', 'block_configurable_reports'), get_string('remotedescription', 'block_configurable_reports'));
83
        $mform->addHelpButton('remote', 'remote', 'block_configurable_reports');
84
        $mform->setDefault('remote', 0);
85
 
86
        $mform->addElement('header', 'exportoptions', get_string('exportoptions', 'block_configurable_reports'));
87
        $options = cr_get_export_plugins();
88
 
89
        foreach ($options as $key => $val) {
90
            $mform->addElement('checkbox', 'export_'.$key, null, $val);
91
        }
92
 
93
        if (isset($this->_customdata['report']->id) && $this->_customdata['report']->id) {
94
            $mform->addElement('hidden', 'id', $this->_customdata['report']->id);
95
            $mform->setType('id', PARAM_INT);
96
        }
97
        if (!empty($adminmode)) {
98
            $mform->addElement('text', 'courseid', get_string('setcourseid', 'block_configurable_reports'), $this->_customdata['courseid']);
99
            $mform->setType('courseid', PARAM_INT);
100
        } else {
101
            $mform->addElement('hidden', 'courseid', $this->_customdata['courseid']);
102
            $mform->setType('courseid', PARAM_INT);
103
        }
104
 
105
        // Buttons.
106
        $this->add_action_buttons(true, get_string('add'));
107
    }
108
 
109
    public function validation($data, $files) {
110
        $errors = parent::validation($data, $files);
111
        return $errors;
112
    }
113
 
114
    /**
115
     * Used to reformat the data from the editor component.
116
     *
117
     * @return stdClass
118
     */
119
    function get_data() {
120
        $data = parent::get_data();
121
 
122
        if ($data !== null and isset($data->summary_editor)) {
123
            $data->summaryformat = $data->summary_editor['format'];
124
            $data->summary = $data->summary_editor['text'];
125
        }
126
 
127
        return $data;
128
    }
129
 
130
    /**
131
     * Load in existing data as form defaults.
132
     *
133
     * @param stdClass|array $default_values object or array of default values.
134
     */
135
    function set_data($default_values) {
136
        if (!is_object($default_values)) {
137
            // We need object for file_prepare_standard_editor.
138
            $default_values = (object)$default_values;
139
        }
140
        $default_values = file_prepare_standard_editor($default_values, 'summary', $this->get_editor_options());
141
 
142
        parent::set_data($default_values);
143
    }
144
 
145
 
146
    /**
147
     * Get editor options for this form.
148
     *
149
     * @return array An array of options.
150
     */
151
    function get_editor_options() {
152
        $editoroptions = [
153
            'subdirs' => 0,
154
            'maxbytes' => 0,
155
            'maxfiles' => 0,
156
            'noclean' => false,
157
            'trusttext' => false
158
        ];
159
        return $editoroptions;
160
    }
161
}