From 992860873b0ef6a18ce7d9ee3db0c99c6cef37c4 Mon Sep 17 00:00:00 2001 From: Luuk Verhoeven Date: Tue, 7 May 2024 17:06:36 +0200 Subject: [PATCH 1/5] Update #1 issue with filtering results when downloading --- report.class.php | 6 +++--- version.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/report.class.php b/report.class.php index 85711fd6..8f9b9c7d 100755 --- a/report.class.php +++ b/report.class.php @@ -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 .= "&{$key}[$k]=" . $v; + $wwwpath .= "&{$key}[$k]=" . $v; } } else { $val = clean_param($val, PARAM_CLEANHTML); - $wwwpath .= "&$key=" . s($val); + $wwwpath .= "&$key=" . s($val); } } } @@ -369,7 +369,7 @@ public function print_export_options(bool $return = false) { } // TODO Use moodle_url. - $output .= ' + $output .= ' ' . s($e) . '  ' . (s(strtoupper($e))) . diff --git a/version.php b/version.php index 2b20d0e3..6aa8f62e 100755 --- a/version.php +++ b/version.php @@ -27,7 +27,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2023121803; +$plugin->version = 2024050700; $plugin->requires = 2017111300; $plugin->maturity = MATURITY_STABLE; $plugin->release = '4.1.0'; From bfe6976bdea6f3008d3e91363368c7c05bc04df1 Mon Sep 17 00:00:00 2001 From: Luuk Verhoeven Date: Sat, 11 May 2024 11:30:45 +0200 Subject: [PATCH 2/5] Update #2 issue bar rendering --- components/plot/bar/graph.php | 47 ++++++++++++++++++++++++---------- components/plot/line/graph.php | 6 ++--- composer.json | 3 ++- lib/pChart2/class/pDraw.php | 2 +- version.php | 2 +- 5 files changed, 41 insertions(+), 19 deletions(-) diff --git a/components/plot/bar/graph.php b/components/plot/bar/graph.php index eff2938f..9d23fbdf 100644 --- a/components/plot/bar/graph.php +++ b/components/plot/bar/graph.php @@ -76,12 +76,16 @@ } 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() @@ -94,6 +98,7 @@ (preg_match("/[\xE0-\xFA]/", iconv("UTF-8", "ISO-8859-8", $value))) ? $reportclass->utf8_strrev($value) : $value ); } + $dataset->addPoints($invertedlabels, "Labels"); $dataset->setAbscissa("Labels"); @@ -106,9 +111,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"; @@ -126,8 +133,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; @@ -137,9 +151,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 = [ @@ -150,7 +161,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, @@ -160,13 +178,16 @@ "DisplayG" => 0, "DisplayB" => 0, "DisplayOffset" => 5, + "DrawSubTicks" => true, ]; - $mypicture->drawBarChart($chartsettings); + /* Draw the chart */ + $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(); } } diff --git a/components/plot/line/graph.php b/components/plot/line/graph.php index a56a32ff..0a53b6ef 100755 --- a/components/plot/line/graph.php +++ b/components/plot/line/graph.php @@ -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); @@ -152,4 +152,4 @@ ob_clean(); // Hack to clear output and send only IMAGE data to browser. $test->Stroke(); } -} +} \ No newline at end of file diff --git a/composer.json b/composer.json index 53deb434..70c90c89 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,8 @@ "license": "GPL-3.0+", "require": { "composer/installers": "*", - "ext-json": "*" + "ext-json": "*", + "ext-iconv": "*" }, "extra": { "installer-name": "configurable_reports" diff --git a/lib/pChart2/class/pDraw.php b/lib/pChart2/class/pDraw.php index 9f62e88f..8a9a02d2 100644 --- a/lib/pChart2/class/pDraw.php +++ b/lib/pChart2/class/pDraw.php @@ -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; diff --git a/version.php b/version.php index 6aa8f62e..418c6272 100755 --- a/version.php +++ b/version.php @@ -27,7 +27,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024050700; +$plugin->version = 2024051100; $plugin->requires = 2017111300; $plugin->maturity = MATURITY_STABLE; $plugin->release = '4.1.0'; From 45f1938d2d79a3ae9c03032aa257f33076ae85e5 Mon Sep 17 00:00:00 2001 From: Luuk Verhoeven Date: Mon, 13 May 2024 12:02:51 +0200 Subject: [PATCH 3/5] Update code style for CI --- component.class.php | 6 ++++-- components/conditions/component.class.php | 10 ++++++++++ components/plot/bar/graph.php | 9 ++++----- components/plot/line/graph.php | 2 +- locallib.php | 10 ++++------ reports/timeline/report.class.php | 10 ++++++++++ 6 files changed, 33 insertions(+), 14 deletions(-) diff --git a/component.class.php b/component.class.php index 1af16c9e..4a197370 100755 --- a/component.class.php +++ b/component.class.php @@ -26,8 +26,10 @@ /** * Class component_base * - * @package block_configurable_reports - * @author Juan leyva + * @copyright 2020 Juan Leyva + * @package block_configurable_reports + * @author Juan leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ abstract class component_base { diff --git a/components/conditions/component.class.php b/components/conditions/component.class.php index fe7688b1..22a0bda9 100755 --- a/components/conditions/component.class.php +++ b/components/conditions/component.class.php @@ -20,6 +20,16 @@ * @copyright 2020 Juan Leyva * @package block_configurable_reports * @author Juan leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Class component_conditions + * + * @copyright 2020 Juan Leyva + * @package block_configurable_reports + * @author Juan leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class component_conditions extends component_base { diff --git a/components/plot/bar/graph.php b/components/plot/bar/graph.php index 9d23fbdf..ebd3c20d 100644 --- a/components/plot/bar/graph.php +++ b/components/plot/bar/graph.php @@ -76,7 +76,6 @@ } if ($g['id'] == $id) { - // 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"); @@ -139,7 +138,7 @@ $mypicture->setFontProperties([ "FontName" => "$fontpath/Cairo-Regular.ttf", "FontSize" => $fontsize, - "Color" => new \pChart\pColor(0 , 0 , 0), + "Color" => new \pChart\pColor(0, 0, 0), ]); [$legendwidth, $legendheight] = array_values($mypicture->getLegendSize()); @@ -180,9 +179,9 @@ "DisplayOffset" => 5, "DrawSubTicks" => true, ]; - /* Draw the chart */ - $pCharts = new \pChart\pCharts($mypicture); - $pCharts->drawBarChart($chartsettings); + + $pcharts = new \pChart\pCharts($mypicture); + $pcharts->drawBarChart($chartsettings); $mypicture->setShadow(false); $mypicture->drawLegend($legendx, $legendy); diff --git a/components/plot/line/graph.php b/components/plot/line/graph.php index 0a53b6ef..102a60ac 100755 --- a/components/plot/line/graph.php +++ b/components/plot/line/graph.php @@ -152,4 +152,4 @@ ob_clean(); // Hack to clear output and send only IMAGE data to browser. $test->Stroke(); } -} \ No newline at end of file +} diff --git a/locallib.php b/locallib.php index c757797d..89a5c27e 100755 --- a/locallib.php +++ b/locallib.php @@ -29,8 +29,7 @@ * @return void */ function cr_print_js_function() { - ?> - - '; } /** diff --git a/reports/timeline/report.class.php b/reports/timeline/report.class.php index 4f76d0c5..9f0c85de 100755 --- a/reports/timeline/report.class.php +++ b/reports/timeline/report.class.php @@ -20,6 +20,16 @@ * @copyright 2020 Juan Leyva * @package block_configurable_reports * @author Juan leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Class report_timeline + * + * @copyright 2020 Juan Leyva + * @package block_configurable_reports + * @author Juan leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class report_timeline extends report_base { From 370c2e3f652731cff6fdb138ae8feb1e6d442661 Mon Sep 17 00:00:00 2001 From: Luuk Verhoeven Date: Mon, 13 May 2024 23:34:31 +0200 Subject: [PATCH 4/5] Add error handling on graph when error in not countable series --- components/plot/line/graph.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/components/plot/line/graph.php b/components/plot/line/graph.php index 102a60ac..05e76728 100755 --- a/components/plot/line/graph.php +++ b/components/plot/line/graph.php @@ -66,7 +66,6 @@ $components = cr_unserialize($report->components); $graphs = $components['plot']['elements']; - if (!empty($graphs)) { $series = []; foreach ($graphs as $g) { @@ -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); @@ -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)) { @@ -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"); From 8ded58f91b9cc4d00c83677288f1db6319189d1c Mon Sep 17 00:00:00 2001 From: Luuk Verhoeven Date: Mon, 13 May 2024 23:34:57 +0200 Subject: [PATCH 5/5] Update version number --- version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.php b/version.php index 418c6272..69f2d3f4 100755 --- a/version.php +++ b/version.php @@ -27,7 +27,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024051100; +$plugin->version = 2024051300; $plugin->requires = 2017111300; $plugin->maturity = MATURITY_STABLE; $plugin->release = '4.1.0';