This gets a thumbs up from the CodeChecker.
Thanks for your help Mary, let me know if you need anything else from me.
----
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This is a one-line short description of the file.
*
* You can have a rather longer description of the file as well,
* if you like, and it can span multiple lines.
*
* @package THEMENAME
* @category theme
* @copyright 2017 XXX
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . "/mod/studentquiz/renderer.php");
class theme_THEMENAME_mod_studentquiz_renderer extends mod_studentquiz_renderer {
public function render_stat_block($report) {
// TODO: Refactor: use mod_studentquiz_report_record_type!
$userstats = $report->get_user_stats();
$sqstats = $report->get_studentquiz_stats();
if (!$userstats) {
$bc = new block_contents();
$bc->attributes['id'] = 'mod_studentquiz_statblock';
$bc->attributes['role'] = 'navigation';
$bc->attributes['aria-labelledby'] = 'mod_studentquiz_navblock_title';
$bc->title = html_writer::span(get_string('statistic_block_title', 'studentquiz'));
$bc->content = get_string('please_enrole_message', 'studentquiz');
return $bc;
}
$bc = new block_contents();
$bc->attributes['id'] = 'mod_studentquiz_statblock';
$bc->attributes['role'] = 'navigation';
$bc->attributes['aria-labelledby'] = 'mod_studentquiz_navblock_title';
$bc->title = html_writer::span(get_string('statistic_block_title', 'studentquiz'));
$info1 = new stdClass();
$info1->total = $sqstats->questions_available;
$info1->group = $userstats->last_attempt_exists;
$info1->one = $userstats->last_attempt_correct;
$info2 = new stdClass();
$info2->total = $userstats->questions_created;
$info2->group = 0;
$info2->one = $userstats->questions_approved;
$bc->content = html_writer::div($this->render_progress_bar($info1), '', array('style' => 'width:inherit'))
. html_writer::div(
get_string('statistic_block_progress_last_attempt_correct', 'studentquiz')
.html_writer::span('<b class="stat last-attempt-correct">' .$userstats->last_attempt_correct .'</b>', '',
array('style' => 'float: right;color:#5cb85c;')))
. html_writer::div(
get_string('statistic_block_progress_last_attempt_incorrect', 'studentquiz')
.html_writer::span('<b class="stat last-attempt-incorrect">' .$userstats->last_attempt_incorrect .'</b>', '',
array('style' => 'float: right;color:#d9534f;')))
. html_writer::div(
get_string('statistic_block_progress_never', 'studentquiz')
.html_writer::span(
'<b class="stat never-answered">' . ($sqstats->questions_available - $userstats->last_attempt_exists) .'</b>',
'', array('style' => 'float: right;color:#f0ad4e;')));
return $bc;
}
public function render_progress_bar($info, $texttotal=null, $bicolor=false) {
// Check input.
$validinput = true;
if (!isset($info->total)) {
$validinput = false;
}
if (!isset($info->group)) {
$validinput = false;
}
if (!isset($info->one)) {
$validinput = false;
}
// Stylings.
$rgbstroke = 'rgb(1, 22, 39)';
$rgbyellow = 'rgb(255, 159, 28)';
$rgbgreen = 'rgb(46, 196, 182)';
$rgbblue = 'rgb(2, 117, 216)';
$rgbred = 'rgb(231, 29, 54)';
$rgbgrey = 'rgb(253, 255, 252)';
$barstroke = 'stroke-width:0.1;stroke:' . $rgbstroke .';';
$svgdims = array('width' => '100%', 'height' => 20);
$bardims = array('height' => '100%', 'rx' => 5, 'ry' => 5);
$idblue = 'blue';
$idgreen = 'green';
$idred = 'red';
$gradientdims = array('cx' => '50%', 'cy' => '50%', 'r' => '50%', 'fx' => '50%', 'fy' => '50%');
$stopcolorgreen = html_writer::tag('stop', null,
array('offset' => '100%', 'style' => 'stop-color:' . $rgbgreen . ';stop-opacity:1'));
$stopcolorred = html_writer::tag('stop', null,
array('offset' => '100%', 'style' => 'stop-color:' . $rgbred . ';stop-opacity:1'));
$stopcolorblue = html_writer::tag('stop', null,
array('offset' => '100%', 'style' => 'stop-color:' . $rgbblue . ';stop-opacity:1'));
$gradientblue = html_writer::tag('radialGradient', $stopcolorblue . $stopcolorblue,
array_merge($gradientdims, array('id' => $idblue)));
$gradientred = html_writer::tag('radialGradient', $stopcolorred . $stopcolorred,
array_merge($gradientdims, array('id' => $idred)));
$gradientgreen = html_writer::tag('radialGradient', $stopcolorgreen . $stopcolorgreen,
array_merge($gradientdims, array('id' => $idgreen)));
$gradients = array($gradientred, $gradientgreen, $gradientblue);
$defs = html_writer::tag('defs', implode($gradients));
// Background bar.
if ($bicolor) {
$barbackground = html_writer::tag('rect', null, array_merge($bardims,
array('width' => '100%', 'style' => $barstroke . 'fill:' . $rgbgrey )));
} else {
$barbackground = html_writer::tag('rect', null, array_merge($bardims,
array('width' => '100%', 'style' => $barstroke . 'fill:' . $rgbyellow)));
}
// Return empty bar if no questions are in StudentQuiz.
if (!$validinput || $info->total <= 0) {
return html_writer::tag('svg', $barbackground, $svgdims);
}
// Calculate Percentages to display.
$percentgroup = round(100 * ($info->group / $info->total));
$percentone = round(100 * ($info->one / $info->total));
if (!empty($texttotal)) {
$text = '<text xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif"'
.' font-size="12" font-weight="bold" id="svg_text" x="50%" y="50%" alignment-baseline="middle"'
.' text-anchor="middle" stroke-width="0" stroke="#000" fill="#000000">TEST' . $texttotal . '</text>';
} else {
$text = '';
}
// Return stacked bars.
$bars = array($barbackground);
if ($bicolor) {
$bars[] = html_writer::tag('rect', null, array_merge($bardims,
array('width' => $percentone . '%', 'style' => $barstroke . 'fill:url(#' . $idblue .')')));
} else {
$bars[] = html_writer::tag('rect', null, array_merge($bardims,
array('width' => $percentgroup . '%', 'style' => $barstroke . 'fill:#e71d36)')));
$bars[] = html_writer::tag('rect', null, array_merge($bardims,
array('width' => $percentone . '%', 'style' => $barstroke . 'fill:#2ec4b6')));
}
return html_writer::tag('svg', $defs . implode($bars) . $text, $svgdims);
}
}