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 customizable reports
20
 * @package blocks
21
 * @author: Juan leyva <http://www.twitter.com/jleyvadelgado>
22
 * @date: 2009
23
 */
24
 
25
class component_customsql extends component_base {
26
    public function init() {
27
        global $PAGE;
28
 
29
        $this->plugins = false;
30
        $this->ordering = false;
31
        $this->form = true;
32
        $this->help = true;
33
 
34
        if (get_config('block_configurable_reports', 'sqlsyntaxhighlight')) {
35
            $PAGE->requires->js_call_amd('block_configurable_reports/main', 'cmirror');
36
        }
37
    }
38
 
39
    public function form_process_data(&$cform) {
40
        global $DB;
41
        if ($this->form) {
42
            $data = $cform->get_data();
43
            // Function cr_serialize() will add slashes.
44
            $components = cr_unserialize($this->config->components);
45
            $components['customsql']['config'] = $data;
46
            $this->config->components = cr_serialize($components);
47
            $DB->update_record('block_configurable_reports', $this->config);
48
        }
49
    }
50
 
51
    public function form_set_data(&$cform) {
52
        if ($this->form) {
53
            $fdata = new stdclass;
54
            $components = cr_unserialize($this->config->components);
55
            $sqlconfig = (isset($components['customsql']['config'])) ? $components['customsql']['config'] : new stdclass;
56
            $cform->set_data($sqlconfig);
57
        }
58
    }
59
}