Details
Description
The calculated question allow to define datasets variable (i.e. {a}) that could be common to questions from the same category.
This NEVER work correctly because you can define a common variable say {b} in question 1 , create say 6 data items.
Create a question 2 that will use the same common {b} in another equation (ex. {cb}+{c}.
You then create a number of datasets for example 2 dataitems so question 2 will have 2 new {c} data items and will use 2 {b} common dataitems
When you will attempt question 2, you will call datasetdependent/abstractype.php function create_session_and_responses()
This function will search for the MAXIMUM data items possible using
if(!$maxnumber = (int)get_field_sql(
"SELECT MIN(a.itemcount)
FROM {$CFG->prefix}question_dataset_definitions a,
{$CFG->prefix}question_datasets b
WHERE b.question = $question->id
AND a.id = b.datasetdefinition")) {
error("Couldn't get the specified dataset for a calculated " .
"question! (question: {$question->id}");
}
it will return $maxnumber =6 from the itemcount of common {b} data items.
You will ask for a random number between 1 and 6.
$state->options->datasetitem = rand(1, $maxnumber);
If you get greater the 2 you are in TROUBLE because there is just 2 {c} data items available.
http://www.chimie.uqam.ca/images/2809/maxnumber6.jpg
However is you change the SQL to
if(!$maxnumber = (int)get_field_sql(
"SELECT MIN(a.itemcount)
FROM {$CFG->prefix}question_dataset_definitions a,
{$CFG->prefix}question_datasets b
WHERE b.question = $question->id
AND a.id = b.datasetdefinition")) {
error("Couldn't get the specified dataset for a calculated " .
"question! (question: {$question->id}");
}
you get $maxnumber = 2 so
$state->options->datasetitem = rand(1, $maxnumber);
will give you a value that is in the range of the smallest dataset {c} and you get
http://www.chimie.uqam.ca/images/2809/minnumber2.jpg
I am also implementing showing the available common category datasetdefs when creating a calculated question.
http://www.chimie.uqam.ca/images/2809/showcommon.jpg
but that's another story....
Issue Links
| This issue will be resolved by: | ||||
| MDL-8552 | The dataitem number is not choosen correctly when using a calculated question in a quiz |
|
|
|
This is just one part of the solution.
If we got a minimum! $maxnumber that is less that 1, this means that one of the questions is not correctly defined.
if we got $maxnumber =1 the rand() should not be called.
I am working also on generating temporary data items ( or even at least one ) so that the question remains somewhat useable although with an explicit NOTIFY.
This is related to the 3 steps actually necessary to create a calculated question.