From d0ca9db03af2fc92d53838681ba0d69f2569f1a1 Mon Sep 17 00:00:00 2001 From: Guillaume Barat Date: Sun, 9 Jun 2024 16:50:07 +1000 Subject: [PATCH] Fixes #25 score display for range grade --- classes/rubric_ranges.php | 4 ++-- locallib.php | 2 +- tests/locallib_test.php | 28 +++++++++++++++++----------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/classes/rubric_ranges.php b/classes/rubric_ranges.php index f3965f1..59bd80b 100644 --- a/classes/rubric_ranges.php +++ b/classes/rubric_ranges.php @@ -76,7 +76,7 @@ public function get_data(\assign $assign, \cm_info $cm): array { $sql = "SELECT grf.id as grfid, cm.course, asg.name as assignment,asg.grade as gradeoutof, criteria.description, level.score, - level.definition, grf.remark, grf.criterionid, + level.definition, grf.remark, grf.grade as grade_rub_range, grf.criterionid, stu.id AS userid, stu.idnumber AS idnumber, stu.firstname, stu.lastname, stu.username, stu.username, stu.email, rubm.username AS grader, @@ -96,7 +96,7 @@ public function get_data(\assign $assign, \cm_info $cm): array { JOIN {user} rubm ON rubm.id = ag.grader JOIN {gradingform_rubric_ranges_f} grf ON (grf.instanceid = gin.id) AND (grf.criterionid = criteria.id) AND (grf.levelid = level.id) - WHERE cm.id = :assignid + WHERE cm.id = :assignid AND stu.deleted = 0 ORDER BY lastname ASC, firstname ASC, userid ASC, criteria.sortorder ASC"; $data = $DB->get_records_sql($sql, ['assignid' => $cm->id]); $data = set_blindmarking($data, $assign, $cm); diff --git a/locallib.php b/locallib.php index 03505b6..aac7d98 100755 --- a/locallib.php +++ b/locallib.php @@ -241,7 +241,7 @@ function get_grades(array $data, array $dbrecords): array { $data['criterion'][$grade->criterionid] = $grade->description; $g[$grade->userid][$grade->criterionid] = [ 'userid' => $grade->userid, - 'score' => number_format($grade->score, 2), + 'score' => number_format($grade->grade_rub_range ?? $grade->score, 2), 'definition' => $grade->definition ?? "", 'feedback' => $grade->remark ]; diff --git a/tests/locallib_test.php b/tests/locallib_test.php index c2a2b96..a1e0df4 100644 --- a/tests/locallib_test.php +++ b/tests/locallib_test.php @@ -36,12 +36,7 @@ use context_module; use core_component; -use core_grades\component_gradeitem; use gradingform_rubric_ranges_controller; -use gradingform_rubric_ranges_generator; -use report_advancedgrading\rubric_ranges; -use report_advancedgrading\rubric; -use report_advancedgrading\guide; /** * Class report @@ -262,6 +257,7 @@ public function test_guide() { * @return void */ public function test_rubric_ranges() { + global $DB, $USER; $this->resetAfterTest(); if (core_component::get_plugin_directory('gradingform', 'rubric_ranges') === null) { @@ -273,17 +269,27 @@ public function test_rubric_ranges() { $rubricgenerator = $generator->get_plugin_generator('gradingform_rubric_ranges'); // Create items required for testing. $course = $this->getDataGenerator()->create_course(); - $module = $generator->create_module('assign', ['course' => $course]); + $module = $generator->create_module('assign', ['course' => $course, 'name' => 'Rubric Range']); $context = context_module::instance($module->cmid); $user = $this->getDataGenerator()->create_user(); $cm = get_coursemodule_from_instance('assign', $module->id); $this->setUser($user); $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); $controllerrange = $rubricgenerator->get_test_rubric_ranges($context, 'assign', 'submissions'); - $instance = $controllerrange->create_instance($student->id, 1); - // Insert grade, contains itemid, spellingscore, spellingremark, picturescore, pictureremark. - // Itemid from rubric range generator. - $result = $rubricgenerator->get_submitted_form_data($controllerrange, 409016, [ + $itemid = $DB->get_field('assign', 'id', ['name' => 'Rubric Range']); + $instance = $controllerrange->create_instance($student->id, $itemid); + // Set assign grade data. + $assigngrade = new \stdClass(); + $assigngrade->assignment = $module->id; + $assigngrade->userid = $student->id; + $assigngrade->timecreated = time(); + $assigngrade->timemodified = $assigngrade->timecreated; + $assigngrade->grader = $USER->id; + $assigngrade->grade = 50; + $assigngrade->attemptnumber = 0; + // Get an assign grade ID for submitted data. + $gid = $DB->insert_record('assign_grades', $assigngrade); + $result = $rubricgenerator->get_submitted_form_data($controllerrange, $gid, [ 'Spelling is important' => [ 'score' => 5, 'remark' => 'Looks good to me', @@ -291,7 +297,7 @@ public function test_rubric_ranges() { 'Pictures' => [ 'score' => 2, 'remark' => 'These picture are ok', - ] + ], ]); $instance->update($result); $this->assertInstanceOf(gradingform_rubric_ranges_controller::class, $controllerrange);