From 3482681ee715ec4b206844967a5369a1d1c79346 Mon Sep 17 00:00:00 2001 From: "LAPTOP-9FMD6JDC\\marce" Date: Wed, 22 Feb 2023 17:45:47 -0300 Subject: [PATCH] Fixes jleyva/moodle-block_configurablereports#147 --- components/plot/bar/graph.php | 5 ++++- components/plot/bar/plugin.class.php | 2 +- components/plot/line/graph.php | 5 ++++- components/plot/line/plugin.class.php | 2 +- components/plot/pie/graph.php | 5 ++++- components/plot/pie/plugin.class.php | 2 +- 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/components/plot/bar/graph.php b/components/plot/bar/graph.php index eed88b14..08c26679 100644 --- a/components/plot/bar/graph.php +++ b/components/plot/bar/graph.php @@ -29,12 +29,15 @@ $id = required_param('id', PARAM_ALPHANUM); $reportid = required_param('reportid', PARAM_INT); +$courseid = optional_param('courseid', null, PARAM_INT); if (!$report = $DB->get_record('block_configurable_reports', array('id' => $reportid))) { print_error('reportdoesnotexists'); } -$courseid = $report->courseid; +if (!$courseid || !$report->global) { + $courseid = $report->courseid; +} if (!$course = $DB->get_record('course', array('id' => $courseid))) { print_error('No such course id'); diff --git a/components/plot/bar/plugin.class.php b/components/plot/bar/plugin.class.php index ff240011..489441a6 100755 --- a/components/plot/bar/plugin.class.php +++ b/components/plot/bar/plugin.class.php @@ -74,7 +74,7 @@ public function execute($id, $data, $finalreport) { $graphdata = urlencode(json_encode($series)); - return $CFG->wwwroot.'/blocks/configurable_reports/components/plot/bar/graph.php?reportid='.$this->report->id.'&id='.$id.'&graphdata='.$graphdata; + return $CFG->wwwroot.'/blocks/configurable_reports/components/plot/bar/graph.php?reportid='.$this->report->id.'&courseid='.$this->report->courseid.'&id='.$id.'&graphdata='.$graphdata; } public function get_series($data) { diff --git a/components/plot/line/graph.php b/components/plot/line/graph.php index b1983d54..192d9847 100755 --- a/components/plot/line/graph.php +++ b/components/plot/line/graph.php @@ -32,12 +32,15 @@ $id = required_param('id', PARAM_ALPHANUM); $reportid = required_param('reportid', PARAM_INT); +$courseid = optional_param('courseid', null, PARAM_INT); if (!$report = $DB->get_record('block_configurable_reports', array('id' => $reportid))) { print_error('reportdoesnotexists'); } -$courseid = $report->courseid; +if (!$courseid || !$report->global) { + $courseid = $report->courseid; +} if (!$course = $DB->get_record('course', array('id' => $courseid))) { print_error('No such course id'); diff --git a/components/plot/line/plugin.class.php b/components/plot/line/plugin.class.php index 364edb87..a9c7088e 100755 --- a/components/plot/line/plugin.class.php +++ b/components/plot/line/plugin.class.php @@ -67,7 +67,7 @@ public function execute($id, $data, $finalreport) { $i++; } - return $CFG->wwwroot.'/blocks/configurable_reports/components/plot/line/graph.php?reportid='.$this->report->id.'&id='.$id.$params.'&min='.$minvalue.'&max='.$maxvalue; + return $CFG->wwwroot.'/blocks/configurable_reports/components/plot/line/graph.php?reportid='.$this->report->id.'&courseid='.$this->report->courseid.'&id='.$id.$params.'&min='.$minvalue.'&max='.$maxvalue; } public function get_series($data) { diff --git a/components/plot/pie/graph.php b/components/plot/pie/graph.php index 88ec71ce..23d71e2d 100755 --- a/components/plot/pie/graph.php +++ b/components/plot/pie/graph.php @@ -32,12 +32,15 @@ $id = required_param('id', PARAM_ALPHANUM); $reportid = required_param('reportid', PARAM_INT); +$courseid = optional_param('courseid', null, PARAM_INT); if (!$report = $DB->get_record('block_configurable_reports', array('id' => $reportid))) { print_error('reportdoesnotexists'); } -$courseid = $report->courseid; +if (!$courseid || !$report->global) { + $courseid = $report->courseid; +} if (!$course = $DB->get_record('course', array('id' => $courseid))) { print_error("No such course id"); diff --git a/components/plot/pie/plugin.class.php b/components/plot/pie/plugin.class.php index 4cd9e068..474715dc 100755 --- a/components/plot/pie/plugin.class.php +++ b/components/plot/pie/plugin.class.php @@ -118,7 +118,7 @@ public function execute($id, $data, $finalreport) { $serie1 = base64_encode(implode(',', $serie1sorted)); $colorpalette = base64_encode(implode(',', $colors)); - return $CFG->wwwroot.'/blocks/configurable_reports/components/plot/pie/graph.php?reportid='.$this->report->id.'&id='.$id.'&serie0='.$serie0.'&serie1='.$serie1.'&colorpalette='.$colorpalette; + return $CFG->wwwroot.'/blocks/configurable_reports/components/plot/pie/graph.php?reportid='.$this->report->id.'&courseid='.$this->report->courseid.'&id='.$id.'&serie0='.$serie0.'&serie1='.$serie1.'&colorpalette='.$colorpalette; } public function get_series($data) {