You are here

function quiz_get_number_of_questions in Quiz 7.5

Same name and namespace in other branches
  1. 8.4 quiz.module \quiz_get_number_of_questions()
  2. 5.2 quiz.module \quiz_get_number_of_questions()
  3. 5 quiz.module \quiz_get_number_of_questions()
  4. 6.6 quiz.module \quiz_get_number_of_questions()
  5. 6.2 quiz.module \quiz_get_number_of_questions()
  6. 6.3 quiz.module \quiz_get_number_of_questions()
  7. 6.4 quiz.module \quiz_get_number_of_questions()
  8. 6.5 quiz.module \quiz_get_number_of_questions()
  9. 7.6 quiz.module \quiz_get_number_of_questions()
  10. 7 quiz.module \quiz_get_number_of_questions()
  11. 7.4 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

int Returns the number of quiz questions.

Related topics

5 calls to quiz_get_number_of_questions()
QuizRandomTestCase::testCategorizedRandomQuestions in tests/QuizRandomTestCase.test
Test pulling questions from categories.
QuizRandomTestCase::testRandomQuestions in tests/QuizRandomTestCase.test
Test random plus required questions from a pool.
quiz_get_score_array in ./quiz.pages.inc
Returns an array of score information for a quiz.
quiz_view in ./quiz.module
Implements hook_view().
theme_quiz_stats_get_basic_stats in modules/quiz_stats/quiz_stats.admin.inc
Generates table of results from quiz data structure.

File

./quiz.module, line 1739
quiz.module Main file for the Quiz module.

Code

function quiz_get_number_of_questions($vid, $nid = NULL) {
  $count = 0;
  $quiz = node_load($nid, $vid);
  $questions = quiz_get_questions($nid, $vid);
  $random = isset($quiz->randomization) ? $quiz->randomization : NULL;
  switch ($random) {
    case 2:
    case 3:
      $count = _quiz_get_num_always_questions($vid) + $quiz->number_of_random_questions;
      break;
    case 0:
    case 1:
    default:
      foreach ($questions as $question) {
        if ($quizQuestion = _quiz_question_get_instance($question)) {
          if ($quizQuestion
            ->isGraded()) {
            $count++;
          }
        }
      }
  }
  return $count;
}