3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * Base class for rendering question types like this one.
22 * @subpackage gapselect
23 * @copyright 2011 The Open University
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') || die();
32 * Generates the output for question types where the question includes embedded interactive elements in the
35 * @copyright 2011 The Open University
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 abstract class qtype_elements_embedded_in_question_text_renderer extends qtype_with_combined_feedback_renderer {
39 public function formulation_and_controls(question_attempt $qa,
40 question_display_options $options) {
42 $question = $qa->get_question();
45 foreach ($question->textfragments as $i => $fragment) {
47 $questiontext .= $this->embedded_element($qa, $i, $options);
49 $questiontext .= $fragment;
53 $result .= html_writer::tag('div', $question->format_text($questiontext,
54 $question->questiontextformat, $qa, 'question', 'questiontext', $question->id),
55 array('class' => $this->qtext_classname(), 'id' => $qa->get_qt_field_name('')));
57 $result .= $this->post_qtext_elements($qa, $options);
59 if ($qa->get_state() == question_state::$invalid) {
60 $result .= html_writer::nonempty_tag('div',
61 $question->get_validation_error($qa->get_last_qt_data()),
62 array('class' => 'validationerror'));
68 protected function qtext_classname() {
72 protected abstract function embedded_element(question_attempt $qa, $place, question_display_options $options);
74 protected function post_qtext_elements(question_attempt $qa, question_display_options $options) {
78 protected function box_id(question_attempt $qa, $place, $group) {
79 return $qa->get_qt_field_name($place) . '_' . $group;
82 public function specific_feedback(question_attempt $qa) {
83 return $this->combined_feedback($qa);
86 public function correct_response(question_attempt $qa) {
87 $question = $qa->get_question();
90 foreach ($question->textfragments as $i => $fragment) {
92 $group = $question->places[$i];
93 $choice = $question->choices[$group][$question->rightchoices[$i]];
94 $correctanswer .= '[' . str_replace('-', '‑',
97 $correctanswer .= $fragment;
100 if (!empty($correctanswer)) {
101 return get_string('correctansweris', 'qtype_gapselect', $correctanswer);