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 |
require_once($CFG->dirroot.'/blocks/configurable_reports/plugin.class.php');
|
|
|
26 |
|
|
|
27 |
class plugin_line extends plugin_base {
|
|
|
28 |
|
|
|
29 |
public function init() {
|
|
|
30 |
$this->fullname = get_string('line', 'block_configurable_reports');
|
|
|
31 |
$this->form = true;
|
|
|
32 |
$this->ordering = true;
|
|
|
33 |
$this->reporttypes = array('timeline', 'sql', 'timeline');
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
public function summary($data) {
|
|
|
37 |
return get_string('linesummary', 'block_configurable_reports');
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
// Data -> Plugin configuration data.
|
|
|
41 |
public function execute($id, $data, $finalreport) {
|
|
|
42 |
global $DB, $CFG;
|
|
|
43 |
|
|
|
44 |
$series = array();
|
|
|
45 |
$data->xaxis--;
|
|
|
46 |
$data->yaxis--;
|
|
|
47 |
$data->serieid--;
|
|
|
48 |
$minvalue = 0;
|
|
|
49 |
$maxvalue = 0;
|
|
|
50 |
|
|
|
51 |
if ($finalreport) {
|
|
|
52 |
foreach ($finalreport as $r) {
|
|
|
53 |
$hash = md5(strtolower($r[$data->serieid]));
|
|
|
54 |
$sname[$hash] = $r[$data->serieid];
|
|
|
55 |
$val = (isset($r[$data->yaxis]) && is_numeric($r[$data->yaxis])) ? $r[$data->yaxis] : 0;
|
|
|
56 |
$series[$hash][] = $val;
|
|
|
57 |
$minvalue = ($val < $minvalue) ? $val : $minvalue;
|
|
|
58 |
$maxvalue = ($val > $maxvalue) ? $val : $maxvalue;
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
$params = '';
|
|
|
63 |
|
|
|
64 |
$i = 0;
|
|
|
65 |
foreach ($series as $h => $s) {
|
|
|
66 |
$params .= "&serie$i=".base64_encode($sname[$h].'||'.implode(',', $s));
|
|
|
67 |
$i++;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
return $CFG->wwwroot.'/blocks/configurable_reports/components/plot/line/graph.php?reportid='.$this->report->id.'&id='.$id.$params.'&min='.$minvalue.'&max='.$maxvalue;
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
public function get_series($data) {
|
|
|
74 |
$series = array();
|
|
|
75 |
foreach ($_GET as $key => $val) {
|
|
|
76 |
if (strpos($key, 'serie') !== false) {
|
|
|
77 |
$id = (int) str_replace('serie', '', $key);
|
|
|
78 |
list($name, $values) = explode('||', base64_decode($val));
|
|
|
79 |
$series[$id] = array('serie' => explode(',', $values), 'name' => $name);
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
return $series;
|
|
|
83 |
}
|
|
|
84 |
}
|