function quiz_get_number_of_questions in Quiz 6.3
Same name and namespace in other branches
- 8.4 quiz.module \quiz_get_number_of_questions()
- 5.2 quiz.module \quiz_get_number_of_questions()
- 5 quiz.module \quiz_get_number_of_questions()
- 6.6 quiz.module \quiz_get_number_of_questions()
- 6.2 quiz.module \quiz_get_number_of_questions()
- 6.4 quiz.module \quiz_get_number_of_questions()
- 6.5 quiz.module \quiz_get_number_of_questions()
- 7.6 quiz.module \quiz_get_number_of_questions()
- 7 quiz.module \quiz_get_number_of_questions()
- 7.4 quiz.module \quiz_get_number_of_questions()
- 7.5 quiz.module \quiz_get_number_of_questions()
Finds out the number of questions for the quiz.
Good example of usage could be to calculate the % of score.
Parameters
$nid: Quiz ID
Return value
integer Returns the number of quiz questions.
2 calls to quiz_get_number_of_questions()
- quiz_take_quiz in ./
quiz.module - Handles quiz taking.
- theme_quiz_take_question in ./
quiz.pages.inc - Theme a question page.
File
- ./
quiz.module, line 933 - Quiz Module
Code
function quiz_get_number_of_questions($vid, $nid) {
// PostgreSQL cannot handle addition of count() columns plus int columns, so we have to do this as two queries:
// $sql = 'SELECT COUNT(*) + (SELECT number_of_random_questions FROM {quiz_node_properties} WHERE vid = %d AND nid = %d)
// FROM {quiz_node_relationship} qnr
// WHERE qnr.parent_vid = %d
// AND qnr.parent_nid = %d
// AND question_status = %d';
// return db_result(db_query($sql, $vid, $nid, $vid, $nid, QUESTION_ALWAYS));
$sql = 'SELECT COUNT(*) FROM {quiz_node_relationship} qnr WHERE qnr.parent_vid = %d AND question_status = %d';
$always_count = db_result(db_query($sql, $vid, QUESTION_ALWAYS));
$rand_count = db_result(db_query('SELECT number_of_random_questions FROM {quiz_node_properties} WHERE vid = %d', $vid));
return $always_count + (int) $rand_count;
}