function quiz_get_questions in Quiz 7.5
Same name and namespace in other branches
- 8.4 quiz.module \quiz_get_questions()
- 6.4 quiz.module \quiz_get_questions()
- 7.6 quiz.module \quiz_get_questions()
- 7 quiz.module \quiz_get_questions()
- 7.4 quiz.module \quiz_get_questions()
Retrieve list of published questions assigned to quiz.
This function should be used for question browsers and similiar... It should not be used to decide what questions a user should answer when taking a quiz. quiz_build_question_list is written for that purpose.
Parameters
$quiz_nid: Quiz node id.
$quiz_vid: Quiz node version id.
Return value
An array of questions.
4 calls to quiz_get_questions()
- quiz_get_number_of_questions in ./
quiz.module - Finds out the number of questions for the quiz.
- quiz_insert in ./
quiz.module - Implements hook_insert().
- quiz_questions_form in ./
quiz.admin.inc - Handles "manage questions" tab.
- quiz_views_pre_view in includes/
views/ quiz.views.inc - Implements hook_views_pre_view().
File
- ./
quiz.module, line 2870 - quiz.module Main file for the Quiz module.
Code
function quiz_get_questions($quiz_nid, $quiz_vid = NULL) {
$questions = array();
$query = db_select('node', 'n');
$query
->fields('n', array(
'nid',
'type',
));
$query
->fields('nr', array(
'vid',
'title',
));
$query
->fields('qnr', array(
'question_status',
'weight',
'max_score',
'auto_update_max_score',
'qnr_id',
'qnr_pid',
'child_nid',
'child_vid',
));
$query
->addField('n', 'vid', 'latest_vid');
$query
->join('node_revision', 'nr', 'n.nid = nr.nid');
$query
->join('quiz_node_relationship', 'qnr', 'nr.vid = qnr.child_vid');
$query
->condition('n.status', 1);
$query
->condition('qnr.parent_nid', $quiz_nid);
if ($quiz_vid) {
$query
->condition('qnr.parent_vid', $quiz_vid);
}
$query
->condition('qnr_pid', NULL, 'IS');
$query
->orderBy('qnr.weight');
$result = $query
->execute();
foreach ($result as $question) {
$questions[] = $question;
quiz_get_sub_questions($question->qnr_id, $questions);
}
return $questions;
}