MDL-49948 lesson: Answer and response format should be known for each form
authorRajesh Taneja <rajesh@moodle.com>
Thu, 23 Apr 2015 07:28:47 +0000 (15:28 +0800)
committerDan Poltawski <dan@moodle.com>
Mon, 27 Apr 2015 13:35:20 +0000 (14:35 +0100)
mod/lesson/editpage.php
mod/lesson/locallib.php
mod/lesson/pagetypes/matching.php
mod/lesson/pagetypes/multichoice.php
mod/lesson/pagetypes/numerical.php
mod/lesson/pagetypes/shortanswer.php
mod/lesson/pagetypes/truefalse.php

index 38a2d96..e0b4bd3 100644 (file)
@@ -112,8 +112,7 @@ if ($edit) {
         $answereditor = 'answer_editor['.$answerscount.']';
         if (is_array($data->$answereditor)) {
             $answerdata = $data->$answereditor;
-            if ($answerdata['format'] != FORMAT_MOODLE) {
-                $answerdata = $data->$answereditor;
+            if ($mform->get_answer_format() === LESSON_ANSWER_HTML) {
                 $answerdraftid = file_get_submitted_draft_itemid($answereditor);
                 $answertext = file_prepare_draft_area($answerdraftid, $PAGE->cm->context->id,
                         'mod_lesson', 'page_answers', $answer->id, $editoroptions, $answerdata['text']);
@@ -126,7 +125,7 @@ if ($edit) {
         $responseeditor = 'response_editor['.$answerscount.']';
         if (is_array($data->$responseeditor)) {
             $responsedata = $data->$responseeditor;
-            if ($responsedata['format'] != FORMAT_MOODLE) {
+            if ($mform->get_response_format() === LESSON_ANSWER_HTML) {
                 $responsedraftid = file_get_submitted_draft_itemid($responseeditor);
                 $responsetext = file_prepare_draft_area($responsedraftid, $PAGE->cm->context->id,
                         'mod_lesson', 'page_responses', $answer->id, $editoroptions, $responsedata['text']);
index f6f90fc..693bab5 100644 (file)
@@ -714,12 +714,36 @@ abstract class lesson_add_page_form_base extends moodleform {
      */
     protected $standard = true;
 
+    /**
+     * Answer format supported by question type.
+     */
+    protected $answerformat = '';
+
+    /**
+     * Response format supported by question type.
+     */
+    protected $responseformat = '';
+
     /**
      * Each page type can and should override this to add any custom elements to
      * the basic form that they want
      */
     public function custom_definition() {}
 
+    /**
+     * Returns answer format used by question type.
+     */
+    public function get_answer_format() {
+        return $this->answerformat;
+    }
+
+    /**
+     * Returns response format used by question type.
+     */
+    public function get_response_format() {
+        return $this->responseformat;
+    }
+
     /**
      * Used to determine if this is a standard page or a special page
      * @return bool
index fb67df3..94ba3aa 100644 (file)
@@ -485,6 +485,8 @@ class lesson_add_page_form_matching extends lesson_add_page_form_base {
 
     public $qtype = 'matching';
     public $qtypestring = 'matching';
+    protected $answerformat = LESSON_ANSWER_HTML;
+    protected $responseformat = '';
 
     public function custom_definition() {
 
index 8165d46..b56fa30 100644 (file)
@@ -457,6 +457,8 @@ class lesson_add_page_form_multichoice extends lesson_add_page_form_base {
 
     public $qtype = 'multichoice';
     public $qtypestring = 'multichoice';
+    protected $answerformat = LESSON_ANSWER_HTML;
+    protected $responseformat = LESSON_ANSWER_HTML;
 
     public function custom_definition() {
 
@@ -466,7 +468,7 @@ class lesson_add_page_form_multichoice extends lesson_add_page_form_base {
 
         for ($i = 0; $i < $this->_customdata['lesson']->maxanswers; $i++) {
             $this->_form->addElement('header', 'answertitle'.$i, get_string('answer').' '.($i+1));
-            $this->add_answer($i, null, ($i<2), LESSON_ANSWER_HTML);
+            $this->add_answer($i, null, ($i<2), $this->get_answer_format());
             $this->add_response($i);
             $this->add_jumpto($i, null, ($i == 0 ? LESSON_NEXTPAGE : LESSON_THISPAGE));
             $this->add_score($i, null, ($i===0)?1:0);
index f8f98e0..52b6ad6 100644 (file)
@@ -257,6 +257,8 @@ class lesson_add_page_form_numerical extends lesson_add_page_form_base {
 
     public $qtype = 'numerical';
     public $qtypestring = 'numerical';
+    protected $answerformat = '';
+    protected $responseformat = LESSON_ANSWER_HTML;
 
     public function custom_definition() {
         for ($i = 0; $i < $this->_customdata['lesson']->maxanswers; $i++) {
index d6edd9d..0efed4f 100644 (file)
@@ -328,6 +328,8 @@ class lesson_page_type_shortanswer extends lesson_page {
 class lesson_add_page_form_shortanswer extends lesson_add_page_form_base {
     public $qtype = 'shortanswer';
     public $qtypestring = 'shortanswer';
+    protected $answerformat = '';
+    protected $responseformat = LESSON_ANSWER_HTML;
 
     public function custom_definition() {
 
index ae8fbaf..5a8623d 100644 (file)
@@ -351,16 +351,18 @@ class lesson_add_page_form_truefalse extends lesson_add_page_form_base {
 
     public $qtype = 'truefalse';
     public $qtypestring = 'truefalse';
+    protected $answerformat = LESSON_ANSWER_HTML;
+    protected $responseformat = LESSON_ANSWER_HTML;
 
     public function custom_definition() {
         $this->_form->addElement('header', 'answertitle0', get_string('correctresponse', 'lesson'));
-        $this->add_answer(0, null, true, LESSON_ANSWER_HTML);
+        $this->add_answer(0, null, true, $this->get_answer_format());
         $this->add_response(0);
         $this->add_jumpto(0, get_string('correctanswerjump', 'lesson'), LESSON_NEXTPAGE);
         $this->add_score(0, get_string('correctanswerscore', 'lesson'), 1);
 
         $this->_form->addElement('header', 'answertitle1', get_string('wrongresponse', 'lesson'));
-        $this->add_answer(1, null, true, LESSON_ANSWER_HTML);
+        $this->add_answer(1, null, true, $this->get_answer_format());
         $this->add_response(1);
         $this->add_jumpto(1, get_string('wronganswerjump', 'lesson'), LESSON_THISPAGE);
         $this->add_score(1, get_string('wronganswerscore', 'lesson'), 0);