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
 /**
26
 * COMPETENCY TEMPLATE FILTER
27
 * A filter for configurable reports
28
 * @author: François Parlant <https://www.linkedin.com/in/francois-parlant/>
29
 * @date: 2020
30
 */
31
 
32
 
33
 /* example of report query
34
 ***********
35
 * Display the courses in which the competencies of a template are used
36
 ***********
37
 
38
 
39
 */
40
 
41
 
42
require_once($CFG->dirroot.'/blocks/configurable_reports/plugin.class.php');
43
 
44
class plugin_competencytemplates extends plugin_base{
45
 
46
    public function init() {
47
        $this->form = false;
48
        $this->unique = true;
49
        $this->fullname = get_string('filtercompetencytemplates', 'block_configurable_reports');
50
        $this->reporttypes = array('courses', 'sql');
51
    }
52
 
53
    public function summary($data) {
54
        return get_string('filtercompetencytemplates_summary', 'block_configurable_reports');
55
    }
56
 
57
    public function execute($finalelements, $data) {
58
 
59
        $filtercompetencytemplates = optional_param('filter_competencytemplates', 0, PARAM_INT);
60
        if (!$filtercompetencytemplates) {
61
            return $finalelements;
62
        }
63
 
64
        if ($this->report->type != 'sql') {
65
            return array($filtercompetencytemplates);
66
        } else {
67
            if (preg_match("/%%FILTER_COMPETENCYTEMPLATES:([^%]+)%%/i", $finalelements, $output)) {
68
                $replace = ' AND '.$output[1].' = '.$filtercompetencytemplates;
69
                return str_replace('%%FILTER_COMPETENCYTEMPLATES:'.$output[1].'%%', $replace, $finalelements);
70
            }
71
        }
72
        return $finalelements;
73
    }
74
 
75
    public function print_filter(&$mform) {
76
        global $remotedb, $COURSE, $PAGE, $CFG;
77
 
78
        $reportclassname = 'report_'.$this->report->type;
79
        $reportclass = new $reportclassname($this->report);
80
 
81
        if ($this->report->type != 'sql') {
82
            $components = cr_unserialize($this->report->components);
83
            $conditions = $components['conditions'];
84
 
85
            $competencytemplateslist = $reportclass->elements_by_conditions($conditions);
86
        } else {
87
            $sql = 'SELECT  ct.id, ct.shortname
88
                      FROM {competency_template} ct
89
                      ';
90
            $studentlist = $remotedb->get_records_sql($sql);
91
            foreach ($studentlist as $student) {
92
                $competencytemplateslist[] = $student->userid;
93
            }
94
 
95
        }
96
 
97
        $competencytemplatesoptions = array();
98
        $competencytemplatesoptions[0] = get_string('filter_all', 'block_configurable_reports');
99
 
100
        if (!empty($competencytemplateslist)) {
101
 
102
            $competencytemplates = $remotedb->get_records_sql($sql);
103
 
104
            foreach ($competencytemplates as $c) {
105
                $competencytemplatesoptions[$c->id] = $c->shortname;
106
            }
107
        }
108
 
109
        $elestr = get_string('competencytemplates', 'block_configurable_reports');
110
        $mform->addElement('select', 'filter_competencytemplates', $elestr, $competencytemplatesoptions);
111
        $mform->setType('filter_competencytemplates', PARAM_INT);
112
    }
113
}