Skip to content

Commit

Permalink
MDL-48633 mod_lesson: Fix lesson grade handling when scales in use
Browse files Browse the repository at this point in the history
  • Loading branch information
golenkovm committed Mar 22, 2022
1 parent 8a5bea2 commit a01201e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
31 changes: 23 additions & 8 deletions mod/lesson/locallib.php
Expand Up @@ -3499,6 +3499,7 @@ public function process_eol_page($outoftime) {
'displayscorewithessays' => false,
'displayscorewithoutessays' => false,
'yourcurrentgradeisoutof' => false,
'yourcurrentgradeis' => false,
'eolstudentoutoftimenoanswers' => false,
'welldone' => false,
'progressbar' => false,
Expand Down Expand Up @@ -3589,12 +3590,6 @@ public function process_eol_page($outoftime) {
} else {
$data->displayscorewithoutessays = $a;
}
if ($this->properties->grade != GRADE_TYPE_NONE) {
$a = new stdClass;
$a->grade = format_float($gradeinfo->grade * $this->properties->grade / 100, 1);
$a->total = $this->properties->grade;
$data->yourcurrentgradeisoutof = $a;
}

$grade = new stdClass();
$grade->lessonid = $this->properties->id;
Expand All @@ -3612,6 +3607,25 @@ public function process_eol_page($outoftime) {
} else {
$newgradeid = $DB->insert_record("lesson_grades", $grade);
}

// Update central gradebook.
lesson_update_grades($this, $USER->id);

// Print grade (grade type Point).
if ($this->properties->grade > 0) {
$a = new stdClass;
$a->grade = format_float($gradeinfo->grade * $this->properties->grade / 100, 1);
$a->total = $this->properties->grade;
$data->yourcurrentgradeisoutof = $a;
}

// Print grade (grade type Scale).
if ($this->properties->grade < 0) {
// Grade type is Scale.
$grades = grade_get_grades($course->id, 'mod', 'lesson', $cm->instance, $USER->id);
$grade = reset($grades->items[0]->grades);
$data->yourcurrentgradeis = $grade->str_grade;
}
} else {
if ($this->properties->timelimit) {
if ($outoftime == 'normal') {
Expand All @@ -3622,14 +3636,15 @@ public function process_eol_page($outoftime) {
$grade->completed = time();
$newgradeid = $DB->insert_record("lesson_grades", $grade);
$data->eolstudentoutoftimenoanswers = true;

// Update central gradebook.
lesson_update_grades($this, $USER->id);
}
} else {
$data->welldone = true;
}
}

// Update central gradebook.
lesson_update_grades($this, $USER->id);
$data->progresscompleted = $progresscompleted;
}
} else {
Expand Down
3 changes: 3 additions & 0 deletions mod/lesson/renderer.php
Expand Up @@ -605,6 +605,9 @@ public function display_eol_page(lesson $lesson, $data) {
if ($data->yourcurrentgradeisoutof !== false) {
$output .= $this->paragraph(get_string("yourcurrentgradeisoutof", "lesson", $data->yourcurrentgradeisoutof), 'center');
}
if ($data->yourcurrentgradeis !== false) {
$output .= $this->paragraph(get_string("yourcurrentgradeis", "lesson", $data->yourcurrentgradeis), 'center');
}
if ($data->eolstudentoutoftimenoanswers !== false) {
$output .= $this->paragraph(get_string("eolstudentoutoftimenoanswers", "lesson"));
}
Expand Down
24 changes: 24 additions & 0 deletions mod/lesson/tests/behat/lesson_informations_at_end.feature
Expand Up @@ -7,6 +7,9 @@ Feature: In a lesson activity, if custom scoring is not enabled, student should
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "scales" exist:
| name | scale |
| Test Scale | Disappointing, Good, Excellent |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
Expand Down Expand Up @@ -44,6 +47,14 @@ Feature: In a lesson activity, if custom scoring is not enabled, student should
| id_response_editor_1 | Incorrect answer |
| id_jumpto_1 | This page |
And I press "Save page"
And I am on "Course 1" course homepage with editing mode on
And I duplicate "Test lesson name" activity
And I wait until section "1" is available
And I am on the "Test lesson name (copy)" "lesson activity editing" page
And I set the field "Name" to "Test lesson name 2"
And I set the field "grade[modgrade_type]" to "Scale"
And I set the field "Scale" to "Test Scale"
And I press "Save and return to course"
And I log out
And I log in as "student1"

Expand Down Expand Up @@ -83,3 +94,16 @@ Feature: In a lesson activity, if custom scoring is not enabled, student should
And I should see "Number of correct answers: 0"
And I should see "Your score is 0 (out of 1)."
And I should see "Your current grade is 0#0 out of 75"

Scenario: Current grade is displayed at end of lesson when grade type is set to scale
Given I am on "Course 1" course homepage
And I follow "Test lesson name 2"
When I press "Next page"
And I should see "1 + 1?"
And I set the following fields to these values:
| Your answer | 2 |
And I press "Submit"
And I press "Continue"
Then I should see "Congratulations - end of lesson reached"
And I should see "Your score is 1 (out of 1)."
And I should see "Your current grade is Excellent"

0 comments on commit a01201e

Please sign in to comment.