Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix: Feedback column doesn't need to show #744929 #5

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
Loading