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
if (!defined('MOODLE_INTERNAL')) {
18
    //  It must be included from a Moodle page.
19
    die('Direct access to this script is forbidden.');
20
}
21
 
22
require_once($CFG->libdir.'/formslib.php');
23
 
24
class line_form extends moodleform {
25
    public function definition() {
26
        global $DB, $USER, $CFG;
27
 
28
        $mform =& $this->_form;
29
        $options = array(0 => get_string('choose'));
30
 
31
        $report = $this->_customdata['report'];
32
 
33
        if ($report->type != 'sql') {
34
            $components = cr_unserialize($this->_customdata['report']->components);
35
 
36
            if (!is_array($components) || empty($components['columns']['elements'])) {
37
                print_error('nocolumns');
38
            }
39
 
40
            $columns = $components['columns']['elements'];
41
            foreach ($columns as $c) {
42
                $options[] = $c['summary'];
43
            }
44
        } else {
45
 
46
            require_once($CFG->dirroot.'/blocks/configurable_reports/report.class.php');
47
            require_once($CFG->dirroot.'/blocks/configurable_reports/reports/'.$report->type.'/report.class.php');
48
 
49
            $reportclassname = 'report_'.$report->type;
50
            $reportclass = new $reportclassname($report);
51
 
52
            $components = cr_unserialize($report->components);
53
            $config = (isset($components['customsql']['config'])) ? $components['customsql']['config'] : new stdclass;
54
 
55
            if (isset($config->querysql)) {
56
                $sql = $config->querysql;
57
                $sql = $reportclass->prepare_sql($sql);
58
                if ($rs = $reportclass->execute_query($sql)) {
59
                    foreach ($rs as $row) {
60
                        $i = 1;
61
                        foreach ($row as $colname => $value) {
62
                            $options[$i] = str_replace('_', ' ', $colname);
63
                            $i++;
64
                        }
65
                        break;
66
                    }
67
                    $rs->close();
68
                }
69
            }
70
        }
71
 
72
        $mform->addElement('header',  'crformheader', get_string('line', 'block_configurable_reports'), '');
73
 
74
        $mform->addElement('select', 'xaxis', get_string('xaxis', 'block_configurable_reports'), $options);
75
        $mform->addRule('xaxis', null, 'required', null, 'client');
76
 
77
        $mform->addElement('select', 'serieid', get_string('serieid', 'block_configurable_reports'), $options);
78
        $mform->addRule('serieid', null, 'required', null, 'client');
79
 
80
        $mform->addElement('select', 'yaxis', get_string('yaxis', 'block_configurable_reports'), $options);
81
        $mform->addRule('yaxis', null, 'required', null, 'client');
82
 
83
        $mform->addElement('checkbox', 'group', get_string('groupseries', 'block_configurable_reports'));
84
 
85
        // Buttons.
86
        $this->add_action_buttons(true, get_string('add'));
87
    }
88
 
89
    public function validation($data, $files) {
90
        $errors = parent::validation($data, $files);
91
 
92
        if ($data['xaxis'] == $data['yaxis']) {
93
            $errors['yaxis'] = get_string('xandynotequal', 'block_configurable_reports');
94
        }
95
 
96
        return $errors;
97
    }
98
}