MDL-20636 Fix codechecker issues in qtype_shortanswer.
[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 *
b04a4319
TH
21 * @package qtype
22 * @subpackage truefalse
23 * @copyright 2007 Jamie Pratt
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2b7da645
TH
25 */
26
27
a17b297d
TH
28defined('MOODLE_INTERNAL') || die();
29
bfebaf64 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 *
7764183a
TH
37 * @copyright 2007 Jamie Pratt
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
42e6506e
TH
64 public function data_preprocessing($question) {
65 $question = parent::data_preprocessing($question);
66
36703ed7 67 if (!empty($question->options->trueanswer)) {
68 $trueanswer = $question->options->answers[$question->options->trueanswer];
2b7da645
TH
69 $question->correctanswer = ($trueanswer->fraction != 0);
70
fe6ce234
DC
71 $draftid = file_get_submitted_draft_itemid('trueanswer');
72 $answerid = $question->options->trueanswer;
73 $text = $trueanswer->feedback;
74
fe6ce234
DC
75 $question->feedbacktrue = array();
76 $question->feedbacktrue['text'] = $trueanswer->feedback;
77 $question->feedbacktrue['format'] = $trueanswer->feedbackformat;
78 $question->feedbacktrue['text'] = file_prepare_draft_area(
79 $draftid, // draftid
80 $this->context->id, // context
81 'question', // component
82 'answerfeedback', // filarea
83 !empty($answerid)?(int)$answerid:null, // itemid
84 $this->fileoptions, // options
85 $text // text
86 );
87 $question->feedbacktrue['itemid'] = $draftid;
42e6506e
TH
88
89 return $question;
fe6ce234 90 }
2b7da645 91
fe6ce234
DC
92 if (!empty($question->options->falseanswer)) {
93 $falseanswer = $question->options->answers[$question->options->falseanswer];
2b7da645 94
fe6ce234
DC
95 $draftid = file_get_submitted_draft_itemid('falseanswer');
96 $answerid = $question->options->falseanswer;
97 $text = $falseanswer->feedback;
98
fe6ce234
DC
99 $question->feedbackfalse = array();
100 $question->feedbackfalse['text'] = $falseanswer->feedback;
101 $question->feedbackfalse['format'] = $falseanswer->feedbackformat;
102 $question->feedbackfalse['text'] = file_prepare_draft_area(
103 $draftid, // draftid
104 $this->context->id, // context
105 'question', // component
106 'answerfeedback', // filarea
107 !empty($answerid)?(int)$answerid:null, // itemid
108 $this->fileoptions, // options
109 $text // text
110 );
111 $question->feedbackfalse['itemid'] = $draftid;
36703ed7 112 }
ff58648f
TH
113
114 return $question;
36703ed7 115 }
01ae934f 116
2b7da645 117 public function qtype() {
36703ed7 118 return 'truefalse';
119 }
120}