When building a calculated question for a quiz the abstracttype.php
function create_session_and_responses(&$question, &$state, $cmoptions, $attempt) {
// Find out how many datasets are available
global $CFG;
if(!$maxnumber = (int)get_field_sql(
"SELECT MAX(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}");
}
If the datasetdefinition are all private to this question, they have an identical itemcount so the function is working correctly.
However if one of the datasetdefinition is a category shareable one its itemcount can be different from the others.
The itemcount could have been settled differently when editing another question using the same category shareable datasetdefinition.
So the $maxnumber of this category shareable datasetdefinition can be greater than the item count of the other private datasetdefinitions related to this question.
As a consequence the following code
$state->options->datasetitem = rand(1, $maxnumber);
$state->options->dataset =
$this->pick_question_dataset($question,$state->options->datasetitem);
could choose an itemnumber for which there is no private dataitems.
If the SQL is changed by using MIN instead of MAX, the problem is solved
at line 30 of abstractype .php
"SELECT MIN(a.itemcount)
and the
function create_session_and_responses(&$question, &$state, $cmoptions, $attempt) {
// Find out how many datasets are available
global $CFG;
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}");
}
// Choose a random dataset
$state->options->datasetitem = rand(1, $maxnumber);
$state->options->dataset =
$this->pick_question_dataset($question,$state->options->datasetitem);
$state->responses = array('' => '');
return true;
}
returns a valid dataset.
- will help resolve
-
MDL-6777 Solving why sharable parameters does not work correctly in calculated question (15, 1.6 etc)
-
- Closed
-