You are here

function quiz_update_total_score_fast in Quiz 8.4

Same name and namespace in other branches
  1. 6.4 quiz.pages.inc \quiz_update_total_score_fast()
  2. 7.6 quiz.pages.inc \quiz_update_total_score_fast()
  3. 7 quiz.pages.inc \quiz_update_total_score_fast()
  4. 7.4 quiz.pages.inc \quiz_update_total_score_fast()

Updates the total score using only one mySql query.

Parameters

$rid: Result id

$quiz_vid: Quiz node version id

1 call to quiz_update_total_score_fast()
quiz_report_form_submit in ./quiz.pages.inc
Submit the report form

File

./quiz.pages.inc, line 767
Page callback file for the quiz module.

Code

function quiz_update_total_score_fast($rid, $quiz_vid) {
  $subq1 = db_select('quiz_node_results_answers', 'a');
  $subq1
    ->condition('a.result_id', $rid)
    ->addExpression('SUM(a.points_awarded)');
  $res1 = $subq1
    ->execute()
    ->fetchField();
  $subq2 = db_select('quiz_node_properties', 'qnp');
  $subq2
    ->condition('qnp.vid', $quiz_vid)
    ->addField('qnp', 'max_score');
  $res2 = $subq2
    ->execute()
    ->fetchField();
  db_update('quiz_node_results')
    ->expression('score', 'ROUND(100*(:res1/:res2))', array(
    ':res1' => $res1,
    ':res2' => $res2,
  ))
    ->condition('result_id', $rid)
    ->execute();
}