Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Select from drop down list question renderer class. 19 * 20 * @package qtype_gapselect 21 * @copyright 2011 The Open University 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 require_once($CFG->dirroot . '/question/type/gapselect/rendererbase.php'); 29 30 31 /** 32 * Generates the output for select missing words questions. 33 * 34 * @copyright 2011 The Open University 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class qtype_gapselect_renderer extends qtype_elements_embedded_in_question_text_renderer { 38 protected function embedded_element(question_attempt $qa, $place, 39 question_display_options $options) { 40 $question = $qa->get_question(); 41 $group = $question->places[$place]; 42 43 $fieldname = $question->field($place); 44 45 $value = $qa->get_last_qt_var($question->field($place)); 46 47 $attributes = array( 48 'id' => $this->box_id($qa, 'p' . $place), 49 'class' => 'custom-select place' . $place, 50 ); 51 $groupclass = 'group' . $group; 52 53 if ($options->readonly) { 54 $attributes['disabled'] = 'disabled'; 55 } 56 57 $orderedchoices = $question->get_ordered_choices($group); 58 $selectoptions = array(); 59 foreach ($orderedchoices as $orderedchoicevalue => $orderedchoice) { 60 $selectoptions[$orderedchoicevalue] = format_string($orderedchoice->text); 61 } 62 63 $feedbackimage = ''; 64 if ($options->correctness) { 65 $response = $qa->get_last_qt_data(); 66 if (array_key_exists($fieldname, $response)) { 67 $fraction = (int) ($response[$fieldname] == 68 $question->get_right_choice_for($place)); 69 $attributes['class'] .= ' ' . $this->feedback_class($fraction); 70 $feedbackimage = $this->feedback_image($fraction); 71 } 72 } 73 74 // Use non-breaking space instead of 'Choose...'. 75 $selecthtml = html_writer::select($selectoptions, $qa->get_qt_field_name($fieldname), 76 $value, ' ', $attributes) . ' ' . $feedbackimage; 77 return html_writer::tag('span', $selecthtml, array('class' => 'control '.$groupclass)); 78 } 79 80 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body