Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with downloading a filtered report #248

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions component.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
/**
* Class component_base
*
* @package block_configurable_reports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
* @copyright 2020 Juan Leyva <[email protected]>
* @package block_configurable_reports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class component_base {

Expand Down
10 changes: 10 additions & 0 deletions components/conditions/component.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
* @copyright 2020 Juan Leyva <[email protected]>
* @package block_configurable_reports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* Class component_conditions
*
* @copyright 2020 Juan Leyva <[email protected]>
* @package block_configurable_reports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class component_conditions extends component_base {

Expand Down
46 changes: 33 additions & 13 deletions components/plot/bar/graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@
}

if ($g['id'] == $id) {
include($CFG->dirroot . "/blocks/configurable_reports/lib/pChart2/class/pDraw.class.php");
include($CFG->dirroot . "/blocks/configurable_reports/lib/pChart2/class/pData.class.php");
include($CFG->dirroot . "/blocks/configurable_reports/lib/pChart2/class/pImage.class.php");
require_once($CFG->dirroot . "/blocks/configurable_reports/lib/pChart2/class/pDraw.php");
require_once($CFG->dirroot . "/blocks/configurable_reports/lib/pChart2/class/pData.php");
require_once($CFG->dirroot . "/blocks/configurable_reports/lib/pChart2/class/pColor.php");
require_once($CFG->dirroot . "/blocks/configurable_reports/lib/pChart2/class/pException.php");
require_once($CFG->dirroot . "/blocks/configurable_reports/lib/pChart2/class/pCharts.php");

// Dataset definition.
$dataset = new pData();

$dataset = new \pChart\pData();
$labels = array_shift($series);

// Invert/Reverse Hebrew labels so it can be rendered using PHP imagettftext()
Expand All @@ -94,6 +97,7 @@
(preg_match("/[\xE0-\xFA]/", iconv("UTF-8", "ISO-8859-8", $value))) ? $reportclass->utf8_strrev($value) : $value
);
}

$dataset->addPoints($invertedlabels, "Labels");
$dataset->setAbscissa("Labels");

Expand All @@ -106,9 +110,11 @@

$width = property_exists($g['formdata'], "width") ? $g['formdata']->width : 900;
$height = property_exists($g['formdata'], "height") ? $g['formdata']->height : 500;

$colorr = property_exists($g['formdata'], "color_r") ? $g['formdata']->color_r : 170;
$colorg = property_exists($g['formdata'], "color_g") ? $g['formdata']->color_g : 183;
$colorb = property_exists($g['formdata'], "color_b") ? $g['formdata']->color_b : 87;

$padding = 30;
$fontsize = 8;
$fontpath = $CFG->dirroot . "/blocks/configurable_reports/lib/pChart2/fonts";
Expand All @@ -126,8 +132,15 @@
$legendoffset = $maxlegendoffset;
}

$mypicture = new pImage($width, $height, $dataset);
$mypicture->setFontProperties(["FontName" => "$fontpath/calibri.ttf", "FontSize" => $fontsize]);
$mypicture = new \pChart\pDraw($width, $height);
$mypicture->myData = $dataset;

$mypicture->setFontProperties([
"FontName" => "$fontpath/Cairo-Regular.ttf",
"FontSize" => $fontsize,
"Color" => new \pChart\pColor(0, 0, 0),
]);

[$legendwidth, $legendheight] = array_values($mypicture->getLegendSize());
$legendx = $width - $legendwidth - $padding;
$legendy = $padding;
Expand All @@ -137,9 +150,6 @@
$graphy = $padding;
$graphwidth = $legendx - $padding;
$graphheight = $height - $labeloffset;

$bgsettings = ['R' => 225, 'G' => 225, 'B' => 225];
$mypicture->drawFilledRectangle(0, 0, $width + 2, $height + 2, $bgsettings);
$mypicture->setGraphArea($graphx, $graphy, $graphwidth, $graphheight);

$scalesettings = [
Expand All @@ -150,7 +160,14 @@
"DrawSubTicks" => true,
];
$mypicture->drawScale($scalesettings);
$mypicture->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
$mypicture->setShadow(true, [
"X" => 1,
"Y" => 1,
"R" => 0,
"G" => 0,
"B" => 0,
"Alpha" => 10,
]);

$chartsettings = [
"DisplayValues" => true,
Expand All @@ -160,13 +177,16 @@
"DisplayG" => 0,
"DisplayB" => 0,
"DisplayOffset" => 5,
"DrawSubTicks" => true,
];
$mypicture->drawBarChart($chartsettings);

$pcharts = new \pChart\pCharts($mypicture);
$pcharts->drawBarChart($chartsettings);

$mypicture->setShadow(false);
$mypicture->drawLegend($legendx, $legendy);
$mypicture->stroke();

// Hack to clear output and send only IMAGE data to browser.
ob_clean();
$mypicture->autoOutput();
}
}
23 changes: 16 additions & 7 deletions components/plot/line/graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

require_login();

error_reporting(0);
ini_set('display_erros', false);
// error_reporting(E_ALL);
// ini_set('display_erros', true);

$id = required_param('id', PARAM_ALPHANUM);
$reportid = required_param('reportid', PARAM_INT);
Expand Down Expand Up @@ -66,7 +66,6 @@

$components = cr_unserialize($report->components);
$graphs = $components['plot']['elements'];

if (!empty($graphs)) {
$series = [];
foreach ($graphs as $g) {
Expand All @@ -80,7 +79,6 @@
}

if ($g['id'] == $id) {

$min = optional_param('min', 0, PARAM_INT);
$max = optional_param('max', 0, PARAM_INT);
$abcise = optional_param('abcise', -1, PARAM_INT);
Expand All @@ -98,10 +96,16 @@
// Dataset definition.
$dataset = new pData;
$lastid = 0;

foreach ($series as $key => $val) {
$dataset->AddPoint($val['serie'], "Serie$key");
$dataset->AddAllSeries("Serie$key");
$lastid = $key;

try {
$dataset->AddPoint($val['serie'], "Serie$key");
$dataset->AddAllSeries();
$lastid = $key;
} catch (Throwable $e) {
continue;
}
}

if (!empty($abciselabel)) {
Expand All @@ -114,6 +118,11 @@

foreach ($series as $key => $val) {
$value = $val['name'];

if (!is_countable($value)) {
continue;
}

$ishebrew = preg_match("/[\xE0-\xFA]/", iconv("UTF-8", "ISO-8859-8", $value));
$fixedvalue = ($ishebrew == 1) ? $reportclass->utf8_strrev($value) : $value;
$dataset->SetSerieName($fixedvalue, "Serie$key");
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"license": "GPL-3.0+",
"require": {
"composer/installers": "*",
"ext-json": "*"
"ext-json": "*",
"ext-iconv": "*"
},
"extra": {
"installer-name": "configurable_reports"
Expand Down
2 changes: 1 addition & 1 deletion lib/pChart2/class/pDraw.php
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ private function drawAlphaPixel($X, $Y, array $ColorA) # FAST
}

/* Allocate a color with transparency */
private function allocateColor(array $ColorA) # FAST
public function allocateColor(array $ColorA) # FAST
{
($ColorA[3] < 0) AND $ColorA[3] = 0;
($ColorA[3] > 100) AND $ColorA[3] = 100;
Expand Down
10 changes: 4 additions & 6 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,25 @@
* @return void
*/
function cr_print_js_function() {
?>
<script>
echo '<script>
function printDiv(id) {
let cdiv, tmpw;

cdiv = document.getElementById(id);
tmpw = window.open(" ", "Print");

tmpw.document.open();
tmpw.document.write('<html><body>');
tmpw.document.write(\'<html><body>\');
tmpw.document.write(cdiv.innerHTML);
tmpw.document.write('</body></html>');
tmpw.document.write(\'</body></html>\');
tmpw.document.close();

setTimeout(function() {
tmpw.print();
tmpw.close();
}, 1000);
}
</script>
<?php
</script>';
}

/**
Expand Down
6 changes: 3 additions & 3 deletions report.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,11 @@ public function print_export_options(bool $return = false) {
foreach ($val as $k => $v) {
$k = s(clean_param($k, PARAM_CLEANHTML));
$v = s(clean_param($v, PARAM_CLEANHTML));
$wwwpath .= "&amp;{$key}[$k]=" . $v;
$wwwpath .= "&{$key}[$k]=" . $v;
}
} else {
$val = clean_param($val, PARAM_CLEANHTML);
$wwwpath .= "&amp;$key=" . s($val);
$wwwpath .= "&$key=" . s($val);
}
}
}
Expand All @@ -369,7 +369,7 @@ public function print_export_options(bool $return = false) {
}

// TODO Use moodle_url.
$output .= '<a href="' . s($wwwpath) . '&amp;download=1&amp;format=' . s($e) . '">
$output .= '<a href="' . s($wwwpath) . '&download=1&format=' . s($e) . '">
<img src="' . $CFG->wwwroot . '/blocks/configurable_reports/export/' . s($e) . '/pix.gif"
alt="' . s($e) . '">
&nbsp;' . (s(strtoupper($e))) .
Expand Down
10 changes: 10 additions & 0 deletions reports/timeline/report.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
* @copyright 2020 Juan Leyva <[email protected]>
* @package block_configurable_reports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* Class report_timeline
*
* @copyright 2020 Juan Leyva <[email protected]>
* @package block_configurable_reports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class report_timeline extends report_base {

Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2023121803;
$plugin->version = 2024051300;
$plugin->requires = 2017111300;
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '4.1.0';
Expand Down
Loading