Moodle
  1. Moodle
  2. MDL-28426

qtype base class export_to_xml method leaves out feedback & answer formats

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0.3, 2.1.2, 2.2
    • Fix Version/s: 2.0.6, 2.1.3
    • Component/s: Questions
    • Labels:
    • Database:
      Any
    • Testing Instructions:
      Hide

      Export a question to XML format using a type which does not override the base export_to_xml method, ensuring that the feedback blocks are in HTML format. Import the question from the XML file and then edit it. The feedback edit areas will now be standard text fields and not HTML editors.

      If that is not possible, just make sure that exporting to Moodle XML does not have any obvious regressions.

      Show
      Export a question to XML format using a type which does not override the base export_to_xml method, ensuring that the feedback blocks are in HTML format. Import the question from the XML file and then edit it. The feedback edit areas will now be standard text fields and not HTML editors. If that is not possible, just make sure that exporting to Moodle XML does not have any obvious regressions.
    • Workaround:
      Hide

      Patch for problem (relative to 2.0.3+) included in description. The only workaround without a patch would be to hand-edit the XML to add the attributes to the correct tags or to always correct the formats after the question is imported.

      Show
      Patch for problem (relative to 2.0.3+) included in description. The only workaround without a patch would be to hand-edit the XML to add the attributes to the correct tags or to always correct the formats after the question is imported.
    • Affected Branches:
      MOODLE_20_STABLE, MOODLE_21_STABLE, MOODLE_22_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE, MOODLE_21_STABLE
    • Pull from Repository:
    • Pull Master Branch:
    • Rank:
      18076

      Description

      The base export_to_xml function in question/type/questiontype.php does not set the feedback (or answer) format values in the exported XML. When these questions are re-read the feedback blocks are converted to 'moodle-auto-format' from whatever they currently are (usually the default HTML). The standard XML import function already supports reading the format value from the attribute of the answer 'text' element and the feedback element. The patch below, when applied to 2.0.3+ should fix the issue.

      — questiontype.php 9 Mar 2011 08:20:51 -0000 1.173
      +++ questiontype.php 21 Jul 2011 18:29:19 -0000
      @@ -1608,10 +1608,12 @@
      //TODO export answers with any extra data
      } else {
      foreach ($question->options->answers as $answer) {
      + $ansformat=$format->get_format($answer->answerformat);
      + $fbformat=$format->get_format($answer->feedbackformat);
      $percent = 100 * $answer->fraction;

      • $expout .= " <answer fraction=\"$percent\">\n";
        + $expout .= " <answer fraction=\"$percent\" format=\"{$ansformat}\">\n";
        $expout .= $format->writetext($answer->answer, 3, false);
      • $expout .= " <feedback>\n";
        + $expout .= " <feedback format=\"{$fbformat}\">\n";
        $expout .= $format->writetext($answer->feedback, 4, false);
        $expout .= " </feedback>\n";
        $expout .= " </answer>\n";

        Issue Links

          Activity

          Hide
          Tim Hunt added a comment -

          Thanks for your patch. It did not apply, for some reason, but the change was easy enough to apply by hand.

          Basically the same change is also required in 2.1 and 2.2, but the required code is different, so I fixed the problem there myself.

          Show
          Tim Hunt added a comment - Thanks for your patch. It did not apply, for some reason, but the change was easy enough to apply by hand. Basically the same change is also required in 2.1 and 2.2, but the required code is different, so I fixed the problem there myself.
          Hide
          Eloy Lafuente (stronk7) added a comment -

          The main moodle.git repository has just been updated with latest weekly modifications. You may wish to rebase your PULL branches to simplify history and avoid any possible merge conflicts. This would also make integrator's life easier next week.

          TIA and ciao

          Show
          Eloy Lafuente (stronk7) added a comment - The main moodle.git repository has just been updated with latest weekly modifications. You may wish to rebase your PULL branches to simplify history and avoid any possible merge conflicts. This would also make integrator's life easier next week. TIA and ciao
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Integrated, thanks!

          Show
          Eloy Lafuente (stronk7) added a comment - Integrated, thanks!
          Hide
          Rajesh Taneja added a comment -

          Works Great
          Thanks for fixing this Tim and Roger.

          Show
          Rajesh Taneja added a comment - Works Great Thanks for fixing this Tim and Roger.
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Yes, you got this finally upstream, just in time for Moodle 2.2beta. Congrats and thanks!

          Ciao

          Show
          Eloy Lafuente (stronk7) added a comment - Yes, you got this finally upstream, just in time for Moodle 2.2beta. Congrats and thanks! Ciao
          Hide
          Jamie Pratt added a comment -

          This is code is causing a fatal error for me.

          The method format is protected and is being called from question type base. I suspect it passed testing because only question types that override the question_type::export_to_xml were tested??

          Error from 2.1 is as below. The code in the master branch will also not work I think. 2.0 looks OK, it is not using the format method.

          Fatal error: Call to protected method qformat_xml::format() from context 'question_type' in C:\Program Files (x86)\Zend\Apache2\htdocs\moodle_21_stable\question\type\questiontypebase.php on line 1000

          Show
          Jamie Pratt added a comment - This is code is causing a fatal error for me. The method format is protected and is being called from question type base. I suspect it passed testing because only question types that override the question_type::export_to_xml were tested?? Error from 2.1 is as below. The code in the master branch will also not work I think. 2.0 looks OK, it is not using the format method. Fatal error: Call to protected method qformat_xml::format() from context 'question_type' in C:\Program Files (x86)\Zend\Apache2\htdocs\moodle_21_stable\question\type\questiontypebase.php on line 1000
          Hide
          Tim Hunt added a comment -

          Jamie, we don't re-open issues any more, once a fix has been integrated.

          Instead, we have to create a new issue.

          Show
          Tim Hunt added a comment - Jamie, we don't re-open issues any more, once a fix has been integrated. Instead, we have to create a new issue.
          Hide
          Tim Hunt added a comment -

          I created MDL-30397

          Show
          Tim Hunt added a comment - I created MDL-30397

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: