From a07ec4565f36cfd5dc6838b5809c26e01d1918f8 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 20 Oct 2014 15:10:32 +0800 Subject: [PATCH] MDL-47400 gradereport_history: Ensure float precision is enforced Format floats according to the grade item config. --- .../history/classes/output/tablelog.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/grade/report/history/classes/output/tablelog.php b/grade/report/history/classes/output/tablelog.php index 3409eace13e..04c308f780c 100644 --- a/grade/report/history/classes/output/tablelog.php +++ b/grade/report/history/classes/output/tablelog.php @@ -63,6 +63,12 @@ class tablelog extends \table_sql implements \renderable { */ protected $cms; + /** + * @var int The default number of decimal points to use in this course + * when a grade item does not itself define the number of decimal points. + */ + protected $defaultdecimalpoints; + /** * Sets up the table_log parameters. * @@ -83,6 +89,7 @@ class tablelog extends \table_sql implements \renderable { */ public function __construct($uniqueid, \context_course $context, $url, $filters = array(), $download = '', $page = 0, $perpage = 100) { + global $CFG; parent::__construct($uniqueid); $this->set_attribute('class', 'gradereport_history generaltable generalbox'); @@ -96,6 +103,7 @@ class tablelog extends \table_sql implements \renderable { $this->gradeitems = \grade_item::fetch_all(array('courseid' => $this->courseid)); $this->cms = get_fast_modinfo($this->courseid); $this->useridfield = 'userid'; + $this->defaultdecimalpoints = grade_get_setting($this->courseid, 'decimalpoints', $CFG->grade_decimalpoints); // Define columns in the table. $this->define_table_columns(); @@ -167,6 +175,40 @@ class tablelog extends \table_sql implements \renderable { $this->define_headers(array_values($cols)); } + /** + * Method to display the final grade. + * + * @param \stdClass $history an entry of history record. + * + * @return string HTML to display + */ + public function col_finalgrade(\stdClass $history) { + if (!empty($this->gradeitems[$history->itemid])) { + $decimalpoints = $this->gradeitems[$history->itemid]->get_decimals(); + } else { + $decimalpoints = $this->defaultdecimalpoints; + } + + return format_float($history->finalgrade, $decimalpoints); + } + + /** + * Method to display the previous grade. + * + * @param \stdClass $history an entry of history record. + * + * @return string HTML to display + */ + public function col_prevgrade(\stdClass $history) { + if (!empty($this->gradeitems[$history->itemid])) { + $decimalpoints = $this->gradeitems[$history->itemid]->get_decimals(); + } else { + $decimalpoints = $this->defaultdecimalpoints; + } + + return format_float($history->prevgrade, $decimalpoints); + } + /** * Method to display column timemodifed. *