You are here

function quiz_update_max_score_properties in Quiz 7.5

Same name and namespace in other branches
  1. 8.4 quiz.module \quiz_update_max_score_properties()
  2. 6.4 quiz.module \quiz_update_max_score_properties()
  3. 7.6 quiz.module \quiz_update_max_score_properties()
  4. 7 quiz.module \quiz_update_max_score_properties()
  5. 7.4 quiz.module \quiz_update_max_score_properties()

Updates the max_score property on the specified quizzes.

Parameters

array $quizzes: Array with the vid's of the quizzes to update.

Related topics

6 calls to quiz_update_max_score_properties()
QuizQuestion::saveRelationships in question_types/quiz_question/quiz_question.core.inc
Save this Question to the specified Quiz.
quiz_add_question_to_quiz in ./quiz.module
VBO action to add questions to the current quiz.
quiz_generate_questions in ./quiz.devel.inc
Generate Quiz questions.
quiz_set_questions in ./quiz.module
Sets the questions that are assigned to a quiz.
quiz_update in ./quiz.module
Implements hook_update().

... See full list

File

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

Code

function quiz_update_max_score_properties(array $quizzes) {
  foreach ($quizzes as $vid) {
    $max_score = 0;
    $questions = entity_load('quiz_question_relationship', FALSE, array(
      'parent_vid' => $vid,
    ));
    $quiz_entities = entity_load('quiz', FALSE, array(
      'vid' => $vid,
    ));
    if ($quiz = reset($quiz_entities)) {
      if ($quiz->randomization == 3) {

        // Count taxonomy questions.
        foreach (_quiz_get_terms($quiz->vid) as $term) {
          $max_score += $term->max_score * $term->number;
        }
      }
      else {
        foreach ($questions as $question) {
          if ($question->question_status) {

            // Count required questions.
            $max_score += $question->max_score;
          }
        }
        if ($quiz->randomization == 2) {

          // Count random questions.
          $max_score += $quiz->number_of_random_questions * $quiz->max_score_for_random;
        }
      }
      $quiz->max_score = $max_score;
      $quiz
        ->save();
    }
  }
}