Skip to content

Commit

Permalink
Matrix: Feedback column doesn't need to show #744929
Browse files Browse the repository at this point in the history
if there isn't any feedback
  • Loading branch information
mkassaei committed Feb 7, 2024
1 parent 916f198 commit 979e61c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
14 changes: 14 additions & 0 deletions question.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ public function update_attempt_state_data_for_new_version(

return $startdata;
}

/**
* Check whether question has any specific feedback.
*
* @return bool
*/
public function has_specific_feedback(): bool {
foreach ($this->rows as $row) {
if (trim($row->feedback) !== '') {
return true;
}
}
return false;
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ public function matrix_table(question_attempt $qa, question_display_options $opt
['scope' => 'col', 'class' => 'align-middle text-center']);
$index += 1;
}
// Add feedback header.
if ($options->feedback) {
// Add feedback header only when specific feedback is set to be displayed and provided at least for one row.
if ($options->feedback && $question->has_specific_feedback()) {
$table .= html_writer::tag('th', html_writer::span(get_string('feedback', 'question'),
'answer_col', ['id' => 'col' . $index]), ['scope' => 'col', 'class' => 'rowfeedback align-middle']);
}
Expand Down Expand Up @@ -212,7 +212,7 @@ public function matrix_table(question_attempt $qa, question_display_options $opt

$table .= html_writer::tag('td', $answered, ['class' => "$class matrixanswer align-middle text-center"]);
}
if ($options->feedback) {
if ($options->feedback && $question->has_specific_feedback()) {
$table .= html_writer::tag('td', $feedback);
}
$table .= html_writer::end_tag('tr');
Expand Down
23 changes: 23 additions & 0 deletions tests/question_single_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,27 @@ public function test_update_attempt_state_date_from_old_version_ok(): void {
$this->assertEquals(['_roworder' => '22,23,21,24'],
$newq->update_attempt_state_data_for_new_version($oldstep, $q));
}

public function test_has_specific_feedback(): void {
$q = \test_question_maker::make_question('oumatrix', 'animals_single');

// This question has speific feedback for all 4 rows.
$this->assertTrue($q->has_specific_feedback());

// First row does not have feedback text.
$q->rows[11]->feedback = '';
$this->assertTrue($q->has_specific_feedback());

// First and second rows do not have feedback text.
$q->rows[12]->feedback = '';
$this->assertTrue($q->has_specific_feedback());

// First, second and third rows do not have feedback text.
$q->rows[13]->feedback = '';
$this->assertTrue($q->has_specific_feedback());

// All rows do not have feedback text.
$q->rows[14]->feedback = '';
$this->assertFalse($q->has_specific_feedback());
}
}

0 comments on commit 979e61c

Please sign in to comment.