Is this a bug in calculated quix XML import?

Is this a bug in calculated quix XML import?

by Tim Lovett -
Number of replies: 8

I make a quiz with a Simple Calculated question in Moodle, with the following unit settings:

 
P.S. This was using a new test site with a fresh install of Moodle 2.2.2, that is 1 hour old.
Average of ratings: -
In reply to Tim Lovett

Re: Is this a bug in calculated quix XML import?

by Tim Lovett -

More details...

When I import the quiz as XML, the SimpleCalc question looks OK.

But when the quiz was run, I discovered the units were not compulsory (despite the correct display of the pull-down menu making it appear to have imported correctly).

It is when you EDIT SETTINGS on that question, you see the default Unit Handling settings. (No units, text entry etc).

Then if you save and return to preview the quiz, the Unit Handling has reverted to those default settings. The pull-down menu has disappeared!

I DO NOT want to have to go through every imported XML calculated question and reset this Unit Handling. (We have hundreds of questions that I am porting from our in-house VB quiz program into Moodle).

I'm guessing there is some sort of fault with XML import of the tag... <unitgradingtype>1</unitgradingtype> ?

(Sorry I'm not much help with PHP at this stage, but I am having a bit of a guess... having written a quiz program in VB that I find quicker than Moodle for writing questions. But Moodle has the whole kit and kaboodle... wink

In reply to Tim Lovett

Re: Is this a bug in calculated quix XML import?

by Pierre Pichet -

Hi Tim,

What you described is a bug but given the info it appears more in the edit_form.

I will try to locate the problem and set a bug.

Pierre

In reply to Tim Lovett

Re: Is this a bug in calculated quix XML import?

by Pierre Pichet -

Could you attach here your quiz xml file

Pierre

In reply to Pierre Pichet

Re: Is this a bug in calculated quix XML import?

by Tim Lovett -

Hi Pierre;

XML file downloaded from Moodle 1.2.1 is here. This quiz was exported after checking all units are working OK in Moodle. 

http://www.joshualovett.com/MDME/Moodle/Moodle-forum/questions-Forces-Default%20for%2010205%20Moments-20120327-1137.xml

And just in case you need a nice simple question that wasn't generated by my program, I did a single question manually and it does the same thing... XML is here

In reply to Tim Lovett

Re: Is this a bug in calculated quix XML import?

by Pierre Pichet -

your single file load correctly and on preview everything (units to choose from) is diplayed correctly because this is set by the showunits parameter although the value of unitgradingtype is set to 0 not 1 

the following changes in numerical/questiontype.php

        } else if (isset($question->showunits)) {
            // Updated import, e.g. Moodle XML.
            $options->showunits = $question->showunits;
            $options->unitgradingtype = $question->unitgradingtype;
            
        } else {

will solve the problem.

Then I have to set the tracker issue and resolve it with all the necessary testing steps...

Pierre

P.S. As they say everywhere, if you apply this patch, you are responsible of its effect wink

In reply to Pierre Pichet

Re: Is this a bug in calculated quix XML import?

by Tim Lovett -

Excellent Piere!

Works perfectly in Moodle 2.2.1 and 2.2.2

In reply to Pierre Pichet

Re: Is this a bug in calculated quix XML import?

by Pierre Pichet -

On import (format.php)

$qo->unitgradingtype = $this->getpath($question, array('#', 'unitgradingtype', 0, '#'), 0);

In edit_numerical_form
$question->unitgradingtypes = $question->options->unitgradingtype;


and in  public function save_unit_options($question) {

$options->unitgradingtype = 0;
        if (isset($question->unitrole)) {
            // Saving the editing form.
            $options->showunits = $question->unitrole;
            if ($question->unitrole == self::UNITGRADED) {
                $options->unitgradingtype = $question->unitgradingtypes;
                $options->showunits = $question->multichoicedisplay;
            }
 
        }
as there is no
$question->unitgradingtypes
in import the value is reset to 0;

This is a bug
Pierre
P.S. As it is midnight, l will set the bug tomorrow wink  
P.S. This should be set by changing the editform and the save_unit_options()  function so that import files stay OK.