You are here

function quiz_update_max_score_properties in Quiz 6.4

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

Updates the max_score property on the specified quizzes

Parameters

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

Related topics

4 calls to quiz_update_max_score_properties()
QuizQuestion::saveRelationships in question_types/quiz_question/quiz_question.core.inc
Handle the add to quiz part of the quiz_question_form
quiz_set_questions in ./quiz.module
Sets the questions that are assigned to a quiz.
quiz_update in ./quiz.module
Implementation of hook_update().
_quiz_delete_question in question_types/quiz_question/quiz_question.module
Delete the question node from the db, and mark its identifiers in the quiz linking table as "NEVER". This is safer than deleting them and allows for same tracing of what's happened if a question was deleted unintentionally.

File

./quiz.module, line 2366
Quiz Module

Code

function quiz_update_max_score_properties($quizzes_to_update) {
  if (empty($quizzes_to_update)) {
    return;
  }
  $sql = "UPDATE {quiz_node_properties} qnp\n          SET max_score = max_score_for_random * number_of_random_questions + (\n            SELECT SUM(max_score)\n            FROM {quiz_node_relationship} qnr\n            WHERE qnr.question_status = " . QUESTION_ALWAYS . "\n            AND parent_vid = qnp.vid\n          )\n          WHERE vid IN( " . db_placeholders($quizzes_to_update) . ")";
  db_query($sql, $quizzes_to_update);
  $sql = "UPDATE {quiz_node_properties} qnp\n          SET qnp.max_score = (\n            SELECT SUM(qt.max_score * qt.number)\n            FROM {quiz_terms} qt\n            WHERE qt.nid = qnp.nid AND qt.vid = qnp.vid\n          )\n          WHERE qnp.randomization = 3 AND qnp.vid IN( " . db_placeholders($quizzes_to_update) . ")";
  db_query($sql, $quizzes_to_update);

  // No need to use db_placeholders for time()...
  $sql = "UPDATE {node_revisions}\n          SET timestamp = " . time() . "\n          WHERE vid IN( " . db_placeholders($quizzes_to_update) . ")";
  db_query($sql, $quizzes_to_update);
  $sql = "UPDATE {node}\n          SET changed = " . time() . "\n          WHERE vid IN( " . db_placeholders($quizzes_to_update) . ")";
  db_query($sql, $quizzes_to_update);

  // Update percent scores
  $sql = 'UPDATE {quiz_node_results} r
          SET r.score = ROUND(
            100 * (
              SELECT SUM(a.points_awarded)
              FROM {quiz_node_results_answers} a
              WHERE a.result_id = r.result_id
            ) / (
              SELECT max_score
              FROM {quiz_node_properties} qnp
              WHERE qnp.vid = r.vid
            )
          )
          WHERE r.vid IN(' . db_placeholders($quizzes_to_update) . ')';
  db_query($sql, $quizzes_to_update);
}