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