MDL-25122 Quiz review page does not check and enforce separate groups mode.
[moodle.git] / question / type / truefalse / edit_truefalse_form.php
CommitLineData
aeb15530 1<?php
fe6ce234
DC
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
2b7da645
TH
18/**
19 * Defines the editing form for the true-false question type.
20 *
21 * @package qtype_truefalse
22 * @copyright &copy; 2007 Jamie Pratt
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26
bfebaf64
MD
27if (!defined('MOODLE_INTERNAL')) {
28 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
29}
30
01ae934f 31require_once($CFG->dirroot.'/question/type/edit_question_form.php');
fe6ce234 32
2b7da645 33
36703ed7 34/**
2b7da645 35 * True-false question editing form definition.
36703ed7 36 *
37 * @copyright &copy; 2006 The Open University
2b7da645 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36703ed7 39 */
6e34cd29 40class qtype_truefalse_edit_form extends question_edit_form {
36703ed7 41 /**
42 * Add question-type specific form fields.
01ae934f 43 *
44 * @param object $mform the form being built.
36703ed7 45 */
2b7da645 46 protected function definition_inner($mform) {
36703ed7 47 $mform->addElement('select', 'correctanswer', get_string('correctanswer', 'qtype_truefalse'),
48 array(0 => get_string('false', 'qtype_truefalse'), 1 => get_string('true', 'qtype_truefalse')));
01ae934f 49
fe6ce234 50 $mform->addElement('editor', 'feedbacktrue', get_string('feedbacktrue', 'qtype_truefalse'), null, $this->editoroptions);;
36703ed7 51 $mform->setType('feedbacktrue', PARAM_RAW);
52
fe6ce234 53 $mform->addElement('editor', 'feedbackfalse', get_string('feedbackfalse', 'qtype_truefalse'), null, $this->editoroptions);
36703ed7 54 $mform->setType('feedbackfalse', PARAM_RAW);
fe76ab50 55
2b7da645
TH
56 $mform->addElement('header', 'multitriesheader', get_string('settingsformultipletries', 'question'));
57
58 $mform->addElement('hidden', 'penalty', 1);
59
60 $mform->addElement('static', 'penaltymessage', get_string('penaltyforeachincorrecttry', 'question'), 1);
61 $mform->addHelpButton('penaltymessage', 'penaltyforeachincorrecttry', 'question');
36703ed7 62 }
01ae934f 63
2b7da645 64 public function set_data($question) {
36703ed7 65 if (!empty($question->options->trueanswer)) {
66 $trueanswer = $question->options->answers[$question->options->trueanswer];
2b7da645
TH
67 $question->correctanswer = ($trueanswer->fraction != 0);
68
fe6ce234
DC
69 $draftid = file_get_submitted_draft_itemid('trueanswer');
70 $answerid = $question->options->trueanswer;
71 $text = $trueanswer->feedback;
72
fe6ce234
DC
73 $question->feedbacktrue = array();
74 $question->feedbacktrue['text'] = $trueanswer->feedback;
75 $question->feedbacktrue['format'] = $trueanswer->feedbackformat;
76 $question->feedbacktrue['text'] = file_prepare_draft_area(
77 $draftid, // draftid
78 $this->context->id, // context
79 'question', // component
80 'answerfeedback', // filarea
81 !empty($answerid)?(int)$answerid:null, // itemid
82 $this->fileoptions, // options
83 $text // text
84 );
85 $question->feedbacktrue['itemid'] = $draftid;
86 }
2b7da645 87
fe6ce234
DC
88 if (!empty($question->options->falseanswer)) {
89 $falseanswer = $question->options->answers[$question->options->falseanswer];
2b7da645 90
fe6ce234
DC
91 $draftid = file_get_submitted_draft_itemid('falseanswer');
92 $answerid = $question->options->falseanswer;
93 $text = $falseanswer->feedback;
94
fe6ce234
DC
95 $question->feedbackfalse = array();
96 $question->feedbackfalse['text'] = $falseanswer->feedback;
97 $question->feedbackfalse['format'] = $falseanswer->feedbackformat;
98 $question->feedbackfalse['text'] = file_prepare_draft_area(
99 $draftid, // draftid
100 $this->context->id, // context
101 'question', // component
102 'answerfeedback', // filarea
103 !empty($answerid)?(int)$answerid:null, // itemid
104 $this->fileoptions, // options
105 $text // text
106 );
107 $question->feedbackfalse['itemid'] = $draftid;
36703ed7 108 }
32db0d42 109 parent::set_data($question);
36703ed7 110 }
01ae934f 111
2b7da645 112 public function qtype() {
36703ed7 113 return 'truefalse';
114 }
115}