Skip to content

Commit b133d4c

Browse files
committed
Adição de plugin para relatórios configuráveis
1 parent 90d84a1 commit b133d4c

File tree

529 files changed

+163293
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

529 files changed

+163293
-0
lines changed
+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
Configurable Reports Block
2+
3+
Installation, Documentation, Tutorials....
4+
See http://docs.moodle.org/en/blocks/configurable_reports/
5+
Also http://moodle.org/mod/data/view.php?d=13&rid=4283
6+
7+
Author: Juan Leyva
8+
<http://moodle.org/user/profile.php?id=49568>
9+
<http://twitter.com/jleyvadelgado>
10+
<http://sites.google.com/site/mooconsole/>
11+
<http://moodle-es.blogspot.com>
12+
<http://openlearningtech.blogspot.com>
13+
14+
Thanks to:
15+
Nadav Kavalerchik for developing amazing new features
16+
Ivan Breziansky for translating the block to slovak language
17+
Iñaki Arenaza for translating the block documentation to spanish
18+
Luis de Vasconcelos for testing the block
19+
Adam Olley and Netspot Moodle Partner for improving some parts of the Moodle2 version
20+
21+
Some functionalities of this plugin uses code from:
22+
23+
Admin Report: Custom SQL queries
24+
http://moodle.org/mod/data/view.php?d=13&rid=2884
25+
By Tim Hunt
26+
27+
28+
Versions history
29+
30+
31+
Added support for Moodle 2.7
32+
33+
Added new user column plugin (final grade in current course)
34+
35+
Added options for limit the max number of records in SQL queries (previously the limit was hard coded to 5000)
36+
37+
2.3.4 (2011040114)Moodle 2.2, 2.3, 2.4, 2.5, 2.6, 2.7
38+
Release date: Thursday, 26 June 2014, 18:16
39+
40+
New fullname user field column
41+
Several bug fixes
42+
43+
2.3.3 (2011040113)Moodle 2.2, 2.3, 2.4, 2.5, 2.6, 2.7
44+
Release date: Friday, 13 June 2014, 18:16
45+
46+
Fixed layout and notice/warnings problems
47+
48+
2.3.2 (2011040110)Moodle 2.2, 2.3, 2.4, 2.5, 2.6
49+
Release date: Friday, 14 February 2014, 11:14 AM
50+
51+
Several bug fixes
52+
53+
2.3.2 (2011040109)Moodle 2.2, 2.3, 2.4, 2.5, 2.6
54+
Release date: Thursday, 30 January 2014, 10:33 AM
55+
56+
Fixed invalid table reference in cron
57+
58+
2.3.2 (2011040108) for Moodle 2.2, 2.3, 2.4, 2.5m 2.6
59+
Release date Thursday, 16 January 2014, 15:25 AM
60+
Some bug fixes
61+
New CSV export
62+
63+
2.3.1 (2011040107) for Moodle 2.0, 2.1, 2.2, 2.3, 2.4, 2.5m 2.6
64+
Release date Monday, 16 December 2013, 10:25 AM
65+
Some minor bug fixes
66+
SQL syntax by default is disabled
67+
New block instance settings (change name and also show/hide global reports)
68+
New users cohorts condition
69+
70+
71+
2.3 (2011040106) for Moodle 2.0, 2.1, 2.2, 2.3, 2.4, 2.5m 2.6
72+
Release date Friday, 13 December 2013, 4:35 PM
73+
74+
Support for Moodle 2.6
75+
Multiple bugs fixed
76+
Global report that can be shared in all courses
77+
Public reports repository with multiple sample reports available
78+
Ppublic SQL queries repository
79+
Reports can run on a different DB that the current (production) DB
80+
Reports can run on a CRON scheduler
81+
Several filter plugins added
82+
Integrated DataTables.js for the report table
83+
Integrated CodeMirror.js for highlighting SQL query code, while editing.
84+
New security settings
85+
86+
Thanks to Nadav Kavalerchik for providing most of the new features
87+
88+
89+
2.2 (2011040105) for Moodle 2.0, 2.1, 2.2, 2.3, 2.4, 2.5
90+
Release date Wednesday, 27 February 2013, 9:35 AM
91+
92+
Support for Moodle 2.4 and 2.5
93+
Bugs fixed
94+
95+
96+
2.1 (2011040103) for Moodle 2.0, 2.1, 2.2, 2.3
97+
Release date Friday, 6 July 2012, 1:29 PM
98+
99+
Support for Moodle 2.3
100+
Bugs fixed
101+
102+
103+
2.0.2 (2011040102) for Moodle 2.0, 2.1, 2.2
104+
Release date Monday, 9 January 2012, 11:41 AM
105+
106+
Support for Moodle 2.2
107+
Bugs fixed
108+
109+
110+
2.0.1 (2011040101) for Moodle 2.0, 2.1
111+
Release date Thursday, 13 October 2011, 12:55 AM
112+
113+
114+
2.0 (2011040100) for Moodle 2.0, 2.1
115+
Release date Thursday, 29 September 2011, 10:47 AM
116+
117+
118+
1.0 (2010090100) for Moodle 1.9
119+
Release date Thursday, 29 September 2011, 10:38 AM
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
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+
/** Configurable Reports
18+
* A Moodle block for creating customizable reports
19+
* @package blocks
20+
* @author: Juan leyva <http://www.twitter.com/jleyvadelgado>
21+
* @date: 2009
22+
*/
23+
24+
class block_configurable_reports extends block_list {
25+
26+
/**
27+
* Sets the block name and version number
28+
*
29+
* @return void
30+
**/
31+
public function init() {
32+
$this->title = get_string('pluginname', 'block_configurable_reports');
33+
}
34+
35+
public function specialization() {
36+
if (empty($this->config->title)) {
37+
$this->title = get_string('pluginname', 'block_configurable_reports');
38+
} else {
39+
$this->title = $this->config->title;
40+
}
41+
}
42+
43+
public function instance_allow_config() {
44+
return true;
45+
}
46+
47+
/**
48+
* Where to add the block
49+
*
50+
* @return boolean
51+
**/
52+
public function applicable_formats() {
53+
return array('site' => true, 'course' => true, 'my' => true);
54+
}
55+
56+
/**
57+
* Global Config?
58+
*
59+
* @return boolean
60+
**/
61+
public function has_config() {
62+
return true;
63+
}
64+
65+
/**
66+
* More than one instance per page?
67+
*
68+
* @return boolean
69+
**/
70+
public function instance_allow_multiple() {
71+
return false;
72+
}
73+
74+
/**
75+
* Gets the contents of the block (course view)
76+
*
77+
* @return object An object with the contents
78+
**/
79+
public function get_content() {
80+
global $DB, $USER, $CFG, $COURSE;
81+
82+
if ($this->content !== null) {
83+
return $this->content;
84+
}
85+
86+
$this->content = new stdClass;
87+
$this->content->footer = '';
88+
$this->content->icons = array();
89+
90+
if (!isloggedin()) {
91+
return $this->content;
92+
}
93+
94+
require_once($CFG->dirroot."/blocks/configurable_reports/locallib.php");
95+
96+
$course = $DB->get_record('course', array('id' => $COURSE->id));
97+
98+
if (!$course) {
99+
print_error('coursedoesnotexists');
100+
}
101+
102+
if ($course->id == SITEID) {
103+
$context = context_system::instance();
104+
} else {
105+
$context = context_course::instance($course->id);
106+
}
107+
108+
// Site (Shared) reports.
109+
if (!empty($this->config->displayglobalreports)) {
110+
$reports = $DB->get_records('block_configurable_reports', array('global' => 1), 'name ASC');
111+
112+
if ($reports) {
113+
foreach ($reports as $report) {
114+
if ($report->visible && cr_check_report_permissions($report, $USER->id, $context)) {
115+
$rname = format_string($report->name);
116+
$this->content->items[] = '<a href= "'.$CFG->wwwroot.'/blocks/configurable_reports/viewreport.php?id='.$report->id.'&courseid='.$course->id.'" alt="'.$rname.'">'.$rname.'</a>';
117+
}
118+
}
119+
if (!empty($this->content->items)) {
120+
$this->content->items[] = '========';
121+
}
122+
}
123+
}
124+
125+
// Course reports.
126+
if (!property_exists($this, 'config')
127+
or !isset($this->config->displayreportslist)
128+
or $this->config->displayreportslist) {
129+
$reports = $DB->get_records('block_configurable_reports', array('courseid' => $course->id), 'name ASC');
130+
131+
if ($reports) {
132+
foreach ($reports as $report) {
133+
if (!$report->global && $report->visible && cr_check_report_permissions($report, $USER->id, $context)) {
134+
$rname = format_string($report->name);
135+
$this->content->items[] = '<a href= "'.$CFG->wwwroot.'/blocks/configurable_reports/viewreport.php?id='.$report->id.'&courseid='.$course->id.'" alt="'.$rname.'">'.$rname.'</a>';
136+
}
137+
}
138+
if (!empty($this->content->items)) {
139+
$this->content->items[] = '========';
140+
}
141+
}
142+
}
143+
144+
if (has_capability('block/configurable_reports:managereports', $context)
145+
|| has_capability('block/configurable_reports:manageownreports', $context)) {
146+
$this->content->items[] = '<a href="'.$CFG->wwwroot.'/blocks/configurable_reports/managereport.php?courseid='.$course->id.'">'.(get_string('managereports', 'block_configurable_reports')).'</a>';
147+
}
148+
149+
return $this->content;
150+
}
151+
152+
public function cron() {
153+
global $CFG, $DB;
154+
155+
$hour = get_config('block_configurable_reports', 'cron_hour');
156+
$min = get_config('block_configurable_reports', 'cron_minute');
157+
158+
$date = usergetdate(time());
159+
$usertime = mktime($date['hours'], $date['minutes'], $date['seconds'], $date['mon'], $date['mday'], $date['year']);
160+
161+
$crontime = mktime($hour, $min, $date['seconds'], $date['mon'], $date['mday'], $date['year']);
162+
163+
if ( ($crontime - $usertime) < 0 ) {
164+
return false;
165+
}
166+
167+
$lastcron = $DB->get_field('block', 'lastcron', array('name' => 'configurable_reports'));
168+
if (!$lastcron and ($lastcron + $this->cron < time()) ) {
169+
return false;
170+
}
171+
172+
// Starting to run...
173+
//$DB->set_field('blocks', 'lastcron',time(), array('name' => 'configurable_reports'));
174+
175+
require_once($CFG->dirroot."/blocks/configurable_reports/locallib.php");
176+
require_once($CFG->dirroot.'/blocks/configurable_reports/report.class.php');
177+
require_once($CFG->dirroot.'/blocks/configurable_reports/reports/sql/report.class.php');
178+
179+
mtrace("\nConfigurable report (block)");
180+
181+
$reports = $DB->get_records('block_configurable_reports');
182+
if ($reports) {
183+
foreach ($reports as $report) {
184+
// Running only SQL reports. $report->type == 'sql'.
185+
if ($report->type == 'sql' AND (!empty($report->cron) AND $report->cron == '1')) {
186+
$reportclass = new report_sql($report);
187+
188+
// Execute it using $remotedb.
189+
$starttime = microtime(true);
190+
mtrace("\nExecuting query '$report->name'");
191+
192+
$components = cr_unserialize($reportclass->config->components);
193+
$config = (isset($components['customsql']['config']))? $components['customsql']['config'] : new stdclass;
194+
$sql = $reportclass->prepare_sql($config->querysql);
195+
196+
$sqlqueries = explode(';', $sql);
197+
198+
foreach ($sqlqueries as $sql) {
199+
mtrace(substr($sql, 0, 60)); // Show some SQL.
200+
$results = $reportclass->execute_query($sql);
201+
mtrace(($results==1) ? '...OK time='.round((microtime(true) - $starttime) * 1000).'mSec' : 'Some SQL Error'.'\n');
202+
}
203+
unset($reportclass);
204+
}
205+
}
206+
}
207+
return true; // Finished OK.
208+
}
209+
210+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
// This file is part of Moodle - http://moodle.org/
4+
//
5+
// Moodle is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Moodle is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
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_base {
26+
27+
var $plugins = false;
28+
var $ordering = false;
29+
var $form = false;
30+
var $help = '';
31+
32+
function __construct($report) {
33+
global $DB, $CFG;
34+
35+
if(is_numeric($report))
36+
$this->config = $DB->get_record('block_configurable_reports',array('id' => $report));
37+
else
38+
$this->config = $report;
39+
$this->init();
40+
}
41+
42+
function add_form_elements(&$mform,$fullform){
43+
return false;
44+
}
45+
46+
}
47+

0 commit comments

Comments
 (0)