From f06a670a6429b4a4acedc1c2faf92c5a8d20c2dd Mon Sep 17 00:00:00 2001 From: Hieu Nguyen Dang Date: Wed, 3 Jul 2024 13:47:27 +0700 Subject: [PATCH] MDL-82100 Quiz\report: Show customised question numbers --- mod/quiz/report/grading/report.php | 2 +- mod/quiz/report/grading/tests/behat/grading.feature | 5 +++-- mod/quiz/report/overview/report.php | 2 +- mod/quiz/report/overview/tests/behat/basic.feature | 10 +++++----- mod/quiz/report/reportlib.php | 1 + mod/quiz/report/responses/report.php | 6 +++--- mod/quiz/report/responses/tests/behat/basic.feature | 11 ++++++----- mod/quiz/report/statistics/report.php | 4 +++- mod/quiz/report/statistics/tests/behat/basic.feature | 11 +++++++---- 9 files changed, 30 insertions(+), 22 deletions(-) diff --git a/mod/quiz/report/grading/report.php b/mod/quiz/report/grading/report.php index c4828be382d..24b92619f22 100644 --- a/mod/quiz/report/grading/report.php +++ b/mod/quiz/report/grading/report.php @@ -383,7 +383,7 @@ class quiz_grading_report extends report_base { $row = []; - $row[] = $this->questions[$counts->slot]->number; + $row[] = $this->questions[$counts->slot]->displaynumber; $row[] = $PAGE->get_renderer('question', 'bank')->qtype_icon($this->questions[$counts->slot]->qtype); diff --git a/mod/quiz/report/grading/tests/behat/grading.feature b/mod/quiz/report/grading/tests/behat/grading.feature index 8ef6f2c3646..e72bc9f1bb1 100644 --- a/mod/quiz/report/grading/tests/behat/grading.feature +++ b/mod/quiz/report/grading/tests/behat/grading.feature @@ -55,8 +55,8 @@ Feature: Basic use of the Manual grading report | quiz | Quiz 1 | C1 | quiz1 | 1 | tging | | quiz | Quiz 2 | C1 | quiz2 | 1 | tging | And quiz "Quiz 1" contains the following questions: - | question | page | - | Short answer 001 | 1 | + | question | page | displaynumber | + | Short answer 001 | 1 | 1a | Scenario: Manual grading report without attempts When I am on the "Quiz 1" "mod_quiz > Manual grading report" page logged in as "teacher1" @@ -98,6 +98,7 @@ Feature: Basic use of the Manual grading report And I set the field "Mark" to "0.6" And I press "Save and show next" And I should see "All selected attempts have been graded. Returning to the list of questions." + And "Short answer 001" row "Q #" column of "questionstograde" table should contain "1a" And "Short answer 001" row "To grade" column of "questionstograde" table should contain "0" And "Short answer 001" row "Already graded" column of "questionstograde" table should contain "1" diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index 358395d378f..fb944f54805 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -149,7 +149,7 @@ class quiz_overview_report extends attempts_report { if ($options->slotmarks) { foreach ($questions as $slot => $question) { $columns[] = 'qsgrade' . $slot; - $header = get_string('qbrief', 'quiz', $question->number); + $header = get_string('qbrief', 'quiz', $question->displaynumber); if (!$table->is_downloading()) { $header .= '
'; } else { diff --git a/mod/quiz/report/overview/tests/behat/basic.feature b/mod/quiz/report/overview/tests/behat/basic.feature index 205537cd543..868eb5d4615 100644 --- a/mod/quiz/report/overview/tests/behat/basic.feature +++ b/mod/quiz/report/overview/tests/behat/basic.feature @@ -46,10 +46,10 @@ Feature: Basic use of the Grades report | Test questions | truefalse | TF1 | First question | | Test questions | truefalse | TF2 | Second question | And quiz "Quiz 1" contains the following questions: - | question | page | maxmark | - | Intro | 1 | | - | TF1 | 1 | | - | TF2 | 1 | 3.0 | + | question | page | maxmark | displaynumber | + | Intro | 1 | | | + | TF1 | 1 | | | + | TF2 | 1 | 3.0 | 2a | And user "student1" has attempted "Quiz 1" with responses: | slot | response | | 2 | True | @@ -68,7 +68,7 @@ Feature: Basic use of the Grades report # Verify that the right columns are visible And I should see "Q. 1" - And I should see "Q. 2" + And I should see "Q. 2a" And I should not see "Q. 3" # Check student1's grade diff --git a/mod/quiz/report/reportlib.php b/mod/quiz/report/reportlib.php index 9919d8c7c4c..21f4a47150c 100644 --- a/mod/quiz/report/reportlib.php +++ b/mod/quiz/report/reportlib.php @@ -113,6 +113,7 @@ function quiz_report_get_significant_questions($quiz) { $slotreport->qtype = $slot->qtype; $slotreport->length = $slot->length; $slotreport->number = $number; + $slotreport->displaynumber = $slot->displaynumber ?? $number; $number += $slot->length; $slotreport->maxmark = $slot->maxmark; $slotreport->category = $slot->category; diff --git a/mod/quiz/report/responses/report.php b/mod/quiz/report/responses/report.php index b77a86e5c83..88291234cd2 100644 --- a/mod/quiz/report/responses/report.php +++ b/mod/quiz/report/responses/report.php @@ -158,15 +158,15 @@ class quiz_responses_report extends attempts_report { foreach ($questions as $id => $question) { if ($options->showqtext) { $columns[] = 'question' . $id; - $headers[] = get_string('questionx', 'question', $question->number); + $headers[] = get_string('questionx', 'question', $question->displaynumber); } if ($options->showresponses) { $columns[] = 'response' . $id; - $headers[] = get_string('responsex', 'quiz_responses', $question->number); + $headers[] = get_string('responsex', 'quiz_responses', $question->displaynumber); } if ($options->showright) { $columns[] = 'right' . $id; - $headers[] = get_string('rightanswerx', 'quiz_responses', $question->number); + $headers[] = get_string('rightanswerx', 'quiz_responses', $question->displaynumber); } } diff --git a/mod/quiz/report/responses/tests/behat/basic.feature b/mod/quiz/report/responses/tests/behat/basic.feature index 7070b04f484..c9524946158 100644 --- a/mod/quiz/report/responses/tests/behat/basic.feature +++ b/mod/quiz/report/responses/tests/behat/basic.feature @@ -28,8 +28,8 @@ Feature: Basic use of the Responses report | questioncategory | qtype | name | template | | Test questions | numerical | NQ | pi3tries | And quiz "Quiz 1" contains the following questions: - | question | page | maxmark | - | NQ | 1 | 3.0 | + | question | page | maxmark | displaynumber | + | NQ | 1 | 3.0 | 1a | @javascript Scenario: Report works when there are no attempts @@ -58,13 +58,14 @@ Feature: Basic use of the Responses report And I should not see "Student Two" And I set the field "Attempts from" to "enrolled users who have, or have not, attempted the quiz" And I set the field "Which tries" to "All tries" + And I should see "Response 1a" And I press "Show report" - And "Student OneReview attempt" row "Response 1Sort by Response 1 Ascending" column of "responses" table should contain "1.0" + And "Student OneReview attempt" row "Response 1aSort by Response 1a Ascending" column of "responses" table should contain "1.0" And "Student OneReview attempt" row "Status" column of "responses" table should contain "" And "Finished" row "Grade/100.00Sort by Grade/100.00 Ascending" column of "responses" table should contain "33.33" - And "Finished" row "Response 1Sort by Response 1 Ascending" column of "responses" table should contain "3.14" + And "Finished" row "Response 1aSort by Response 1a Ascending" column of "responses" table should contain "3.14" And "Student Two" row "Status" column of "responses" table should contain "-" - And "Student Two" row "Response 1Sort by Response 1 Ascending" column of "responses" table should contain "-" + And "Student Two" row "Response 1aSort by Response 1a Ascending" column of "responses" table should contain "-" @javascript Scenario: Report does not allow strange combinations of options diff --git a/mod/quiz/report/statistics/report.php b/mod/quiz/report/statistics/report.php index c6151a727ed..1a7928b1b59 100644 --- a/mod/quiz/report/statistics/report.php +++ b/mod/quiz/report/statistics/report.php @@ -890,11 +890,13 @@ class quiz_statistics_report extends report_base { $questions = quiz_report_get_significant_questions($quiz); $questiondata = []; foreach ($questions as $qs => $question) { + $displaynumber = $question->displaynumber; if ($question->qtype === 'random') { $question->id = 0; $question->name = get_string('random', 'quiz'); $question->questiontext = get_string('random', 'quiz'); $question->parenttype = 'random'; + $question->number = $displaynumber; $questiondata[$question->slot] = $question; } else if ($question->qtype === 'missingtype') { $question->id = is_numeric($question->id) ? (int) $question->id : 0; @@ -905,7 +907,7 @@ class quiz_statistics_report extends report_base { $q = question_bank::load_question_data($question->id); $q->maxmark = $question->maxmark; $q->slot = $question->slot; - $q->number = $question->number; + $q->number = $displaynumber; $q->parenttype = null; $questiondata[$question->slot] = $q; } diff --git a/mod/quiz/report/statistics/tests/behat/basic.feature b/mod/quiz/report/statistics/tests/behat/basic.feature index 3228635443a..514452bee55 100644 --- a/mod/quiz/report/statistics/tests/behat/basic.feature +++ b/mod/quiz/report/statistics/tests/behat/basic.feature @@ -32,10 +32,10 @@ Feature: Basic use of the Statistics report | activity | name | course | idnumber | | quiz | Quiz 1 | C1 | quiz1 | And quiz "Quiz 1" contains the following questions: - | question | page | - | Question A | 1 | - | Question B | 1 | - | Question C | 2 | + | question | page | displaynumber | + | Question A | 1 | | + | Question B | 1 | | + | Question C | 2 | 3c | @javascript Scenario: Report works when there are no attempts @@ -64,6 +64,7 @@ Feature: Basic use of the Statistics report And "Show chart data" "link" should exist # Question A statistics breakdown. + And "1" row "Q#" column of "questionstatistics" table should contain "1" And "1" row "Question name" column of "questionstatistics" table should contain "Question A" And "1" row "Attempts" column of "questionstatistics" table should contain "3" And "1" row "Facility index" column of "questionstatistics" table should contain "66.67%" @@ -74,6 +75,7 @@ Feature: Basic use of the Statistics report And "1" row "Discrimination index" column of "questionstatistics" table should contain "50.00%" # Question B statistics breakdown. + And "2" row "Q#" column of "questionstatistics" table should contain "2" And "2" row "Question name" column of "questionstatistics" table should contain "Question B" And "2" row "Attempts" column of "questionstatistics" table should contain "3" And "2" row "Facility index" column of "questionstatistics" table should contain "33.33%" @@ -84,6 +86,7 @@ Feature: Basic use of the Statistics report And "2" row "Discrimination index" column of "questionstatistics" table should contain "86.60%" # Question C statistics breakdown. + And "3" row "Q#" column of "questionstatistics" table should contain "3c" And "3" row "Question name" column of "questionstatistics" table should contain "Question C" And "3" row "Attempts" column of "questionstatistics" table should contain "3" And "3" row "Facility index" column of "questionstatistics" table should contain "33.33%"