PageRenderTime 68ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/question/type/truefalse/edit_truefalse_form.php

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