From 3a72810347377b08020bf60ae08ad7b55a637004 Mon Sep 17 00:00:00 2001 From: hieuvu Date: Fri, 18 Apr 2025 14:27:32 +0700 Subject: [PATCH] MDL-85239 mod_quiz: Add caption for Attempt tables. --- .../output/attempt_summary_information.php | 16 ++++++++++++++++ mod/quiz/comment.php | 3 ++- mod/quiz/lang/en/quiz.php | 1 + mod/quiz/reviewquestion.php | 2 ++ .../attempt_summary_information.mustache | 6 +++++- .../tests/behat/attempt_redo_questions.feature | 1 + .../tests/behat/manually_mark_question.feature | 1 + mod/quiz/tests/behat/preview.feature | 2 ++ 8 files changed, 30 insertions(+), 2 deletions(-) diff --git a/mod/quiz/classes/output/attempt_summary_information.php b/mod/quiz/classes/output/attempt_summary_information.php index bea6737229f..7944d9f77c8 100644 --- a/mod/quiz/classes/output/attempt_summary_information.php +++ b/mod/quiz/classes/output/attempt_summary_information.php @@ -47,6 +47,9 @@ class attempt_summary_information implements renderable, named_templatable { /** @var array[] The rows of summary data. {@see add_item()} should make the structure clear. */ protected array $summarydata = []; + /** @var string The caption for attempt summary table. */ + protected string $caption = ''; + /** * Add an item to the summary. * @@ -61,6 +64,15 @@ class attempt_summary_information implements renderable, named_templatable { ]; } + /** + * Set the caption for the summary table. + * + * @param string $caption + */ + public function set_caption(string $caption): void { + $this->caption = $caption; + } + /** * Add an item to the summary just before the given item. * @@ -209,6 +221,9 @@ class attempt_summary_information implements renderable, named_templatable { } } + // Caption. + $summary->set_caption(get_string('summaryofattemptscaption', 'quiz', $attemptobj->get_attempt_number())); + // Attempt state. $summary->add_item('state', get_string('attemptstate', 'quiz'), quiz_attempt::state_name($attemptobj->get_attempt()->state)); @@ -321,6 +336,7 @@ class attempt_summary_information implements renderable, named_templatable { $templatecontext = [ 'hasitems' => !empty($this->summarydata), 'items' => [], + 'caption' => $this->caption, ]; foreach ($this->summarydata as $item) { if ($item['title'] instanceof renderable) { diff --git a/mod/quiz/comment.php b/mod/quiz/comment.php index 37ef4d9a62d..8c6e9872560 100644 --- a/mod/quiz/comment.php +++ b/mod/quiz/comment.php @@ -58,7 +58,8 @@ echo $output->header(); // Prepare summary information about this question attempt. $summary = new attempt_summary_information(); - +// Set the caption. +$summary->set_caption(get_string('summaryofattempt', 'quiz')); // Student name. $userpicture = new user_picture($student); $userpicture->courseid = $attemptobj->get_courseid(); diff --git a/mod/quiz/lang/en/quiz.php b/mod/quiz/lang/en/quiz.php index 0d4ec099135..a973e9633e6 100644 --- a/mod/quiz/lang/en/quiz.php +++ b/mod/quiz/lang/en/quiz.php @@ -1109,6 +1109,7 @@ $string['subplugintype_quizaccess_plural'] = 'Access rules'; $string['substitutedby'] = 'will be substituted by'; $string['summaryofattempt'] = 'Summary of attempt'; $string['summaryofattempts'] = 'Your attempts'; +$string['summaryofattemptscaption'] = 'Attempt {$a} summary'; $string['temporaryblocked'] = 'You are temporarily not allowed to re-attempt the quiz.
You will be able to take another attempt on:'; $string['theattempt'] = 'The attempt'; $string['theattempt_help'] = 'Whether the student can review the attempt at all.'; diff --git a/mod/quiz/reviewquestion.php b/mod/quiz/reviewquestion.php index 54f1519c7aa..d82a4703925 100644 --- a/mod/quiz/reviewquestion.php +++ b/mod/quiz/reviewquestion.php @@ -77,6 +77,8 @@ if ($attemptobj->is_own_attempt()) { // Prepare summary informat about this question attempt. $summary = new attempt_summary_information(); +// Set the caption. +$summary->set_caption(get_string('summaryofattempt', 'quiz')); // Student name. $userpicture = new user_picture($student); diff --git a/mod/quiz/templates/attempt_summary_information.mustache b/mod/quiz/templates/attempt_summary_information.mustache index 1f3a84157bf..de574ca2b97 100644 --- a/mod/quiz/templates/attempt_summary_information.mustache +++ b/mod/quiz/templates/attempt_summary_information.mustache @@ -29,11 +29,15 @@ {"title": "Completed", "content": "Thursday, 23 November 2023, 9:32 AM"}, {"title": "Duration", "content": "3 minutes"}, {"title": "Grade", "content": "Not yet graded"} - ] + ], + "caption": "Summary of attempt" } }} {{#hasitems}} + {{#caption}} + + {{/caption}} {{#items}} diff --git a/mod/quiz/tests/behat/attempt_redo_questions.feature b/mod/quiz/tests/behat/attempt_redo_questions.feature index ccc78260bef..3fa4fb48fc2 100644 --- a/mod/quiz/tests/behat/attempt_redo_questions.feature +++ b/mod/quiz/tests/behat/attempt_redo_questions.feature @@ -169,6 +169,7 @@ Feature: Allow students to redo questions in a practice quiz, without starting a And I follow "Review attempt" And I click on "1" "link" in the "First question" "question" And I switch to "reviewquestion" window + And "Summary of attempt" "table" should exist And the state of "First question" question is shown as "Incorrect" # Now switch to the other quiz attempt using the link at the top, which does not have a redo. And I click on "2" "link" in the "Attempts" "table_row" diff --git a/mod/quiz/tests/behat/manually_mark_question.feature b/mod/quiz/tests/behat/manually_mark_question.feature index 9bbfccf554d..d7ba2448d83 100644 --- a/mod/quiz/tests/behat/manually_mark_question.feature +++ b/mod/quiz/tests/behat/manually_mark_question.feature @@ -63,6 +63,7 @@ Feature: Teachers can override the grade for any question And I am on the "Quiz 1 > student1 > Attempt 1" "mod_quiz > Attempt review" page And I follow "Make comment or override mark" And I switch to "commentquestion" window + And "Summary of attempt" "table" should exist And I set the field "Comment" to "Administrator's comment" And I select the "p" element in position "0" of the "Comment" TinyMCE editor And I click on the "Image" button for the "Comment" TinyMCE editor diff --git a/mod/quiz/tests/behat/preview.feature b/mod/quiz/tests/behat/preview.feature index 5266f474802..b90403de83e 100644 --- a/mod/quiz/tests/behat/preview.feature +++ b/mod/quiz/tests/behat/preview.feature @@ -37,10 +37,12 @@ Feature: Preview a quiz as a teacher Scenario: Review the quiz attempt When I am on the "Quiz 1" "mod_quiz > View" page logged in as "teacher" And I follow "Review" + And "Attempt 1 summary" "table" should exist Then I should see "25.00 out of 100.00" And I should see "v1 (latest)" in the "Question 1" "question" And I follow "Finish review" And "Review" "link" in the "Attempt 1" "list_item" should be visible + And "Attempt 1 summary" "table" should exist @javascript Scenario: Review the quiz attempt with custom decimal separator
{{caption}}