diff --git a/mod/quiz/attemptlib.php b/mod/quiz/attemptlib.php index 91a60482da2..5d7f3cf321a 100644 --- a/mod/quiz/attemptlib.php +++ b/mod/quiz/attemptlib.php @@ -2756,8 +2756,12 @@ abstract class quiz_nav_panel_base { public function get_question_buttons() { $buttons = array(); foreach ($this->attemptobj->get_slots() as $slot) { - if ($heading = $this->attemptobj->get_heading_before_slot($slot)) { - $buttons[] = new quiz_nav_section_heading(format_string($heading)); + $heading = $this->attemptobj->get_heading_before_slot($slot); + if (!is_null($heading)) { + $sections = $this->attemptobj->get_quizobj()->get_sections(); + if (!(empty($heading) && count($sections) == 1)) { + $buttons[] = new quiz_nav_section_heading(format_string($heading)); + } } $qa = $this->attemptobj->get_question_attempt($slot); diff --git a/mod/quiz/lang/en/quiz.php b/mod/quiz/lang/en/quiz.php index 67ed5bdd377..029feb1f637 100644 --- a/mod/quiz/lang/en/quiz.php +++ b/mod/quiz/lang/en/quiz.php @@ -892,6 +892,7 @@ $string['scores'] = 'Scores'; $string['search:activity'] = 'Quiz - activity information'; $string['sectionheadingedit'] = 'Edit heading \'{$a}\''; $string['sectionheadingremove'] = 'Remove heading \'{$a}\''; +$string['sectionnoname'] = '(Untitled section)'; $string['seequestions'] = '(See questions)'; $string['select'] = 'Select'; $string['selectall'] = 'Select all'; diff --git a/mod/quiz/renderer.php b/mod/quiz/renderer.php index 2dadeb2fad7..e212893585b 100644 --- a/mod/quiz/renderer.php +++ b/mod/quiz/renderer.php @@ -395,7 +395,14 @@ class mod_quiz_renderer extends plugin_renderer_base { * @return string HTML fragment. */ protected function render_quiz_nav_section_heading(quiz_nav_section_heading $heading) { - return $this->heading($heading->heading, 3, 'mod_quiz-section-heading'); + if (empty($heading->heading)) { + $headingtext = get_string('sectionnoname', 'quiz'); + $class = ' dimmed_text'; + } else { + $headingtext = $heading->heading; + $class = ''; + } + return $this->heading($headingtext, 3, 'mod_quiz-section-heading' . $class); } /** @@ -671,7 +678,16 @@ class mod_quiz_renderer extends plugin_renderer_base { // Add a section headings if we need one here. $heading = $attemptobj->get_heading_before_slot($slot); if ($heading) { - $cell = new html_table_cell(format_string($heading)); + $heading = format_string($heading); + } + $sections = $attemptobj->get_quizobj()->get_sections(); + if (!is_null($heading) && empty($heading) && count($sections) > 1) { + $heading = get_string('sectionnoname', 'quiz'); + $heading = \html_writer::span($heading, 'dimmed_text'); + } + + if ($heading) { + $cell = new html_table_cell($heading); $cell->header = true; $cell->colspan = $tablewidth; $table->data[] = array($cell); diff --git a/mod/quiz/tests/behat/attempt_basic.feature b/mod/quiz/tests/behat/attempt_basic.feature index 70dde156e0f..8c529b43bb8 100644 --- a/mod/quiz/tests/behat/attempt_basic.feature +++ b/mod/quiz/tests/behat/attempt_basic.feature @@ -79,7 +79,7 @@ Feature: Attempt a quiz And I should see question "1" in section "Section 1" in the quiz navigation And I should see question "2" in section "Section 1" in the quiz navigation And I should see question "3" in section "Section 2" in the quiz navigation - And I should see question "4" in section "Section 2" in the quiz navigation + And I should see question "4" in section "(Untitled section)" in the quiz navigation And I should see question "5" in section "Section 3" in the quiz navigation And I should see question "6" in section "Section 3" in the quiz navigation @@ -87,11 +87,12 @@ Feature: Attempt a quiz And I should see question "1" in section "Section 1" in the quiz navigation And I should see question "2" in section "Section 1" in the quiz navigation And I should see question "3" in section "Section 2" in the quiz navigation - And I should see question "4" in section "Section 2" in the quiz navigation + And I should see question "4" in section "(Untitled section)" in the quiz navigation And I should see question "5" in section "Section 3" in the quiz navigation And I should see question "6" in section "Section 3" in the quiz navigation And I should see "Section 1" in the "quizsummaryofattempt" "table" And I should see "Section 2" in the "quizsummaryofattempt" "table" + And I should see "(Untitled section)" in the "quizsummaryofattempt" "table" And I should see "Section 3" in the "quizsummaryofattempt" "table" And I press "Submit all and finish" @@ -99,7 +100,7 @@ Feature: Attempt a quiz And I should see question "1" in section "Section 1" in the quiz navigation And I should see question "2" in section "Section 1" in the quiz navigation And I should see question "3" in section "Section 2" in the quiz navigation - And I should see question "4" in section "Section 2" in the quiz navigation + And I should see question "4" in section "(Untitled section)" in the quiz navigation And I should see question "5" in section "Section 3" in the quiz navigation And I should see question "6" in section "Section 3" in the quiz navigation