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 * Defines the editing form for the 'missingtype' question type. 19 * 20 * @package qtype 21 * @subpackage missingtype 22 * @copyright 2007 Jamie Pratt 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 30 /** 31 * This question renderer class is used when the actual question type of this 32 * question cannot be found. 33 * 34 * @copyright 2007 Jamie Pratt 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class qtype_missingtype_edit_form extends question_edit_form { 38 public function __construct($submiturl, $question, $category, $contexts, $formeditable = true) { 39 parent::__construct($submiturl, $question, $category, $contexts, false); 40 } 41 42 /** 43 * Add question-type specific form fields. 44 * 45 * @param object $mform the form being built. 46 */ 47 protected function definition_inner($mform) { 48 $this->add_per_answer_fields($mform, get_string('answerno', 'qtype_missingtype', '{no}'), 49 question_bank::fraction_options_full()); 50 } 51 52 public function set_data($question) { 53 if (isset($question->options) && is_array($question->options->answers)) { 54 $answers = $question->options->answers; 55 $default_values = array(); 56 $key = 0; 57 foreach ($answers as $answer) { 58 $default_values['answer['.$key.']'] = $answer->answer; 59 $default_values['fraction['.$key.']'] = $answer->fraction; 60 $default_values['feedback['.$key.']'] = $answer->feedback; 61 $key++; 62 } 63 $question = (object)((array)$question + $default_values); 64 } 65 parent::set_data($question); 66 } 67 68 public function qtype() { 69 return 'missingtype'; 70 } 71 72 public function validation($data, $files) { 73 $errors = parent::validation($data, $files); 74 $errors['name'] = get_string('cannotchangeamissingqtype', 'qtype_missingtype'); 75 return $errors; 76 } 77 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body