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