Skip to content

Commit

Permalink
Fixes #25 score display for range grade
Browse files Browse the repository at this point in the history
  • Loading branch information
gbarat87 committed Jun 9, 2024
1 parent 69a1bbb commit d0ca9db
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions classes/rubric_ranges.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
Expand Down
28 changes: 17 additions & 11 deletions tests/locallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -273,25 +269,35 @@ 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',
],
'Pictures' => [
'score' => 2,
'remark' => 'These picture are ok',
]
],
]);
$instance->update($result);
$this->assertInstanceOf(gradingform_rubric_ranges_controller::class, $controllerrange);
Expand Down

0 comments on commit d0ca9db

Please sign in to comment.