You are here

function _quiz_get_random_taxonomy_question_ids in Quiz 7

Same name and namespace in other branches
  1. 8.4 quiz.module \_quiz_get_random_taxonomy_question_ids()
  2. 6.6 quiz.module \_quiz_get_random_taxonomy_question_ids()
  3. 6.2 quiz.module \_quiz_get_random_taxonomy_question_ids()
  4. 6.3 quiz.module \_quiz_get_random_taxonomy_question_ids()
  5. 6.4 quiz.module \_quiz_get_random_taxonomy_question_ids()
  6. 6.5 quiz.module \_quiz_get_random_taxonomy_question_ids()
  7. 7.6 quiz.module \_quiz_get_random_taxonomy_question_ids()
  8. 7.4 quiz.module \_quiz_get_random_taxonomy_question_ids()

Given a term ID, get all of the question nid/vids that have that ID.

Parameters

$tid: Integer term ID.

Return value

Array of nid/vid combos, like array(array('nid'=>1, 'vid'=>2)).

2 calls to _quiz_get_random_taxonomy_question_ids()
quiz_questions_form_submit in ./quiz.admin.inc
Submit function for quiz_questions.
_quiz_get_random_questions in ./quiz.module
Get an array list of random questions for a quiz.

File

./quiz.module, line 3321
Quiz Module

Code

function _quiz_get_random_taxonomy_question_ids($tid, $num_random) {
  if ($tid == 0) {
    return array();
  }

  // Select random questions by taxonomy.
  $term = taxonomy_term_load($tid);
  $tree = taxonomy_get_tree($term->vid, $term->tid);

  // Flatten the taxonomy tree, and just keep term id's.
  $term_ids[] = $term->tid;
  if (is_array($tree)) {
    foreach ($tree as $term) {
      $term_ids[] = $term->tid;
    }
  }
  $term_ids = implode(',', $term_ids);

  // Get all published questions with one of the allowed term ids.
  // TODO Please convert this statement to the D7 database API syntax.
  $result = db_query_range("SELECT n.nid, n.vid\n    FROM {node} n\n    INNER JOIN {taxonomy_term_node} tn USING (nid)\n    WHERE n.status = 1 AND tn.tid IN ({$term_ids})\n    AND n.type IN ('" . implode("','", array_keys(_quiz_get_question_types())) . "') ORDER BY RAND()");
  $questions = array();
  while ($question_node = db_fetch_array($result)) {
    $question_node['random'] = TRUE;
    $questions[] = $question_node;
  }
  return $questions;
}