From 5ed33cc95053daad83102a5668a2f2849d8ca4d3 Mon Sep 17 00:00:00 2001 From: Davo Smith Date: Thu, 25 Jun 2015 11:35:24 +0100 Subject: [PATCH] Switch status grade from integer to decimal --- db/install.xml | 2 +- db/upgrade.php | 13 +++++++++++++ export.php | 10 +++++++++- preferences.php | 8 ++++++-- renderer.php | 4 ++-- renderhelpers.php | 4 ++-- version.php | 2 +- 7 files changed, 34 insertions(+), 9 deletions(-) diff --git a/db/install.xml b/db/install.xml index b1fc454..e683ef6 100644 --- a/db/install.xml +++ b/db/install.xml @@ -68,7 +68,7 @@ - + diff --git a/db/upgrade.php b/db/upgrade.php index 75bf87e..ec1488f 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -145,5 +145,18 @@ function xmldb_attendance_upgrade($oldversion=0) { upgrade_mod_savepoint(true, 2015040502, 'attendance'); } + if ($oldversion < 2015040503) { + + // Changing type of field grade on table attendance_statuses to number. + $table = new xmldb_table('attendance_statuses'); + $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '5, 2', null, XMLDB_NOTNULL, null, '0', 'description'); + + // Launch change of type for field grade. + $dbman->change_field_type($table, $field); + + // Attendance savepoint reached. + upgrade_mod_savepoint(true, 2015040503, 'attendance'); + } + return $result; } diff --git a/export.php b/export.php index f70682b..76de1b4 100644 --- a/export.php +++ b/export.php @@ -118,6 +118,7 @@ if ($mform->is_submitted()) { } if ($reportdata->gradable) { $data->tabhead[] = get_string('grade'); + $data->tabhead[] = get_string('percentage', 'attendance'); } $i = 0; @@ -151,7 +152,14 @@ if ($mform->is_submitted()) { $cellsgenerator = new user_sessions_cells_text_generator($reportdata, $user); $data->table[$i] = array_merge($data->table[$i], $cellsgenerator->get_cells(isset($formdata->includeremarks))); if ($reportdata->gradable) { - $data->table[$i][] = $reportdata->grades[$user->id].' / '.$reportdata->maxgrades[$user->id]; + $data->table[$i][] = format_float($reportdata->grades[$user->id]).' / '. + format_float($reportdata->maxgrades[$user->id]); + if ($reportdata->maxgrades[$user->id]) { + $percent = $reportdata->grades[$user->id] * 100.0 / $reportdata->maxgrades[$user->id]; + } else { + $percent = 0.0; + } + $data->table[$i][] = $percent; } $i++; } diff --git a/preferences.php b/preferences.php index 210734e..57b53ea 100644 --- a/preferences.php +++ b/preferences.php @@ -59,7 +59,8 @@ switch ($att->pageparams->action) { case att_preferences_page_params::ACTION_ADD: $newacronym = optional_param('newacronym', null, PARAM_TEXT); $newdescription = optional_param('newdescription', null, PARAM_TEXT); - $newgrade = optional_param('newgrade', 0, PARAM_INT); + $newgrade = optional_param('newgrade', 0, PARAM_RAW); + $newgrade = unformat_float($newgrade); $att->add_status($newacronym, $newdescription, $newgrade); if ($pageparams->statusset > $maxstatusset) { @@ -103,7 +104,10 @@ switch ($att->pageparams->action) { case att_preferences_page_params::ACTION_SAVE: $acronym = required_param_array('acronym', PARAM_MULTILANG); $description = required_param_array('description', PARAM_MULTILANG); - $grade = required_param_array('grade', PARAM_INT); + $grade = required_param_array('grade', PARAM_RAW); + foreach ($grade as &$val) { + $val = unformat_float($val); + } $statuses = $att->get_statuses(false); foreach ($acronym as $id => $v) { diff --git a/renderer.php b/renderer.php index 2aad1e8..c393bf0 100644 --- a/renderer.php +++ b/renderer.php @@ -860,7 +860,7 @@ class mod_attendance_renderer extends plugin_renderer_base { } if ($reportdata->gradable) { - $row->cells[] = $reportdata->grades[$user->id].' / '.$reportdata->maxgrades[$user->id]; + $row->cells[] = format_float($reportdata->grades[$user->id]).' / '.format_float($reportdata->maxgrades[$user->id]); } if ($reportdata->sessionslog) { @@ -962,7 +962,7 @@ class mod_attendance_renderer extends plugin_renderer_base { $table->data[$i][] = $i; $table->data[$i][] = $this->construct_text_input('acronym['.$st->id.']', 2, 2, $st->acronym); $table->data[$i][] = $this->construct_text_input('description['.$st->id.']', 30, 30, $st->description); - $table->data[$i][] = $this->construct_text_input('grade['.$st->id.']', 4, 4, $st->grade); + $table->data[$i][] = $this->construct_text_input('grade['.$st->id.']', 4, 4, format_float($st->grade)); $table->data[$i][] = $this->construct_preferences_actions_icons($st, $prefdata); $i++; diff --git a/renderhelpers.php b/renderhelpers.php index 15ab178..f190c7f 100644 --- a/renderhelpers.php +++ b/renderhelpers.php @@ -237,7 +237,7 @@ function construct_user_data_stat($stat, $statuses, $gradable, $grade, $maxgrade $row = new html_table_row(); $row->cells[] = get_string('attendancegrade', 'attendance') . $OUTPUT->help_icon('gradebookexplanation', 'attendance') . ':'; - $row->cells[] = $grade . ' / ' . $maxgrade; + $row->cells[] = format_float($grade) . ' / ' . format_float($maxgrade); $stattable->data[] = $row; $row = new html_table_row(); @@ -247,7 +247,7 @@ function construct_user_data_stat($stat, $statuses, $gradable, $grade, $maxgrade } else { $percent = $grade / $maxgrade * 100; } - $row->cells[] = sprintf("%0.{$decimalpoints}f", $percent); + $row->cells[] = format_float(sprintf("%0.{$decimalpoints}f", $percent)); $stattable->data[] = $row; } diff --git a/version.php b/version.php index 7872ebf..ff213d4 100644 --- a/version.php +++ b/version.php @@ -22,7 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$plugin->version = 2015040502; +$plugin->version = 2015040503; $plugin->requires = 2014042900; $plugin->release = '2.9.1'; $plugin->maturity = MATURITY_STABLE;