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 namespace tool_brickfield\output\activityresults; 18 19 use core\chart_bar as chart_bar; 20 use core\chart_series as chart_series; 21 use tool_brickfield\accessibility; 22 use tool_brickfield\local\tool\filter; 23 use tool_brickfield\manager; 24 25 /** 26 * tool_brickfield/activityresults renderer 27 * 28 * @package tool_brickfield 29 * @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie 30 * @author Mike Churchward 31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 32 */ 33 class renderer extends \tool_brickfield\output\renderer { 34 /** 35 * Render the page containing the activity results report. 36 * 37 * @param \stdClass $data Report data. 38 * @param filter $filter Display filters. 39 * @return String HTML showing charts. 40 * @throws \coding_exception 41 * @throws \dml_exception 42 * @throws \moodle_exception 43 */ 44 public function display(\stdClass $data, filter $filter): string { 45 $templatedata = new \stdClass(); 46 47 // Set up the page information for the template. 48 $templatedata->title = accessibility::get_title($filter, $data->countdata); 49 $templatedata->chartdesc = get_string('pagedesc:pertarget', manager::PLUGINNAME); 50 $templatedata->chartdesctitle = get_string('pagedesctitle:pertarget', manager::PLUGINNAME); 51 52 // Set up a table of data for the external renderer. 53 $labels = []; 54 $failed = []; 55 $passed = []; 56 foreach ($data->data as $rowdata) { 57 $labels[] = $rowdata->componentlabel; 58 $passed[] = $rowdata->total - $rowdata->failed; 59 $failed[] = $rowdata->failed; 60 } 61 62 $chart = new chart_bar(); 63 $chart->set_stacked(true); 64 $series1 = new chart_series(get_string('passed', manager::PLUGINNAME), $passed); 65 $series2 = new chart_series(get_string('failed', manager::PLUGINNAME), $failed); 66 $chart->add_series($series1); 67 $chart->add_series($series2); 68 $chart->set_labels($labels); 69 $chart->set_title(get_string('targetratio', manager::PLUGINNAME)); 70 71 $templatedata->chart = $this->render($chart); 72 return $this->render_from_template(manager::PLUGINNAME . '/chartsingle', $templatedata); 73 } 74 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body