Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   1  <?php
   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  
  17  /**
  18   * Defines the editing form for the true-false question type.
  19   *
  20   * @package    qtype
  21   * @subpackage truefalse
  22   * @copyright  2007 Jamie Pratt
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  
  30  require_once($CFG->dirroot.'/question/type/edit_question_form.php');
  31  
  32  
  33  /**
  34   * True-false question editing form definition.
  35   *
  36   * @copyright  2007 Jamie Pratt
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class qtype_truefalse_edit_form extends question_edit_form {
  40      /**
  41       * Add question-type specific form fields.
  42       *
  43       * @param object $mform the form being built.
  44       */
  45      protected function definition_inner($mform) {
  46          $mform->addElement('select', 'correctanswer',
  47                  get_string('correctanswer', 'qtype_truefalse'), array(
  48                  0 => get_string('false', 'qtype_truefalse'),
  49                  1 => get_string('true', 'qtype_truefalse')));
  50  
  51          $mform->addElement('editor', 'feedbacktrue',
  52                  get_string('feedbacktrue', 'qtype_truefalse'), array('rows' => 10), $this->editoroptions);
  53          $mform->setType('feedbacktrue', PARAM_RAW);
  54  
  55          $mform->addElement('editor', 'feedbackfalse',
  56                  get_string('feedbackfalse', 'qtype_truefalse'), array('rows' => 10), $this->editoroptions);
  57          $mform->setType('feedbackfalse', PARAM_RAW);
  58  
  59          $mform->addElement('header', 'multitriesheader',
  60                  get_string('settingsformultipletries', 'question'));
  61  
  62          $mform->addElement('hidden', 'penalty', 1);
  63          $mform->setType('penalty', PARAM_FLOAT);
  64  
  65          $mform->addElement('static', 'penaltymessage',
  66                  get_string('penaltyforeachincorrecttry', 'question'), 1);
  67          $mform->addHelpButton('penaltymessage', 'penaltyforeachincorrecttry', 'question');
  68      }
  69  
  70      public function data_preprocessing($question) {
  71          $question = parent::data_preprocessing($question);
  72  
  73          if (!empty($question->options->trueanswer)) {
  74              $trueanswer = $question->options->answers[$question->options->trueanswer];
  75              $question->correctanswer = ($trueanswer->fraction != 0);
  76  
  77              $draftid = file_get_submitted_draft_itemid('trueanswer');
  78              $answerid = $question->options->trueanswer;
  79  
  80              $question->feedbacktrue = array();
  81              $question->feedbacktrue['format'] = $trueanswer->feedbackformat;
  82              $question->feedbacktrue['text'] = file_prepare_draft_area(
  83                  $draftid,             // Draftid
  84                  $this->context->id,   // context
  85                  'question',           // component
  86                  'answerfeedback',     // filarea
  87                  !empty($answerid) ? (int) $answerid : null, // itemid
  88                  $this->fileoptions,   // options
  89                  $trueanswer->feedback // text.
  90              );
  91              $question->feedbacktrue['itemid'] = $draftid;
  92          }
  93  
  94          if (!empty($question->options->falseanswer)) {
  95              $falseanswer = $question->options->answers[$question->options->falseanswer];
  96  
  97              $draftid = file_get_submitted_draft_itemid('falseanswer');
  98              $answerid = $question->options->falseanswer;
  99  
 100              $question->feedbackfalse = array();
 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                  $falseanswer->feedback // text.
 110              );
 111              $question->feedbackfalse['itemid'] = $draftid;
 112          }
 113  
 114          return $question;
 115      }
 116  
 117      public function qtype() {
 118          return 'truefalse';
 119      }
 120  }