Hi,

When the questions for a Quiz are randomly selected using a term, nothing is done to handle multi-languages. All published question for the term are used. Quiz doesn't check that the questions are in the same language that the Quiz itself. Multi-languages in the term's vocabulary is not handled.

Here is patch that add multi-languages support when randomly selecting questions using a term. Also attached to this is a test case to for the behavior of the modified function.

Comments

pbuyle’s picture

StatusFileSize
new3.99 KB

Here is an updated patch to also select questions without a language (== language neutral) in _quiz_get_random_taxonomy_question_ids().

pbuyle’s picture

Status: Active » Needs review
StatusFileSize
new6.6 KB

Here is a patch build on the one in #1 (with quiz.test in the 'tests' folder from initial post) that adds language support to the "Manage questions" tab of quiz nodes. Auto-complete has been modified to use language as first argument (and to properly handle '/' in the query). Form validation has been modified to check for language too of added questions. The test case only covers autocomplete.

tutumlum’s picture

Title: Multi-languages support when randomly selecting questions using a term » Multi-languages support for "Categorized random questions"
Version: 6.x-3.4 » 6.x-4.1

Simply needed to add following lines to quiz.module just after line #2747 :

    if ($quiz->language != '') {
      $sql .= " AND n.language = '" . $quiz->language . "'";
    }

Tested and it works. If you want to test, you should take quiz newly. Resuming quizzes will not be affected since question list is built before.

pbonnefoi’s picture

Component: Code » Code - Import/Export

Is this has been ported yet ? I think, the count needs to be also updated on line 2552, but I don't know how to do it...

while ($question = db_fetch_array($res)) {
      $count++;
      $question['tid'] = $term->tid;
      $question['number'] = $count + $total_count;
      $questions[] = $question;
      $nids[] = $question['nid'];
}

If you put more questions than questions available in a given language, but still under the number of questions available for a term (no matter what's the language) the function will pass.

pbonnefoi’s picture

Well actually, the problem isn't there, the $count is alright, the warning message does not show up in a right place. It only appear when the quiz is taken, not when the number of questions is added. quiz.admin.inc, needs to be reviewed (I pasted the code below where the problem is). I'm working on it.

function quiz_categorized_form_validate($form, &$form_state) {
  if (_quiz_is_int(arg(1))) {
    if (node_last_changed(arg(1)) > $form_state['values']['timestamp']) {
      form_set_error('changed', t('This content has been modified by another user, changes cannot be saved.'));
    }
  }
  else {
    form_set_error('changed', t('A critical error has occured. Please report error code 28 on the quiz project page.'));
    return;
  }
  if (!empty($form_state['values']['term'])) {
    $tid = _quiz_get_id_from_string($form_state['values']['term']);
    if ($tid === FALSE) {
      $terms = _quiz_search_terms($form_state['values']['term']);
      $num_terms = count($terms);
      if ($num_terms == 1) {
        $tid = key($terms);
      }
      elseif ($num_terms > 1) {
        form_set_error('term', t('You need to be more specific, or use the autocomplete feature. The term name you entered matches several terms: %terms', array('%terms' => implode(', ', $terms))));
      }
      elseif ($num_terms == 0) {
        form_set_error('term', t("The term name you entered doesn't match any registered question terms."));
      }
    }
    if (in_array($tid, array_keys($form))) {
      form_set_error('term', t('The category you are trying to add has already been added to this quiz.'));
    }
    else {
      form_set_value($form['tid'], $tid, $form_state);
    }

    if (!_quiz_is_int($form_state['values']['number'])) {
      form_set_error('number', t('The number of questions needs to be a positive integer'));
    }
    if (!_quiz_is_int($form_state['values']['max_score'], 0)) {
      form_set_error('max_score', t('The max score needs to be a positive integer or 0'));
    }
  }
}
djdevin’s picture

Component: Code - Import/Export » Code - Quiz core
Issue summary: View changes
Status: Needs review » Closed (outdated)

This issue is being closed because it was filed against a version that is no longer supported. If the issue still persists in the latest version of Quiz, please open a new issue.