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
29 * Generates the output for question types where the question includes embedded interactive elements in the
32 * @copyright 2011 The Open University
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 abstract class qtype_elements_embedded_in_question_text_renderer extends qtype_with_combined_feedback_renderer {
36 public function formulation_and_controls(question_attempt $qa,
37 question_display_options $options) {
39 $question = $qa->get_question();
42 foreach ($question->textfragments as $i => $fragment) {
44 $questiontext .= $this->embedded_element($qa, $i, $options);
46 $questiontext .= $fragment;
50 $result .= html_writer::tag('div', $question->format_text($questiontext,
51 $qa, 'question', 'questiontext', $question->id),
52 array('class' => $this->qtext_classname(), 'id' => $qa->get_qt_field_name('')));
54 $result .= $this->post_qtext_elements($qa, $options);
56 if ($qa->get_state() == question_state::$invalid) {
57 $result .= html_writer::nonempty_tag('div',
58 $question->get_validation_error($qa->get_last_qt_data()),
59 array('class' => 'validationerror'));
65 protected function qtext_classname() {
69 protected abstract function embedded_element(question_attempt $qa, $place, question_display_options $options);
71 protected function post_qtext_elements(question_attempt $qa, question_display_options $options) {
75 protected function box_id(question_attempt $qa, $place, $group) {
76 return $qa->get_qt_field_name($place) . '_' . $group;
79 public function specific_feedback(question_attempt $qa) {
80 return $this->combined_feedback($qa);
83 public function correct_response(question_attempt $qa) {
84 $question = $qa->get_question();
87 foreach ($question->textfragments as $i => $fragment) {
89 $group = $question->places[$i];
90 $choice = $question->choices[$group][$question->rightchoices[$i]];
91 $correctanswer .= '[' . str_replace('-', '‑',
94 $correctanswer .= $fragment;
97 if (!empty($correctanswer)) {
98 return get_string('correctansweris', 'qtype_gapselect', $correctanswer);