Skip to content

Commit

Permalink
MDL-71785 core_quiz: Empty quiz section name behaves like new page
Browse files Browse the repository at this point in the history
  • Loading branch information
levemar committed Sep 14, 2021
1 parent ab931f6 commit c943722
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
8 changes: 6 additions & 2 deletions mod/quiz/attemptlib.php
Expand Up @@ -2686,8 +2686,12 @@ public function __construct(quiz_attempt $attemptobj,
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);
Expand Down
1 change: 1 addition & 0 deletions mod/quiz/lang/en/quiz.php
Expand Up @@ -886,6 +886,7 @@
$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';
Expand Down
20 changes: 18 additions & 2 deletions mod/quiz/renderer.php
Expand Up @@ -395,7 +395,14 @@ protected function render_quiz_nav_question_button(quiz_nav_question_button $but
* @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);
}

/**
Expand Down Expand Up @@ -671,7 +678,16 @@ public function summary_table($attemptobj, $displayoptions) {
// 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);
Expand Down
7 changes: 4 additions & 3 deletions mod/quiz/tests/behat/attempt_basic.feature
Expand Up @@ -79,27 +79,28 @@ 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 follow "Finish attempt ..."
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"
And I click on "Submit all and finish" "button" in the "Confirmation" "dialogue"
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

Expand Down

0 comments on commit c943722

Please sign in to comment.