You are here

function quiz_update_max_score_properties in Quiz 7.6

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 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

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
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 2226
quiz.module Main file for the Quiz module.

Code

function quiz_update_max_score_properties($quizzes_to_update) {
  if (empty($quizzes_to_update)) {
    return;
  }
  db_update('quiz_node_properties')
    ->expression('max_score', 'max_score_for_random * number_of_random_questions + (
      SELECT COALESCE(SUM(max_score), 0)
      FROM {quiz_node_relationship} qnr
      WHERE qnr.question_status = ' . QUIZ_QUESTION_ALWAYS . '
      AND parent_vid = {quiz_node_properties}.vid)')
    ->condition('vid', $quizzes_to_update, 'IN')
    ->execute();
  db_update('quiz_node_properties')
    ->expression('max_score', '(SELECT COALESCE(SUM(qt.max_score * qt.number), 0)
      FROM {quiz_terms} qt
      WHERE qt.nid = {quiz_node_properties}.nid AND qt.vid = {quiz_node_properties}.vid)')
    ->condition('randomization', 3)
    ->condition('vid', $quizzes_to_update, 'IN')
    ->execute();
  db_update('node_revision')
    ->fields(array(
    'timestamp' => REQUEST_TIME,
  ))
    ->condition('vid', $quizzes_to_update, 'IN')
    ->execute();
  db_update('node')
    ->fields(array(
    'changed' => REQUEST_TIME,
  ))
    ->condition('vid', $quizzes_to_update, 'IN')
    ->execute();
  $results_to_update = db_query('SELECT vid FROM {quiz_node_properties} WHERE vid IN (:vid) AND max_score <> :max_score', array(
    ':vid' => $quizzes_to_update,
    ':max_score' => 0,
  ))
    ->fetchCol();
  if (!empty($results_to_update)) {
    db_update('quiz_node_results')
      ->expression('score', 'ROUND(
        100 * (
          SELECT COALESCE (SUM(a.points_awarded), 0)
          FROM {quiz_node_results_answers} a
          WHERE a.result_id = {quiz_node_results}.result_id
        ) / (
          SELECT max_score
          FROM {quiz_node_properties} qnp
          WHERE qnp.vid = {quiz_node_results}.vid
        )
      )')
      ->condition('vid', $results_to_update, 'IN')
      ->execute();
  }
}