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 FRAMEWORK 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 framework are used
|
|
|
36 |
***********
|
|
|
37 |
SELECT ccc.id, ccc.courseid, ccc.competencyid, cf.shortname as 'referentiel', cf.idnumber as 'framework Id', c.fullname as 'cours', comp.shortname
|
|
|
38 |
FROM prefix_competency_coursecomp ccc
|
|
|
39 |
INNER JOIN prefix_course AS c ON c.id = ccc.courseid
|
|
|
40 |
INNER JOIN prefix_competency AS comp ON comp.id = ccc.competencyid
|
|
|
41 |
INNER JOIN prefix_competency_framework AS cf ON cf.id = comp.competencyframeworkid
|
|
|
42 |
JOIN prefix_course_categories cc ON c.category = cc.id
|
|
|
43 |
WHERE 1=1
|
|
|
44 |
%%FILTER_COMPETENCYFRAMEWORKS:cf.id%%
|
|
|
45 |
%%FILTER_SUBCATEGORIES:cc.path%%
|
|
|
46 |
%%FILTER_STARTTIME:c.startdate:>=%% %%FILTER_ENDTIME:c.startdate:<=%%
|
|
|
47 |
|
|
|
48 |
*/
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
require_once($CFG->dirroot.'/blocks/configurable_reports/plugin.class.php');
|
|
|
52 |
|
|
|
53 |
class plugin_competencyframeworks extends plugin_base{
|
|
|
54 |
|
|
|
55 |
public function init() {
|
|
|
56 |
$this->form = false;
|
|
|
57 |
$this->unique = true;
|
|
|
58 |
$this->fullname = get_string('filtercompetencyframeworks', 'block_configurable_reports');
|
|
|
59 |
$this->reporttypes = array('courses', 'sql');
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
public function summary($data) {
|
|
|
63 |
return get_string('filtercompetencyframeworks_summary', 'block_configurable_reports');
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
public function execute($finalelements, $data) {
|
|
|
67 |
|
|
|
68 |
$filtercompetencyframeworks = optional_param('filter_competencyframeworks', 0, PARAM_INT);
|
|
|
69 |
if (!$filtercompetencyframeworks) {
|
|
|
70 |
return $finalelements;
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
if ($this->report->type != 'sql') {
|
|
|
74 |
return array($filtercompetencyframeworks);
|
|
|
75 |
} else {
|
|
|
76 |
if (preg_match("/%%FILTER_COMPETENCYFRAMEWORKS:([^%]+)%%/i", $finalelements, $output)) {
|
|
|
77 |
$replace = ' AND '.$output[1].' = '.$filtercompetencyframeworks;
|
|
|
78 |
return str_replace('%%FILTER_COMPETENCYFRAMEWORKS:'.$output[1].'%%', $replace, $finalelements);
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
return $finalelements;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
public function print_filter(&$mform) {
|
|
|
85 |
global $remotedb, $COURSE, $PAGE, $CFG;
|
|
|
86 |
|
|
|
87 |
$reportclassname = 'report_'.$this->report->type;
|
|
|
88 |
$reportclass = new $reportclassname($this->report);
|
|
|
89 |
|
|
|
90 |
if ($this->report->type != 'sql') {
|
|
|
91 |
$components = cr_unserialize($this->report->components);
|
|
|
92 |
$conditions = $components['conditions'];
|
|
|
93 |
|
|
|
94 |
$competencyframeworkslist = $reportclass->elements_by_conditions($conditions);
|
|
|
95 |
} else {
|
|
|
96 |
$sql = 'SELECT cf.id, cf.shortname
|
|
|
97 |
FROM {competency_framework} cf
|
|
|
98 |
';
|
|
|
99 |
$studentlist = $remotedb->get_records_sql($sql);
|
|
|
100 |
foreach ($studentlist as $student) {
|
|
|
101 |
$competencyframeworkslist[] = $student->userid;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
$competencyframeworksoptions = array();
|
|
|
107 |
$competencyframeworksoptions[0] = get_string('filter_all', 'block_configurable_reports');
|
|
|
108 |
|
|
|
109 |
if (!empty($competencyframeworkslist)) {
|
|
|
110 |
|
|
|
111 |
$competencyframeworks = $remotedb->get_records_sql($sql);
|
|
|
112 |
|
|
|
113 |
foreach ($competencyframeworks as $c) {
|
|
|
114 |
$competencyframeworksoptions[$c->id] = $c->shortname;
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
$elestr = get_string('competencyframeworks', 'block_configurable_reports');
|
|
|
119 |
$mform->addElement('select', 'filter_competencyframeworks', $elestr, $competencyframeworksoptions);
|
|
|
120 |
$mform->setType('filter_competencyframeworks', PARAM_INT);
|
|
|
121 |
}
|
|
|
122 |
}
|