function quiz_build_question_list in Quiz 7
Same name and namespace in other branches
- 8.4 quiz.module \quiz_build_question_list()
- 5.2 quiz.module \quiz_build_question_list()
- 5 quiz.module \quiz_build_question_list()
- 6.6 quiz.module \quiz_build_question_list()
- 6.2 quiz.module \quiz_build_question_list()
- 6.3 quiz.module \quiz_build_question_list()
- 6.4 quiz.module \quiz_build_question_list()
- 6.5 quiz.module \quiz_build_question_list()
- 7.6 quiz.module \quiz_build_question_list()
- 7.4 quiz.module \quiz_build_question_list()
- 7.5 quiz.module \quiz_build_question_list()
Retrieves a list of questions (to be taken) for a given quiz.
If the quiz has random questions this function only returns a random selection of those questions. This function should be used to decide what questions a quiz taker should answer.
Parameters
$quiz: Quiz node.
Return value
Array of question node IDs.
Related topics
2 calls to quiz_build_question_list()
- _quiz_resume_existing_quiz in ./
quiz.module - Resume an in-progress quiz.
- _quiz_take_quiz_init in ./
quiz.module
File
- ./
quiz.module, line 2800 - Quiz Module
Code
function quiz_build_question_list($quiz) {
$questions = array();
if ($quiz->randomization == 3) {
return _quiz_build_categorized_question_list($quiz);
}
// Get required questions first.
$query = db_query('SELECT child_nid as nid, child_vid as vid, max_score as relative_max_score
FROM {quiz_node_relationship}
WHERE parent_vid = :parent_vid
AND question_status = :question_status
ORDER BY weight', array(
':parent_vid' => $quiz->vid,
':question_status' => QUESTION_ALWAYS,
));
while ($question_node = $query
->fetchAssoc()) {
$questions[] = $question_node;
}
// Get random questions for the remainder.
if ($quiz->number_of_random_questions > 0) {
$random_questions = _quiz_get_random_questions($quiz);
$questions = array_merge($questions, $random_questions);
if ($quiz->number_of_random_questions > count($random_questions)) {
// Unable to find enough requested random questions.
return FALSE;
}
}
// Shuffle questions if required.
if ($quiz->randomization > 0) {
shuffle($questions);
}
$count = 0;
foreach ($questions as &$question) {
$count++;
$question['number'] = $count;
}
return $questions;
}