MDL-46148 qtype_calculated: fix validation when importing.
In order to do this in a sane way, I cleaned up a lot of old mess, inclduing: 1. Previously, qtype_calcuated used ->answeres when importing, and ->answer when saving the form. This was crazy, so I fixed it, and stripped out the code that made the alternative variable name work. 2. Similarly, it could handle ->answer being either an array, such as you would get form the HTML editor, or a simple string, which is what you get form the form. I simplified that too. 3. Finally, I made import use a transaction around saving each question, so we don't get half questions in the database when an error occurs.
This commit is contained in:
@@ -606,12 +606,9 @@ class qformat_webct extends qformat_default {
|
||||
// Calculated Question.
|
||||
$question = $this->defaultquestion();
|
||||
$question->qtype = 'calculated';
|
||||
$question->answers = array(); // No problem as they go as :FORMULA: from webct.
|
||||
$question->answer = array(); // No problem as they go as :FORMULA: from webct.
|
||||
$question->units = array();
|
||||
$question->dataset = array();
|
||||
|
||||
// To make us pass the end-of-question sanity checks.
|
||||
$question->answer = array('dummy');
|
||||
$question->fraction = array('1.0');
|
||||
$question->feedback = array();
|
||||
|
||||
@@ -739,7 +736,7 @@ class qformat_webct extends qformat_default {
|
||||
if (preg_match('~^:FORMULA:(.*)~i', $line, $webctoptions)) {
|
||||
// Answer for a calculated question.
|
||||
++$currentchoice;
|
||||
$question->answers[$currentchoice] =
|
||||
$question->answer[$currentchoice] =
|
||||
qformat_webct_convert_formula($webctoptions[1]);
|
||||
|
||||
// Default settings.
|
||||
|
||||
Reference in New Issue
Block a user