Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/type/truefalse/edit_truefalse_form.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 
00030 require_once($CFG->dirroot.'/question/type/edit_question_form.php');
00031 
00032 
00039 class qtype_truefalse_edit_form extends question_edit_form {
00045     protected function definition_inner($mform) {
00046         $mform->addElement('select', 'correctanswer',
00047                 get_string('correctanswer', 'qtype_truefalse'), array(
00048                 0 => get_string('false', 'qtype_truefalse'),
00049                 1 => get_string('true', 'qtype_truefalse')));
00050 
00051         $mform->addElement('editor', 'feedbacktrue',
00052                 get_string('feedbacktrue', 'qtype_truefalse'), array('rows' => 10), $this->editoroptions);
00053         $mform->setType('feedbacktrue', PARAM_RAW);
00054 
00055         $mform->addElement('editor', 'feedbackfalse',
00056                 get_string('feedbackfalse', 'qtype_truefalse'), array('rows' => 10), $this->editoroptions);
00057         $mform->setType('feedbackfalse', PARAM_RAW);
00058 
00059         $mform->addElement('header', 'multitriesheader',
00060                 get_string('settingsformultipletries', 'question'));
00061 
00062         $mform->addElement('hidden', 'penalty', 1);
00063 
00064         $mform->addElement('static', 'penaltymessage',
00065                 get_string('penaltyforeachincorrecttry', 'question'), 1);
00066         $mform->addHelpButton('penaltymessage', 'penaltyforeachincorrecttry', 'question');
00067     }
00068 
00069     public function data_preprocessing($question) {
00070         $question = parent::data_preprocessing($question);
00071 
00072         if (!empty($question->options->trueanswer)) {
00073             $trueanswer = $question->options->answers[$question->options->trueanswer];
00074             $question->correctanswer = ($trueanswer->fraction != 0);
00075 
00076             $draftid = file_get_submitted_draft_itemid('trueanswer');
00077             $answerid = $question->options->trueanswer;
00078 
00079             $question->feedbacktrue = array();
00080             $question->feedbacktrue['format'] = $trueanswer->feedbackformat;
00081             $question->feedbacktrue['text'] = file_prepare_draft_area(
00082                 $draftid,             // draftid
00083                 $this->context->id,   // context
00084                 'question',           // component
00085                 'answerfeedback',     // filarea
00086                 !empty($answerid) ? (int) $answerid : null, // itemid
00087                 $this->fileoptions,   // options
00088                 $trueanswer->feedback // text
00089             );
00090             $question->feedbacktrue['itemid'] = $draftid;
00091         }
00092 
00093         if (!empty($question->options->falseanswer)) {
00094             $falseanswer = $question->options->answers[$question->options->falseanswer];
00095 
00096             $draftid = file_get_submitted_draft_itemid('falseanswer');
00097             $answerid = $question->options->falseanswer;
00098 
00099             $question->feedbackfalse = array();
00100             $question->feedbackfalse['format'] = $falseanswer->feedbackformat;
00101             $question->feedbackfalse['text'] = file_prepare_draft_area(
00102                 $draftid,              // draftid
00103                 $this->context->id,    // context
00104                 'question',            // component
00105                 'answerfeedback',      // filarea
00106                 !empty($answerid) ? (int) $answerid : null, // itemid
00107                 $this->fileoptions,    // options
00108                 $falseanswer->feedback // text
00109             );
00110             $question->feedbackfalse['itemid'] = $draftid;
00111         }
00112 
00113         return $question;
00114     }
00115 
00116     public function qtype() {
00117         return 'truefalse';
00118     }
00119 }
 All Data Structures Namespaces Files Functions Variables Enumerations