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

    • Icon: Sub-task Sub-task
    • Resolution: Fixed
    • Icon: Minor Minor
    • 1.8
    • 1.6
    • Questions
    • None
    • MOODLE_16_STABLE
    • MOODLE_18_STABLE

      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.

            timhunt Tim Hunt
            ppichet Pierre Pichet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.