diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 56c0a07da29..c64508a39da 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -3504,6 +3504,7 @@ class lesson extends lesson_base { 'displayscorewithessays' => false, 'displayscorewithoutessays' => false, 'yourcurrentgradeisoutof' => false, + 'yourcurrentgradeis' => false, 'eolstudentoutoftimenoanswers' => false, 'welldone' => false, 'progressbar' => false, @@ -3594,12 +3595,6 @@ class lesson extends lesson_base { } 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; @@ -3617,6 +3612,25 @@ class lesson extends lesson_base { } 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') { @@ -3627,14 +3641,15 @@ class lesson extends lesson_base { $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 { diff --git a/mod/lesson/renderer.php b/mod/lesson/renderer.php index 9a2b30be4de..09d29fc42cb 100644 --- a/mod/lesson/renderer.php +++ b/mod/lesson/renderer.php @@ -595,6 +595,9 @@ class mod_lesson_renderer extends plugin_renderer_base { 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")); } diff --git a/mod/lesson/tests/behat/lesson_informations_at_end.feature b/mod/lesson/tests/behat/lesson_informations_at_end.feature index abc5e7effd8..5856e5fd22b 100644 --- a/mod/lesson/tests/behat/lesson_informations_at_end.feature +++ b/mod/lesson/tests/behat/lesson_informations_at_end.feature @@ -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 | @@ -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" @@ -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"