Skip to content

Commit

Permalink
MDL-83654 qtype_match: Code style improvements for the renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Jan 31, 2025
1 parent 01f55a4 commit 3add420
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions question/type/match/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,25 @@ public function formulation_and_controls(question_attempt $qa,
$choices = $this->format_choices($question);

$questiontextid = $qa->get_qt_field_name('qtext');
$result = '';
$result .= html_writer::tag('div', $question->format_questiontext($qa),
array('class' => 'qtext', 'id' => $questiontextid));
$result = html_writer::div($question->format_questiontext($qa), 'qtext', ['id' => $questiontextid]);

$result .= html_writer::start_tag('div', array('class' => 'ablock'));
$result .= html_writer::start_tag('table', array('class' => 'answer', 'role' => 'presentation'));
$result .= html_writer::start_tag('div', ['class' => 'ablock']);
$result .= html_writer::start_tag('table', ['class' => 'answer', 'role' => 'presentation']);
$result .= html_writer::start_tag('tbody', ['role' => 'presentation']);

$parity = 0;
$i = 1;
foreach ($stemorder as $key => $stemid) {

$result .= html_writer::start_tag('tr', array('class' => 'r' . $parity, 'role' => 'presentation'));
$result .= html_writer::start_tag('tr', ['class' => 'r' . $parity, 'role' => 'presentation']);
$fieldname = 'sub' . $key;

$itemtextid = $qa->get_qt_field_name($fieldname . '_itemtext');
$result .= html_writer::tag('td', $this->format_stem_text($qa, $stemid),
array('class' => 'text', 'id' => $itemtextid, 'role' => 'presentation'));
$result .= html_writer::tag('td', $this->format_stem_text($qa, $stemid), [
'class' => 'text',
'id' => $itemtextid,
'role' => 'presentation',
]);

$classes = 'control';
$feedbackimage = '';
Expand All @@ -80,13 +81,22 @@ public function formulation_and_controls(question_attempt $qa,
}

$labeltext = $options->add_question_identifier_to_label(get_string('answer', 'qtype_match', $i));
$result .= html_writer::tag('td',
html_writer::label($labeltext,
'menu' . $qa->get_qt_field_name('sub' . $key), false,
array('class' => 'accesshide')) .
html_writer::select($choices, $qa->get_qt_field_name('sub' . $key), $selected,
array('0' => 'choose'), array('disabled' => $options->readonly, 'class' => 'custom-select ms-1', 'aria-describedby' => "$questiontextid $itemtextid")) .
' ' . $feedbackimage, array('class' => $classes, 'role' => 'presentation'));
$selectlabel = html_writer::label($labeltext, 'menu' . $qa->get_qt_field_name($fieldname), false, ['class' => 'accesshide']);
$select = html_writer::select(
$choices,
$qa->get_qt_field_name($fieldname),
$selected,
['0' => 'choose'],
[
'disabled' => $options->readonly,
'class' => 'custom-select ms-1',
'aria-describedby' => "$questiontextid $itemtextid"
]
);
$result .= html_writer::tag('td', $selectlabel . $select . ' ' . $feedbackimage, [
'class' => $classes,
'role' => 'presentation',
]);

$result .= html_writer::end_tag('tr');
$parity = 1 - $parity;
Expand Down

0 comments on commit 3add420

Please sign in to comment.