function _quiz_get_random_questions in Quiz 7
Same name and namespace in other branches
- 8.4 quiz.module \_quiz_get_random_questions()
- 5.2 quiz.module \_quiz_get_random_questions()
- 6.6 quiz.module \_quiz_get_random_questions()
- 6.2 quiz.module \_quiz_get_random_questions()
- 6.3 quiz.module \_quiz_get_random_questions()
- 6.4 quiz.module \_quiz_get_random_questions()
- 6.5 quiz.module \_quiz_get_random_questions()
- 7.6 quiz.module \_quiz_get_random_questions()
- 7.4 quiz.module \_quiz_get_random_questions()
- 7.5 quiz.module \_quiz_get_random_questions()
Get an array list of random questions for a quiz.
Parameters
$quiz: The quiz node.
Return value
Array of nid/vid combos for quiz questions.
1 call to _quiz_get_random_questions()
- quiz_build_question_list in ./
quiz.module - Retrieves a list of questions (to be taken) for a given quiz.
File
- ./
quiz.module, line 3283 - Quiz Module
Code
function _quiz_get_random_questions($quiz) {
if (!is_object($quiz)) {
drupal_set_message(t('The question pool cannot be generated.'), 'error');
watchdog('quiz', '_quiz_get_random_questions was called incorrectly.', array(), WATCHDOG_ERROR);
return FALSE;
}
$num_random = $quiz->number_of_random_questions;
$tid = $quiz->tid;
$questions = array();
if ($num_random > 0) {
if ($tid > 0) {
$questions = _quiz_get_random_taxonomy_question_ids($tid, $num_random);
}
else {
// Select random question from assigned pool.
$result = db_query_range("SELECT child_nid as nid, child_vid as vid\n FROM {quiz_node_relationship}\n WHERE parent_vid = :parent_vid AND parent_nid = :parent_nid AND question_status = :question_status ORDER BY RAND()", array(
':parent_vid' => $quiz->vid,
':parent_nid' => $quiz->nid,
':question_status' => QUESTION_RANDOM,
));
while ($question_node = db_fetch_array($result)) {
$question_node['random'] = TRUE;
$question_node['relative_max_score'] = $quiz->max_score_for_random;
$questions[] = $question_node;
}
}
}
return $questions;
}