sangwinc/moodle-qtype_stack — pull request #7 by alcarola (2012-05-17 22:37:11+00:00)
Title: Multi-part question bug fix

I commited a fix for the following bug:

About multi-part questions, I end up with an unexpected "Exception - stack_cas_keyval: raw must be a string." in the following way:

i) Create a minimal single-part question, moving the response from prt1 into the question stem. Update and save.

ii) Add [[input:ans2]] [[validation:ans2]] to the question stem, update the form and save. So far all good.

iii) Now add [[feedback:prt2]] to the question stem and click update.

There is the exception, which essentially prevents me from upgrading a single-part question into a multi-part question. It works fine if you add several parts to the question stem before you save the question the first time. But when you reopen a saved question, you cannot add new PRTs to the question stem anymore.

After some debugging I found out the following:

The problem s the part of the edit form that writes "This prt will become active when the student has answered . The function get_inputs_used_by_prt creates a null $prt on the line

$prt = $prts[$prtname];

and later on the line

$feedbackvariables = new stack_cas_keyval($prt->feedbackvariables, null, 0, 't');

stack_cas_keyval gets called with a null raw string, hence the exception.

The commited fix seems to work fine for me. I can now update the edit form after adding a new PRT and then I have to enter the student answer and teacher answer before I can save, which I guess is acceptable behaviour?