function _quiz_get_random_taxonomy_question_ids in Quiz 6.2
Same name and namespace in other branches
- 8.4 quiz.module \_quiz_get_random_taxonomy_question_ids()
- 6.6 quiz.module \_quiz_get_random_taxonomy_question_ids()
- 6.3 quiz.module \_quiz_get_random_taxonomy_question_ids()
- 6.4 quiz.module \_quiz_get_random_taxonomy_question_ids()
- 6.5 quiz.module \_quiz_get_random_taxonomy_question_ids()
- 7.6 quiz.module \_quiz_get_random_taxonomy_question_ids()
- 7 quiz.module \_quiz_get_random_taxonomy_question_ids()
- 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
File
- ./
quiz.module, line 1464 - 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_get_term($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.
$result = db_query_range("SELECT n.nid, n.vid \n FROM {node} n \n INNER JOIN {term_node} tn USING (nid)\n WHERE n.status = 1 AND tn.tid IN ({$term_ids}) \n AND n.type IN ('" . implode("','", _quiz_get_question_types()) . "') ORDER BY RAND()", 0, $num_random);
$questions = array();
while ($question_node = db_fetch_array($result)) {
$questions[] = $question_node;
}
return $questions;
}