Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-8395 Calculated question: adding or improving class (calculated, datasetdependent,numerical) functions
  3. MDL-8552

The dataitem number is not choosen correctly when using a calculated question in a quiz

    XMLWordPrintable

    Details

    • Type: Sub-task
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.6
    • Fix Version/s: 1.8
    • Component/s: Questions
    • Labels:
      None
    • Affected Branches:
      MOODLE_16_STABLE
    • Fixed Branches:
      MOODLE_18_STABLE

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              timhunt Tim Hunt
              Reporter:
              ppichet Pierre Pichet
              Participants:
              Component watchers:
              Tim Hunt, Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                31/Mar/07