. /** * Matching question renderer class. * * @package qtype_match * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); /** * Generates the output for matching questions. * * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class qtype_match_renderer extends qtype_with_combined_feedback_renderer { public function formulation_and_controls(question_attempt $qa, question_display_options $options) { $question = $qa->get_question(); $stemorder = $question->get_stem_order(); $response = $qa->get_last_qt_data(); $choices = $this->format_choices($question); $result = ''; $result .= html_writer::tag('div', $question->format_questiontext($qa), array('class' => 'qtext')); $result .= html_writer::start_tag('div', array('class' => 'ablock')); $result .= html_writer::start_tag('table', array('class' => 'answer')); $result .= html_writer::start_tag('tbody'); $parity = 0; $i = 1; foreach ($stemorder as $key => $stemid) { $result .= html_writer::start_tag('tr', array('class' => 'r' . $parity)); $fieldname = 'sub' . $key; $result .= html_writer::tag('td', $this->format_stem_text($qa, $stemid), array('class' => 'text')); $classes = 'control'; $feedbackimage = ''; if (array_key_exists($fieldname, $response)) { $selected = $response[$fieldname]; } else { $selected = 0; } $fraction = (int) ($selected && $selected == $question->get_right_choice_for($stemid)); if ($options->correctness && $selected) { $classes .= ' ' . $this->feedback_class($fraction); $feedbackimage = $this->feedback_image($fraction); } $result .= html_writer::tag('td', html_writer::label(get_string('answer', 'qtype_match', $i), '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)) . ' ' . $feedbackimage, array('class' => $classes)); $result .= html_writer::end_tag('tr'); $parity = 1 - $parity; $i++; } $result .= html_writer::end_tag('tbody'); $result .= html_writer::end_tag('table'); $result .= html_writer::end_tag('div'); // Closes