Skip to content

Commit

Permalink
Merge branch 'MDL-77229-master' of https://github.com/ilyatregubov/mo…
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyatregubov committed Apr 21, 2023
2 parents ba81947 + 1601a26 commit ad401db
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
14 changes: 10 additions & 4 deletions mod/lesson/pagetypes/numerical.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,12 @@ public function report_answers($answerpage, $answerdata, $useranswer, $pagestats
$total = $stats["total"];
unset($stats["total"]);
foreach ($stats as $valentered => $ntimes) {
$valformatted = '';
if (!is_null($valentered) && trim($valentered) !== '') { // Empty response, 0 could be ok.
$valformatted = s(format_float($valentered, strlen($valentered), true, true));
}
$data = '<input class="form-control" type="text" size="50" ' .
'disabled="disabled" readonly="readonly" value="'.
s(format_float($valentered, strlen($valentered), true, true)).'" />';
'disabled="disabled" readonly="readonly" value="'. $valformatted .'" />';
$percent = $ntimes / $total * 100;
$percent = round($percent, 2);
$percent .= "% ".get_string("enteredthis", "lesson");
Expand All @@ -270,9 +273,12 @@ public function report_answers($answerpage, $answerdata, $useranswer, $pagestats
} else if ($useranswer != null && ($answer->id == $useranswer->answerid || ($answer == end($answers) &&
empty($answerdata->answers)))) {
// Get in here when the user answered or for the last answer.
$valformatted = '';
if (!is_null($useranswer->useranswer) && trim($useranswer->useranswer) !== '') { // Empty response, 0 could be ok.
$valformatted = s(format_float($useranswer->useranswer, strlen($useranswer->useranswer), true, true));
}
$data = '<input class="form-control" type="text" size="50" ' .
'disabled="disabled" readonly="readonly" value="'.
s(format_float($useranswer->useranswer, strlen($useranswer->useranswer), true, true)).'">';
'disabled="disabled" readonly="readonly" value="' . $valformatted .'">';
if (isset($pagestats[$this->properties->id][$useranswer->useranswer])) {
$percent = $pagestats[$this->properties->id][$useranswer->useranswer] / $pagestats[$this->properties->id]["total"] * 100;
$percent = round($percent, 2);
Expand Down
23 changes: 23 additions & 0 deletions mod/lesson/tests/behat/lesson_report.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ Feature: In a lesson activity, teachers can review student attempts
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
| student2 | Student | 2 | student2@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
| student2 | C1 | student |
And the following "activities" exist:
| activity | name | course | idnumber | retake |
| lesson | Test lesson name | C1 | lesson1 | 1 |
Expand Down Expand Up @@ -149,3 +151,24 @@ Feature: In a lesson activity, teachers can review student attempts
And I should not see "High score"
And I should not see "Average score"
And I should not see "Low score"

Scenario: View detailed statistics in a lesson when empty string is given as answer
Given I follow "Add a question page"
And I set the field "Select a question type" to "Numerical"
And I press "Add a question page"
And I set the following fields to these values:
| Page title | Numerical question |
| Page contents | What is 1 + 0.5? |
| id_answer_editor_0 | 1.5 |
| id_jumpto_0 | End of lesson |
And I press "Save page"
When I am on the "Test lesson name" "lesson activity" page logged in as student1
And I press "Submit"
And I log out
And I am on the "Test lesson name" "lesson activity" page logged in as student2
And I set the field "Your answer" to "1.5"
And I press "Submit"
And I am on the "Test lesson name" "lesson activity" page logged in as teacher1
And I navigate to "Reports" in current page administration
And I select "Detailed statistics" from the "jump" singleselect
Then I should see "50% entered this."

0 comments on commit ad401db

Please sign in to comment.